]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
Rename a variable
[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 #include "Color.h"
19 #include "ColorCode.h"
20 #include "FontEnums.h"
21
22 #include "support/Changer.h"
23 #include "support/strfwd.h"
24
25
26 namespace lyx {
27
28 class Lexer;
29
30 ///
31 class FontInfo
32 {
33 public:
34         ///
35         FontInfo();
36         ///
37         FontInfo(
38                 FontFamily family,
39                 FontSeries series,
40                 FontShape  shape,
41                 FontSize   size,
42                 ColorCode  color,
43                 ColorCode  background,
44                 FontState  emph,
45                 FontState  underbar,
46                 FontState  strikeout,
47                 FontState  xout,
48                 FontState  uuline,
49                 FontState  uwave,
50                 FontState  noun,
51                 FontState  number)
52                 : family_(family), series_(series), shape_(shape), size_(size),
53                 style_(LM_ST_TEXT), color_(color), background_(background), emph_(emph),
54                 underbar_(underbar), strikeout_(strikeout), xout_(xout), uuline_(uuline),
55                 uwave_(uwave), noun_(noun), number_(number)
56         {}
57
58         /// Decreases font size by one
59         FontInfo & decSize();
60         /// Increases font size by one
61         FontInfo & incSize();
62
63         /// \name Accessor methods
64         //@{
65         FontFamily family() const { return family_; }
66         void setFamily(FontFamily f) { family_ = f; }
67         FontSeries series() const { return series_; }
68         void setSeries(FontSeries s) { series_ = s; }
69         FontShape shape() const { return shape_; }
70         void setShape(FontShape s) { shape_ = s; }
71         FontSize size() const { return size_; }
72         void setSize(FontSize s) { size_ = s; }
73         MathStyle style() const {return style_; }
74         void setStyle(MathStyle s) { style_ = s; }
75         FontState emph() const { return emph_; }
76         void setEmph(FontState e) { emph_ = e; }
77         FontState underbar() const { return underbar_; }
78         void setUnderbar(FontState u) { underbar_ = u; }
79         FontState strikeout() const { return strikeout_; }
80         void setStrikeout(FontState s) { strikeout_ = s; }
81         FontState xout() const { return xout_; }
82         void setXout(FontState s) { xout_ = s; }
83         FontState uuline() const { return uuline_; }
84         void setUuline(FontState s) { uuline_ = s; }
85         FontState uwave() const { return uwave_; }
86         void setUwave(FontState s) { uwave_ = s; }
87         FontState noun() const { return noun_; }
88         void setNoun(FontState n) { noun_ = n; }
89         FontState number() const { return number_; }
90         void setNumber(FontState n) { number_ = n; }
91         ColorCode color() const { return color_; }
92         void setColor(ColorCode c) { color_ = c; }
93         ColorCode background() const { return background_; }
94         void setBackground(ColorCode b) { background_ = b; }
95         //@}
96
97         ///
98         void update(FontInfo const & newfont, bool toggleall);
99
100         /** Reduce font to fall back to template where possible.
101             Equal fields are reduced to INHERIT */
102         void reduce(FontInfo const & tmplt);
103
104         /// Realize font from a template (INHERIT are realized)
105         FontInfo & realize(FontInfo const & tmplt);
106         /// Is a given font fully resolved?
107         bool resolved() const;
108
109         /// The real color of the font. This can be the color that is
110         /// set for painting, the color of the font or a default color.
111         Color realColor() const;
112         /// Sets the color which is used during painting
113         void setPaintColor(Color c) { paint_color_ = c; }
114
115         /// Compute the font size, taking size and math style into account.
116         double realSize() const;
117
118         ///
119         docstring asCSS() const;
120
121         /// Converts logical attributes to concrete shape attribute
122         /// Try hard to inline this as it shows up with 4.6 % in the profiler.
123         FontShape realShape() const
124         {
125                 if (noun_ == FONT_ON)
126                         return SMALLCAPS_SHAPE;
127                 if (emph_ == FONT_ON)
128                         return (shape_ == ITALIC_SHAPE) ? UP_SHAPE : ITALIC_SHAPE;
129                 return shape_;
130         }
131
132         bool isSymbolFont() const
133         {
134                 switch (family_) {
135                 case SYMBOL_FAMILY:
136                 case CMSY_FAMILY:
137                 case CMM_FAMILY:
138                 case CMEX_FAMILY:
139                 case MSA_FAMILY:
140                 case MSB_FAMILY:
141                 case STMARY_FAMILY:
142                 case WASY_FAMILY:
143                 case ESINT_FAMILY:
144                         return true;
145                 default:
146                         return false;
147                 }
148         }
149
150         /// Temporarily replace the color with \param color.
151         Changer changeColor(ColorCode const color);
152         /// Temporarily replace the shape with \param shape.
153         Changer changeShape(FontShape const shape);
154         /// Temporarily replace the style
155         Changer changeStyle(MathStyle style);
156         /// Temporarily replace the FontInfo with \param font, and optionally
157         /// \param realize the \param font against the current FontInfo.
158         Changer change(FontInfo font, bool realize = false);
159
160 private:
161         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
162
163         ///
164         FontFamily family_;
165         ///
166         FontSeries series_;
167         ///
168         FontShape shape_;
169         ///
170         FontSize size_;
171         ///
172         MathStyle style_;
173         ///
174         ColorCode color_;
175         ///
176         ColorCode background_;
177         /// The color used for painting
178         Color paint_color_;
179         ///
180         FontState emph_;
181         ///
182         FontState underbar_;
183         ///
184         FontState strikeout_;
185         ///
186         FontState xout_;
187         ///
188         FontState uuline_;
189         ///
190         FontState uwave_;
191         ///
192         FontState noun_;
193         ///
194         FontState number_;
195 };
196
197
198 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
199 {
200         return lhs.family_ == rhs.family_
201                 && lhs.series_ == rhs.series_
202                 && lhs.shape_ == rhs.shape_
203                 && lhs.size_ == rhs.size_
204                 && lhs.color_ == rhs.color_
205                 && lhs.background_ == rhs.background_
206                 && lhs.emph_ == rhs.emph_
207                 && lhs.underbar_ == rhs.underbar_
208                 && lhs.strikeout_ == rhs.strikeout_
209                 && lhs.xout_ == rhs.xout_
210                 && lhs.uuline_ == rhs.uuline_
211                 && lhs.uwave_ == rhs.uwave_
212                 && lhs.noun_ == rhs.noun_
213                 && lhs.number_ == rhs.number_;
214 }
215
216
217 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
218 {
219         return !operator==(lhs, rhs);
220 }
221
222 /// Sane font.
223 extern FontInfo const sane_font;
224 /// All inherit font.
225 extern FontInfo const inherit_font;
226 /// All ignore font.
227 extern FontInfo const ignore_font;
228
229 /// Set family after LyX text format
230 void setLyXFamily(std::string const &, FontInfo &);
231
232 /// Set series after LyX text format
233 void setLyXSeries(std::string const &, FontInfo &);
234
235 /// Set shape after LyX text format
236 void setLyXShape(std::string const &, FontInfo &);
237
238 /// Set size after LyX text format
239 void setLyXSize(std::string const &, FontInfo &);
240
241 /// Sets color after LyX text format
242 void setLyXColor(std::string const &, FontInfo &);
243
244 /// Returns misc flag after LyX text format
245 FontState setLyXMisc(std::string const &);
246
247 /// Read a font specification from Lexer. Used for layout files.
248 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
249
250 /// Write a font specification. Used for layout files.
251 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);
252
253 } // namespace lyx
254
255 #endif