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