]> git.lyx.org Git - lyx.git/blob - src/lyxfont.h
make NO_LATEX default, set ut compability stuff
[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, 
266                     Language const * default_lang,
267                     bool toggleall = false);
268  
269         /** Reduce font to fall back to template where possible.
270             Equal fields are reduced to INHERIT */
271         void reduce(LyXFont const & tmplt);
272  
273         /// Realize font from a template (INHERIT are realized)
274         LyXFont & realize(LyXFont const & tmplt);
275
276         /// Is a given font fully resolved?
277         bool resolved() const;
278  
279         /// Read a font specification from LyXLex. Used for layout files.
280         LyXFont & lyxRead(LyXLex &);
281  
282         /// Writes the changes from this font to orgfont in .lyx format in file
283         void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
284
285         /** Writes the head of the LaTeX needed to change to this font.
286             Writes to string, the head of the LaTeX needed to change
287             to this font. Returns number of chars written. Base is the
288             font state active now.
289         */
290         int latexWriteStartChanges(std::ostream &, LyXFont const & base,
291                                    LyXFont const & prev) const;
292
293         /** Writes tha tail of the LaTeX needed to chagne to this font.
294             Returns number of chars written. Base is the font state we want
295             to achieve.
296         */
297         int latexWriteEndChanges(std::ostream &, LyXFont const & base,
298                                  LyXFont const & next) const;
299
300         /// Build GUI description of font state
301         string const stateText(BufferParams * params) const;
302
303         ///
304         LColor::color realColor() const;
305
306         ///
307         friend
308         bool operator==(LyXFont const & font1, LyXFont const & font2);
309
310         /// compares two fonts, ignoring the setting of the Latex part.
311         bool equalExceptLatex(LyXFont const &) const;
312
313         /// Converts logical attributes to concrete shape attribute
314         LyXFont::FONT_SHAPE realShape() const;
315 private:
316         ///
317         struct FontBits {
318                 ///
319                 bool operator==(FontBits const & fb1) const;
320                 ///
321                 bool operator!=(FontBits const & fb1) const;
322                 ///
323                 FONT_FAMILY family;
324                 ///
325                 FONT_SERIES series;
326                 ///
327                 FONT_SHAPE shape;
328                 ///
329                 FONT_SIZE size;
330                 ///
331                 LColor::color color;
332                 ///
333                 FONT_MISC_STATE emph;
334                 ///
335                 FONT_MISC_STATE underbar;
336                 ///
337                 FONT_MISC_STATE noun;
338 #ifndef NO_LATEX
339                 ///
340                 FONT_MISC_STATE latex;
341 #endif
342                 ///
343                 FONT_MISC_STATE number;
344         };
345
346         ///
347         FontBits bits;
348         
349         ///
350         Language const * lang;
351         
352         /// Sane font
353         static FontBits sane;
354         
355         /// All inherit font
356         static FontBits inherit;
357  
358         /// All ignore font
359         static FontBits ignore;
360
361         /// Updates a misc setting according to request
362         LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
363                                          LyXFont::FONT_MISC_STATE org);
364 };
365
366
367 inline
368 LyXFont::FONT_SHAPE LyXFont::shape() const
369 {
370         return bits.shape;
371 }
372
373
374 inline
375 LyXFont::LyXFont()
376         : bits(sane), lang(default_language)
377 {}
378
379
380 inline
381 LyXFont::FONT_FAMILY LyXFont::family() const 
382 {
383         return bits.family;
384 }
385
386
387 inline
388 LyXFont::FONT_SERIES LyXFont::series() const
389 {
390         return bits.series;
391 }
392
393
394 inline
395 LyXFont::FONT_SIZE LyXFont::size() const
396 {
397         return bits.size;
398 }
399
400
401 inline
402 LyXFont::FONT_MISC_STATE LyXFont::emph() const
403 {
404         return bits.emph;
405 }
406
407
408 inline
409 LyXFont::FONT_MISC_STATE LyXFont::noun() const
410 {
411         return bits.noun;
412 }
413
414
415 ///
416 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
417
418 ///
419 inline
420 bool operator==(LyXFont const & font1, LyXFont const & font2)
421 {
422         return font1.bits == font2.bits &&
423                 font1.lang == font2.lang;
424 }
425
426 ///
427 inline
428 bool operator!=(LyXFont const & font1, LyXFont const & font2)
429 {
430         return !(font1 == font2);
431 }
432 #endif