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) ? UP_SHAPE : ITALIC_SHAPE;
136 bool isSymbolFont() const
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);
164 /// Build GUI description of font state
165 docstring const stateText(bool const terse = false) const;
168 friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
183 ColorCode background_;
184 /// The color used for painting
191 FontState strikeout_;
203 FontState nospellcheck_;
207 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
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_;
228 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
230 return !operator==(lhs, rhs);
234 extern FontInfo const sane_font;
235 /// All inherit font.
236 extern FontInfo const inherit_font;
238 extern FontInfo const ignore_font;
240 /// Set family after LyX text format
241 void setLyXFamily(std::string const &, FontInfo &);
243 /// Set series after LyX text format
244 void setLyXSeries(std::string const &, FontInfo &);
246 /// Set shape after LyX text format
247 void setLyXShape(std::string const &, FontInfo &);
249 /// Set size after LyX text format
250 void setLyXSize(std::string const &, FontInfo &);
252 /// Sets color after LyX text format
253 void setLyXColor(std::string const &, FontInfo &);
255 /// Returns misc flag after LyX text format
256 FontState setLyXMisc(std::string const &);
258 /// Read a font specification from Lexer. Used for layout files.
259 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
261 /// Write a font specification. Used for layout files.
262 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);