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