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