4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
12 * Full author contact details are available in file CREDITS.
15 #ifndef FONT_PROPERTIES_H
16 #define FONT_PROPERTIES_H
19 #include "ColorCode.h"
20 #include "FontEnums.h"
22 #include "support/Changer.h"
23 #include "support/strfwd.h"
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)
60 /// Decreases font size by one
62 /// Increases font size by one
65 /// \name Accessor methods
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; }
102 void update(FontInfo const & newfont, bool toggleall);
104 /** Reduce font to fall back to template where possible.
105 Equal fields are reduced to INHERIT */
106 void reduce(FontInfo const & tmplt);
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;
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; }
119 /// Compute the font size, taking size and math style into account.
120 double realSize() const;
123 docstring asCSS() const;
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
129 if (noun_ == FONT_ON)
130 return SMALLCAPS_SHAPE;
131 if (emph_ == FONT_ON)
132 return (shape_ == ITALIC_SHAPE || shape_ == SLANTED_SHAPE)
133 ? UP_SHAPE : ITALIC_SHAPE;
137 bool isSymbolFont() const
155 /// Temporarily replace the color with \param color.
156 Changer changeColor(ColorCode const color);
157 /// Temporarily replace the shape with \param shape.
158 Changer changeShape(FontShape const shape);
159 /// Temporarily replace the style
160 Changer changeStyle(MathStyle style);
161 /// Temporarily replace the FontInfo with \param font, and optionally
162 /// \param realize the \param font against the current FontInfo.
163 Changer change(FontInfo font, bool realize = false);
165 /// Build GUI description of font state
166 docstring const stateText(bool const terse = false) const;
169 friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
184 ColorCode background_;
185 /// The color used for painting
192 FontState strikeout_;
204 FontState nospellcheck_;
208 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
210 return lhs.family_ == rhs.family_
211 && lhs.series_ == rhs.series_
212 && lhs.shape_ == rhs.shape_
213 && lhs.size_ == rhs.size_
214 && lhs.style_ == rhs.style_
215 && lhs.color_ == rhs.color_
216 && lhs.background_ == rhs.background_
217 && lhs.emph_ == rhs.emph_
218 && lhs.underbar_ == rhs.underbar_
219 && lhs.strikeout_ == rhs.strikeout_
220 && lhs.xout_ == rhs.xout_
221 && lhs.uuline_ == rhs.uuline_
222 && lhs.uwave_ == rhs.uwave_
223 && lhs.noun_ == rhs.noun_
224 && lhs.number_ == rhs.number_
225 && lhs.nospellcheck_ == rhs.nospellcheck_;
229 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
231 return !operator==(lhs, rhs);
235 extern FontInfo const sane_font;
236 /// All inherit font.
237 extern FontInfo const inherit_font;
239 extern FontInfo const ignore_font;
241 /// Set family after LyX text format
242 void setLyXFamily(std::string const &, FontInfo &);
244 /// Set series after LyX text format
245 void setLyXSeries(std::string const &, FontInfo &);
247 /// Set shape after LyX text format
248 void setLyXShape(std::string const &, FontInfo &);
250 /// Set size after LyX text format
251 void setLyXSize(std::string const &, FontInfo &);
253 /// Sets color after LyX text format
254 void setLyXColor(std::string const &, FontInfo &);
256 /// Returns misc flag after LyX text format
257 FontState setLyXMisc(std::string const &);
259 /// Read a font specification from Lexer. Used for layout files.
260 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
262 /// Write a font specification. Used for layout files.
263 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);