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"
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)
59 /// Decreases font size by one
61 /// Increases font size by one
64 /// \name Accessor methods
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; }
101 void update(FontInfo const & newfont, bool toggleall);
103 /** Reduce font to fall back to template where possible.
104 Equal fields are reduced to INHERIT */
105 void reduce(FontInfo const & tmplt);
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;
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; }
118 /// Compute the font size, taking size and math style into account.
119 double realSize() const;
122 docstring asCSS() const;
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
128 if (noun_ == FONT_ON)
129 return SMALLCAPS_SHAPE;
130 if (emph_ == FONT_ON)
131 return (shape_ == ITALIC_SHAPE) ? UP_SHAPE : ITALIC_SHAPE;
135 bool isSymbolFont() const
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);
164 friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
179 ColorCode background_;
180 /// The color used for painting
187 FontState strikeout_;
199 FontState nospellcheck_;
203 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
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_;
223 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
225 return !operator==(lhs, rhs);
229 extern FontInfo const sane_font;
230 /// All inherit font.
231 extern FontInfo const inherit_font;
233 extern FontInfo const ignore_font;
235 /// Set family after LyX text format
236 void setLyXFamily(std::string const &, FontInfo &);
238 /// Set series after LyX text format
239 void setLyXSeries(std::string const &, FontInfo &);
241 /// Set shape after LyX text format
242 void setLyXShape(std::string const &, FontInfo &);
244 /// Set size after LyX text format
245 void setLyXSize(std::string const &, FontInfo &);
247 /// Sets color after LyX text format
248 void setLyXColor(std::string const &, FontInfo &);
250 /// Returns misc flag after LyX text format
251 FontState setLyXMisc(std::string const &);
253 /// Read a font specification from Lexer. Used for layout files.
254 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
256 /// Write a font specification. Used for layout files.
257 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);