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 || shape_ == SLANTED_SHAPE)
129 ? UP_SHAPE : ITALIC_SHAPE;
133 bool isSymbolFont() const
151 /// Temporarily replace the color with \param color.
152 Changer changeColor(ColorCode const color);
153 /// Temporarily replace the shape with \param shape.
154 Changer changeShape(FontShape const shape);
155 /// Temporarily replace the style
156 Changer changeStyle(MathStyle style);
157 /// Temporarily replace the FontInfo with \param font, and optionally
158 /// \param realize the \param font against the current FontInfo.
159 Changer change(FontInfo font, bool realize = false);
162 friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
177 ColorCode background_;
178 /// The color used for painting
185 FontState strikeout_;
199 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
201 return lhs.family_ == rhs.family_
202 && lhs.series_ == rhs.series_
203 && lhs.shape_ == rhs.shape_
204 && lhs.size_ == rhs.size_
205 && lhs.color_ == rhs.color_
206 && lhs.background_ == rhs.background_
207 && lhs.emph_ == rhs.emph_
208 && lhs.underbar_ == rhs.underbar_
209 && lhs.strikeout_ == rhs.strikeout_
210 && lhs.xout_ == rhs.xout_
211 && lhs.uuline_ == rhs.uuline_
212 && lhs.uwave_ == rhs.uwave_
213 && lhs.noun_ == rhs.noun_
214 && lhs.number_ == rhs.number_;
218 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
220 return !operator==(lhs, rhs);
224 extern FontInfo const sane_font;
225 /// All inherit font.
226 extern FontInfo const inherit_font;
228 extern FontInfo const ignore_font;
230 /// Set family after LyX text format
231 void setLyXFamily(std::string const &, FontInfo &);
233 /// Set series after LyX text format
234 void setLyXSeries(std::string const &, FontInfo &);
236 /// Set shape after LyX text format
237 void setLyXShape(std::string const &, FontInfo &);
239 /// Set size after LyX text format
240 void setLyXSize(std::string const &, FontInfo &);
242 /// Sets color after LyX text format
243 void setLyXColor(std::string const &, FontInfo &);
245 /// Returns misc flag after LyX text format
246 FontState setLyXMisc(std::string const &);
248 /// Read a font specification from Lexer. Used for layout files.
249 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
251 /// Write a font specification. Used for layout files.
252 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);