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