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