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