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