]> git.lyx.org Git - lyx.git/blob - src/lyxfont.h
support for fraktur font in mathed
[lyx.git] / src / lyxfont.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.   
9  *
10  * ====================================================== */
11
12 #ifndef LYXFONT_H
13 #define LYXFONT_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <iosfwd>
20
21 #include "LString.h"
22 #include "LColor.h"
23
24 class LyXLex;
25 class BufferParams;
26 class Language;
27
28
29 ///
30 class LyXFont {
31 public:
32         /** The value INHERIT_* means that the font attribute is
33             inherited from the layout. In the case of layout fonts, the
34             attribute is inherited from the default font.
35             The value IGNORE_* is used with LyXFont::update() when the
36             attribute should not be changed.
37         */
38         enum FONT_FAMILY {
39                 ///
40                 ROMAN_FAMILY, // fontstruct rely on this to be 0
41                 ///
42                 SANS_FAMILY,
43                 ///
44                 TYPEWRITER_FAMILY,
45                 ///
46                 SYMBOL_FAMILY,
47                 ///
48                 CMR_FAMILY,
49                 ///
50                 CMSY_FAMILY,
51                 ///
52                 CMM_FAMILY,
53                 ///
54                 CMEX_FAMILY,
55                 ///
56                 MSA_FAMILY,
57                 ///
58                 MSB_FAMILY,
59                 ///
60                 EUFRAK_FAMILY,
61                 ///
62                 INHERIT_FAMILY,
63                 ///
64                 IGNORE_FAMILY,
65                 ///
66                 NUM_FAMILIES = INHERIT_FAMILY
67         };
68
69         ///
70         enum FONT_SERIES {
71                 ///
72                 MEDIUM_SERIES, // fontstruct rely on this to be 0
73                 ///
74                 BOLD_SERIES,
75                 ///
76                 INHERIT_SERIES,
77                 ///
78                 IGNORE_SERIES
79         };
80
81         ///
82         enum FONT_SHAPE {
83                 ///
84                 UP_SHAPE, // fontstruct rely on this to be 0
85                 ///
86                 ITALIC_SHAPE,
87                 ///
88                 SLANTED_SHAPE,
89                 ///
90                 SMALLCAPS_SHAPE,
91                 ///
92                 INHERIT_SHAPE,
93                 ///
94                 IGNORE_SHAPE
95         };
96
97         ///
98         enum FONT_SIZE {
99                 ///
100                 SIZE_TINY, // fontstruct rely on this to be 0
101                 ///
102                 SIZE_SCRIPT,
103                 ///
104                 SIZE_FOOTNOTE,
105                 ///
106                 SIZE_SMALL,
107                 ///
108                 SIZE_NORMAL,
109                 ///
110                 SIZE_LARGE,
111                 ///
112                 SIZE_LARGER,
113                 ///
114                 SIZE_LARGEST,
115                 ///
116                 SIZE_HUGE,
117                 ///
118                 SIZE_HUGER,
119                 ///
120                 INCREASE_SIZE,
121                 ///
122                 DECREASE_SIZE,
123                 ///
124                 INHERIT_SIZE,
125                 ///
126                 IGNORE_SIZE
127         };
128  
129         /// Used for emph, underbar, noun and latex toggles
130         enum FONT_MISC_STATE {
131                 ///
132                 OFF,
133                 ///
134                 ON,
135                 ///
136                 TOGGLE,
137                 ///
138                 INHERIT,
139                 ///
140                 IGNORE
141         };
142
143         /// Trick to overload constructor and make it megafast
144         enum FONT_INIT1 {
145                 ///
146                 ALL_INHERIT
147         };
148         ///
149         enum FONT_INIT2 {
150                 ///
151                 ALL_IGNORE
152         };
153         ///
154         enum FONT_INIT3 {
155                 ///
156                 ALL_SANE
157         };
158
159         ///
160         LyXFont();
161
162         /// Shortcut initialization
163         explicit
164         LyXFont(LyXFont::FONT_INIT1);
165         /// Shortcut initialization
166         explicit
167         LyXFont(LyXFont::FONT_INIT2);
168         /// Shortcut initialization
169         explicit
170         LyXFont(LyXFont::FONT_INIT3);
171         /// Shortcut initialization
172         LyXFont(LyXFont::FONT_INIT1, Language const * l);
173         /// Shortcut initialization
174         LyXFont(LyXFont::FONT_INIT2, Language const * l);
175         /// Shortcut initialization
176         LyXFont(LyXFont::FONT_INIT3, Language const * l);
177
178         /// Decreases font size by one
179         LyXFont & decSize();
180  
181         /// Increases font size by one
182         LyXFont & incSize();
183  
184         ///
185         FONT_FAMILY family() const;
186  
187         ///
188         FONT_SERIES series() const;
189  
190         ///
191         FONT_SHAPE shape() const;
192  
193         ///
194         FONT_SIZE size() const;
195  
196         ///
197         FONT_MISC_STATE emph() const;
198  
199         ///
200         FONT_MISC_STATE underbar() const;
201  
202         ///
203         FONT_MISC_STATE noun() const;
204
205         ///
206         FONT_MISC_STATE number() const;
207
208         ///
209         LColor::color color() const;
210
211         ///
212         Language const * language() const;
213
214         ///
215         bool isRightToLeft() const;
216
217         ///
218         bool isVisibleRightToLeft() const;
219
220         ///
221         bool isSymbolFont() const;
222         
223         ///
224         LyXFont & setFamily(LyXFont::FONT_FAMILY f);
225         ///
226         LyXFont & setSeries(LyXFont::FONT_SERIES s);
227         ///
228         LyXFont & setShape(LyXFont::FONT_SHAPE s);
229         ///
230         LyXFont & setSize(LyXFont::FONT_SIZE s);
231         ///
232         LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
233         ///
234         LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
235         ///
236         LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
237         ///
238         LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
239         ///
240         LyXFont & setColor(LColor::color c);
241         ///
242         LyXFont & setLanguage(Language const * l);
243
244         /// Set family after LyX text format
245         LyXFont & setLyXFamily(string const &);
246  
247         /// Set series after LyX text format
248         LyXFont & setLyXSeries(string const &);
249  
250         /// Set shape after LyX text format
251         LyXFont & setLyXShape(string const &);
252  
253         /// Set size after LyX text format
254         LyXFont & setLyXSize(string const &);
255  
256         /// Returns misc flag after LyX text format
257         LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
258
259         /// Sets color after LyX text format
260         LyXFont & setLyXColor(string const &);
261
262         /// Returns size of font in LaTeX text notation
263         string const latexSize() const;
264  
265         /** Updates font settings according to request.
266             If an attribute is IGNORE, the attribute is left as it is.
267             When toggleall = true, all properties that matches the font in use
268             will have the effect that the properties is reset to the
269             default.  If we have a text that is TYPEWRITER_FAMILY, and is
270             update()'ed with TYPEWRITER_FAMILY, the operation will be as if
271             a INHERIT_FAMILY was asked for.  This is necessary for the
272             toggle-user-defined-style button on the toolbar.
273         */
274         void update(LyXFont const & newfont,
275                     Language const * default_lang,
276                     bool toggleall = false);
277  
278         /** Reduce font to fall back to template where possible.
279             Equal fields are reduced to INHERIT */
280         void reduce(LyXFont const & tmplt);
281  
282         /// Realize font from a template (INHERIT are realized)
283 #ifndef INHERIT_LANGUAGE
284         LyXFont & realize(LyXFont const & tmplt);
285 #else
286         LyXFont & realize(LyXFont const & tmplt, Language const * language);
287 #endif
288         /// Is a given font fully resolved?
289         bool resolved() const;
290  
291         /// Read a font specification from LyXLex. Used for layout files.
292         LyXFont & lyxRead(LyXLex &);
293  
294         /// Writes the changes from this font to orgfont in .lyx format in file
295 #ifndef INHERIT_LANGUAGE
296         void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
297 #else
298         void lyxWriteChanges(LyXFont const & orgfont, Language const * doclang,
299                              std::ostream &) const;
300 #endif
301
302         /** Writes the head of the LaTeX needed to change to this font.
303             Writes to string, the head of the LaTeX needed to change
304             to this font. Returns number of chars written. Base is the
305             font state active now.
306         */
307         int latexWriteStartChanges(std::ostream &, LyXFont const & base,
308                                    LyXFont const & prev) const;
309
310         /** Writes tha tail of the LaTeX needed to chagne to this font.
311             Returns number of chars written. Base is the font state we want
312             to achieve.
313         */
314         int latexWriteEndChanges(std::ostream &, LyXFont const & base,
315                                  LyXFont const & next) const;
316
317         /// Build GUI description of font state
318         string const stateText(BufferParams * params) const;
319
320         ///
321         LColor::color realColor() const;
322
323         ///
324         friend
325         bool operator==(LyXFont const & font1, LyXFont const & font2);
326
327         /// Converts logical attributes to concrete shape attribute
328         LyXFont::FONT_SHAPE realShape() const;
329 private:
330         ///
331         struct FontBits {
332                 ///
333                 bool operator==(FontBits const & fb1) const;
334                 ///
335                 bool operator!=(FontBits const & fb1) const;
336                 ///
337                 FONT_FAMILY family;
338                 ///
339                 FONT_SERIES series;
340                 ///
341                 FONT_SHAPE shape;
342                 ///
343                 FONT_SIZE size;
344                 ///
345                 LColor::color color;
346                 ///
347                 FONT_MISC_STATE emph;
348                 ///
349                 FONT_MISC_STATE underbar;
350                 ///
351                 FONT_MISC_STATE noun;
352                 ///
353                 FONT_MISC_STATE number;
354         };
355
356         ///
357         FontBits bits;
358         
359         ///
360         Language const * lang;
361         
362         /// Sane font
363         static FontBits sane;
364         
365         /// All inherit font
366         static FontBits inherit;
367  
368         /// All ignore font
369         static FontBits ignore;
370
371         /// Updates a misc setting according to request
372         LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
373                                          LyXFont::FONT_MISC_STATE org);
374 };
375
376
377 inline
378 LyXFont::FONT_SHAPE LyXFont::shape() const
379 {
380         return bits.shape;
381 }
382
383
384 inline
385 LyXFont::FONT_FAMILY LyXFont::family() const 
386 {
387         return bits.family;
388 }
389
390
391 inline
392 LyXFont::FONT_SERIES LyXFont::series() const
393 {
394         return bits.series;
395 }
396
397
398 inline
399 LyXFont::FONT_SIZE LyXFont::size() const
400 {
401         return bits.size;
402 }
403
404
405 inline
406 LyXFont::FONT_MISC_STATE LyXFont::emph() const
407 {
408         return bits.emph;
409 }
410
411
412 inline
413 LyXFont::FONT_MISC_STATE LyXFont::noun() const
414 {
415         return bits.noun;
416 }
417
418
419 inline
420 bool LyXFont::isSymbolFont() const
421 {
422         switch(family()) {
423         case LyXFont::SYMBOL_FAMILY:
424         case LyXFont::CMSY_FAMILY:
425         case LyXFont::CMM_FAMILY:
426         case LyXFont::CMEX_FAMILY:
427         case LyXFont::MSA_FAMILY:
428         case LyXFont::MSB_FAMILY:
429                 return true;
430         default:
431                 return false;
432         }
433 }
434
435 ///
436 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
437
438 ///
439 inline
440 bool operator==(LyXFont const & font1, LyXFont const & font2)
441 {
442         return font1.bits == font2.bits &&
443                 font1.lang == font2.lang;
444 }
445
446 ///
447 inline
448 bool operator!=(LyXFont const & font1, LyXFont const & font2)
449 {
450         return !(font1 == font2);
451 }
452 #endif