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 : family_(family), series_(series), shape_(shape), size_(size),
53 style_(LM_ST_TEXT), color_(color), background_(background), emph_(emph),
54 underbar_(underbar), strikeout_(strikeout), xout_(xout), uuline_(uuline),
55 uwave_(uwave), noun_(noun), number_(number)
58 /// Decreases font size by one
60 /// Increases font size by one
63 /// \name Accessor methods
65 FontFamily family() const { return family_; }
66 void setFamily(FontFamily f) { family_ = f; }
67 FontSeries series() const { return series_; }
68 void setSeries(FontSeries s) { series_ = s; }
69 FontShape shape() const { return shape_; }
70 void setShape(FontShape s) { shape_ = s; }
71 FontSize size() const { return size_; }
72 void setSize(FontSize s) { size_ = s; }
73 MathStyle style() const {return style_; }
74 void setStyle(MathStyle s) { style_ = s; }
75 FontState emph() const { return emph_; }
76 void setEmph(FontState e) { emph_ = e; }
77 FontState underbar() const { return underbar_; }
78 void setUnderbar(FontState u) { underbar_ = u; }
79 FontState strikeout() const { return strikeout_; }
80 void setStrikeout(FontState s) { strikeout_ = s; }
81 FontState xout() const { return xout_; }
82 void setXout(FontState s) { xout_ = s; }
83 FontState uuline() const { return uuline_; }
84 void setUuline(FontState s) { uuline_ = s; }
85 FontState uwave() const { return uwave_; }
86 void setUwave(FontState s) { uwave_ = s; }
87 FontState noun() const { return noun_; }
88 void setNoun(FontState n) { noun_ = n; }
89 FontState number() const { return number_; }
90 void setNumber(FontState n) { number_ = n; }
91 ColorCode color() const { return color_; }
92 void setColor(ColorCode c) { color_ = c; }
93 ColorCode background() const { return background_; }
94 void setBackground(ColorCode b) { background_ = b; }
98 void update(FontInfo const & newfont, bool toggleall);
100 /** Reduce font to fall back to template where possible.
101 Equal fields are reduced to INHERIT */
102 void reduce(FontInfo const & tmplt);
104 /// Realize font from a template (INHERIT are realized)
105 FontInfo & realize(FontInfo const & tmplt);
106 /// Is a given font fully resolved?
107 bool resolved() const;
109 /// The real color of the font. This can be the color that is
110 /// set for painting, the color of the font or a default color.
111 Color realColor() const;
112 /// Sets the color which is used during painting
113 void setPaintColor(Color c) { paint_color_ = c; }
115 /// Compute the font size, taking size and math style into account.
116 double realSize() const;
119 docstring asCSS() const;
121 /// Converts logical attributes to concrete shape attribute
122 /// Try hard to inline this as it shows up with 4.6 % in the profiler.
123 FontShape realShape() const
125 if (noun_ == FONT_ON)
126 return SMALLCAPS_SHAPE;
127 if (emph_ == FONT_ON)
128 return (shape_ == ITALIC_SHAPE) ? UP_SHAPE : ITALIC_SHAPE;
132 bool isSymbolFont() const
150 /// Temporarily replace the color with \param color.
151 Changer changeColor(ColorCode const color);
152 /// Temporarily replace the shape with \param shape.
153 Changer changeShape(FontShape const shape);
154 /// Temporarily replace the style
155 Changer changeStyle(MathStyle style);
156 /// Temporarily replace the FontInfo with \param font, and optionally
157 /// \param realize the \param font against the current FontInfo.
158 Changer change(FontInfo font, bool realize = false);
161 friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
176 ColorCode background_;
177 /// The color used for painting
184 FontState strikeout_;
198 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
200 return lhs.family_ == rhs.family_
201 && lhs.series_ == rhs.series_
202 && lhs.shape_ == rhs.shape_
203 && lhs.size_ == rhs.size_
204 && lhs.color_ == rhs.color_
205 && lhs.background_ == rhs.background_
206 && lhs.emph_ == rhs.emph_
207 && lhs.underbar_ == rhs.underbar_
208 && lhs.strikeout_ == rhs.strikeout_
209 && lhs.xout_ == rhs.xout_
210 && lhs.uuline_ == rhs.uuline_
211 && lhs.uwave_ == rhs.uwave_
212 && lhs.noun_ == rhs.noun_
213 && lhs.number_ == rhs.number_;
217 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
219 return !operator==(lhs, rhs);
223 extern FontInfo const sane_font;
224 /// All inherit font.
225 extern FontInfo const inherit_font;
227 extern FontInfo const ignore_font;
229 /// Set family after LyX text format
230 void setLyXFamily(std::string const &, FontInfo &);
232 /// Set series after LyX text format
233 void setLyXSeries(std::string const &, FontInfo &);
235 /// Set shape after LyX text format
236 void setLyXShape(std::string const &, FontInfo &);
238 /// Set size after LyX text format
239 void setLyXSize(std::string const &, FontInfo &);
241 /// Sets color after LyX text format
242 void setLyXColor(std::string const &, FontInfo &);
244 /// Returns misc flag after LyX text format
245 FontState setLyXMisc(std::string const &);
247 /// Read a font specification from Lexer. Used for layout files.
248 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
250 /// Write a font specification. Used for layout files.
251 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);