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