]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
Treat math style a bit more like other font features
[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 private:
165         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
166
167         ///
168         FontFamily family_;
169         ///
170         FontSeries series_;
171         ///
172         FontShape shape_;
173         ///
174         FontSize size_;
175         ///
176         MathStyle style_;
177         ///
178         ColorCode color_;
179         ///
180         ColorCode background_;
181         /// The color used for painting
182         Color paint_color_;
183         ///
184         FontState emph_;
185         ///
186         FontState underbar_;
187         ///
188         FontState strikeout_;
189         ///
190         FontState xout_;
191         ///
192         FontState uuline_;
193         ///
194         FontState uwave_;
195         ///
196         FontState noun_;
197         ///
198         FontState number_;
199         ///
200         FontState nospellcheck_;
201 };
202
203
204 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
205 {
206         return lhs.family_ == rhs.family_
207                 && lhs.series_ == rhs.series_
208                 && lhs.shape_ == rhs.shape_
209                 && lhs.size_ == rhs.size_
210                 && lhs.style_ == rhs.style_
211                 && lhs.color_ == rhs.color_
212                 && lhs.background_ == rhs.background_
213                 && lhs.emph_ == rhs.emph_
214                 && lhs.underbar_ == rhs.underbar_
215                 && lhs.strikeout_ == rhs.strikeout_
216                 && lhs.xout_ == rhs.xout_
217                 && lhs.uuline_ == rhs.uuline_
218                 && lhs.uwave_ == rhs.uwave_
219                 && lhs.noun_ == rhs.noun_
220                 && lhs.number_ == rhs.number_
221                 && lhs.nospellcheck_ == rhs.nospellcheck_;
222 }
223
224
225 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
226 {
227         return !operator==(lhs, rhs);
228 }
229
230 /// Sane font.
231 extern FontInfo const sane_font;
232 /// All inherit font.
233 extern FontInfo const inherit_font;
234 /// All ignore font.
235 extern FontInfo const ignore_font;
236
237 /// Set family after LyX text format
238 void setLyXFamily(std::string const &, FontInfo &);
239
240 /// Set series after LyX text format
241 void setLyXSeries(std::string const &, FontInfo &);
242
243 /// Set shape after LyX text format
244 void setLyXShape(std::string const &, FontInfo &);
245
246 /// Set size after LyX text format
247 void setLyXSize(std::string const &, FontInfo &);
248
249 /// Sets color after LyX text format
250 void setLyXColor(std::string const &, FontInfo &);
251
252 /// Returns misc flag after LyX text format
253 FontState setLyXMisc(std::string const &);
254
255 /// Read a font specification from Lexer. Used for layout files.
256 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
257
258 /// Write a font specification. Used for layout files.
259 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);
260
261 } // namespace lyx
262
263 #endif