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