]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
ab1fab670dc18cdddef2c2f0cc58d134e9f9408e
[lyx.git] / src / FontInfo.h
1 // -*- C++ -*-
2 /**
3  * \file src/FontInfo.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author Angus Leeming
10  * \author Dekel Tsur
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef FONT_PROPERTIES_H
16 #define FONT_PROPERTIES_H
17
18 #ifdef TEX2LYX
19 #include "tex2lyx/Font.h"
20 #else
21
22 #include "ColorCode.h"
23 #include "FontEnums.h"
24
25 namespace lyx {
26
27 ///
28 class FontInfo
29 {
30 public:
31         ///
32         FontInfo();
33         ///
34         FontInfo(
35                 FontFamily family,
36                 FontSeries series,
37                 FontShape shape,
38                 FontSize size,
39                 ColorCode color,
40                 ColorCode background,
41                 FontState emph,
42                 FontState underbar,
43                 FontState noun,
44                 FontState number
45                 ): family_(family), series_(series), shape_(shape), size_(size), 
46                 color_(color), background_(background), emph_(emph),
47                 underbar_(underbar), noun_(noun), number_(number)
48         {}
49
50         /// Decreases font size by one
51         FontInfo & decSize();
52         /// Increases font size by one
53         FontInfo & incSize();
54
55         /// Accessor methods.
56         ///@{
57         FontFamily family() const { return family_; }
58         void setFamily(FontFamily f) { family_ = f; }
59         FontSeries series() const { return series_; }
60         void setSeries(FontSeries s) { series_ = s; }
61         FontShape shape() const { return shape_; }
62         void setShape(FontShape s) { shape_ = s; }
63         FontSize size() const { return size_; }
64         void setSize(FontSize s) { size_ = s; }
65         FontState emph() const { return emph_; }
66         void setEmph(FontState e) { emph_ = e; }
67         FontState underbar() const { return underbar_; }
68         void setUnderbar(FontState u) { underbar_ = u; }
69         FontState noun() const { return noun_; }
70         void setNoun(FontState n) { noun_ = n; }
71         FontState number() const { return number_; }
72         void setNumber(FontState n) { number_ = n; }
73         ColorCode color() const { return color_; }
74         void setColor(ColorCode c) { color_ = c; }
75         ColorCode background() const { return background_; }
76         void setBackground(ColorCode b) { background_ = b; }
77         ///@}
78
79         ///
80         void update(FontInfo const & newfont, bool toggleall);
81
82         /** Reduce font to fall back to template where possible.
83             Equal fields are reduced to INHERIT */
84         void reduce(FontInfo const & tmplt);
85
86         /// Realize font from a template (INHERIT are realized)
87         FontInfo & realize(FontInfo const & tmplt);
88         /// Is a given font fully resolved?
89         bool resolved() const;
90
91         ///
92         ColorCode realColor() const;
93
94         /// Converts logical attributes to concrete shape attribute
95         /// Try hard to inline this as it shows up with 4.6 % in the profiler.
96         FontShape realShape() const
97         {
98                 if (noun_ == FONT_ON)
99                         return SMALLCAPS_SHAPE;
100                 if (emph_ == FONT_ON)
101                         return (shape_ == UP_SHAPE) ? ITALIC_SHAPE : UP_SHAPE;
102                 return shape_;
103         }
104
105         bool isSymbolFont() const
106         {
107                 switch (family_) {
108                 case SYMBOL_FAMILY:
109                 case CMSY_FAMILY:
110                 case CMM_FAMILY:
111                 case CMEX_FAMILY:
112                 case MSA_FAMILY:
113                 case MSB_FAMILY:
114                 case WASY_FAMILY:
115                 case ESINT_FAMILY:
116                         return true;
117                 default:
118                         return false;
119                 }
120         }
121
122 private:
123         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
124
125         ///
126         FontFamily family_;
127         ///
128         FontSeries series_;
129         ///
130         FontShape shape_;
131         ///
132         FontSize size_;
133         ///
134         ColorCode color_;
135         ///
136         ColorCode background_;
137         ///
138         FontState emph_;
139         ///
140         FontState underbar_;
141         ///
142         FontState noun_;
143         ///
144         FontState number_;
145 };
146
147
148 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
149 {
150         return lhs.family_ == rhs.family_
151                 && lhs.series_ == rhs.series_
152                 && lhs.shape_ == rhs.shape_
153                 && lhs.size_ == rhs.size_
154                 && lhs.color_ == rhs.color_
155                 && lhs.background_ == rhs.background_
156                 && lhs.emph_ == rhs.emph_
157                 && lhs.underbar_ == rhs.underbar_
158                 && lhs.noun_ == rhs.noun_
159                 && lhs.number_ == rhs.number_;
160 }
161
162
163 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
164 {
165         return !operator==(lhs, rhs);
166 }
167
168 /// Sane font.
169 extern FontInfo const sane_font;
170 /// All inherit font.
171 extern FontInfo const inherit_font;
172 /// All ignore font.
173 extern FontInfo const ignore_font;
174
175 } // namespace lyx
176
177 #endif // TEX2LYX_FONT_H
178 #endif