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 color_(color), background_(background), paint_color_(), 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 FontState emph() const { return emph_; }
73 void setEmph(FontState e) { emph_ = e; }
74 FontState underbar() const { return underbar_; }
75 void setUnderbar(FontState u) { underbar_ = u; }
76 FontState strikeout() const { return strikeout_; }
77 void setStrikeout(FontState s) { strikeout_ = s; }
78 FontState uuline() const { return uuline_; }
79 void setUuline(FontState s) { uuline_ = s; }
80 FontState uwave() const { return uwave_; }
81 void setUwave(FontState s) { uwave_ = s; }
82 FontState noun() const { return noun_; }
83 void setNoun(FontState n) { noun_ = n; }
84 FontState number() const { return number_; }
85 void setNumber(FontState n) { number_ = n; }
86 ColorCode color() const { return color_; }
87 void setColor(ColorCode c) { color_ = c; }
88 ColorCode background() const { return background_; }
89 void setBackground(ColorCode b) { background_ = b; }
93 void update(FontInfo const & newfont, bool toggleall);
95 /** Reduce font to fall back to template where possible.
96 Equal fields are reduced to INHERIT */
97 void reduce(FontInfo const & tmplt);
99 /// Realize font from a template (INHERIT are realized)
100 FontInfo & realize(FontInfo const & tmplt);
101 /// Is a given font fully resolved?
102 bool resolved() const;
104 /// The real color of the font. This can be the color that is
105 /// set for painting, the color of the font or a default color.
106 Color realColor() const;
107 /// Sets the color which is used during painting
108 void setPaintColor(Color c) { paint_color_ = c; }
111 docstring asCSS() const;
113 /// Converts logical attributes to concrete shape attribute
114 /// Try hard to inline this as it shows up with 4.6 % in the profiler.
115 FontShape realShape() const
117 if (noun_ == FONT_ON)
118 return SMALLCAPS_SHAPE;
119 if (emph_ == FONT_ON)
120 return (shape_ == ITALIC_SHAPE) ? UP_SHAPE : ITALIC_SHAPE;
124 bool isSymbolFont() const
142 /// Temporarily replace the color with \param color.
143 Changer changeColor(ColorCode const color, bool cond = true);
144 /// Temporarily replace the shape with \param shape.
145 Changer changeShape(FontShape const shape, bool cond = true);
146 /// Temporarily replace the FontInfo with \param font, and optionally
147 /// \param realize the \param font against the current FontInfo.
148 Changer change(FontInfo font, bool realize = false, bool cond = true);
151 friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
164 ColorCode background_;
165 /// The color used for painting
172 FontState strikeout_;
184 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
186 return lhs.family_ == rhs.family_
187 && lhs.series_ == rhs.series_
188 && lhs.shape_ == rhs.shape_
189 && lhs.size_ == rhs.size_
190 && lhs.color_ == rhs.color_
191 && lhs.background_ == rhs.background_
192 && lhs.emph_ == rhs.emph_
193 && lhs.underbar_ == rhs.underbar_
194 && lhs.strikeout_ == rhs.strikeout_
195 && lhs.uuline_ == rhs.uuline_
196 && lhs.uwave_ == rhs.uwave_
197 && lhs.noun_ == rhs.noun_
198 && lhs.number_ == rhs.number_;
202 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
204 return !operator==(lhs, rhs);
208 extern FontInfo const sane_font;
209 /// All inherit font.
210 extern FontInfo const inherit_font;
212 extern FontInfo const ignore_font;
214 /// Set family after LyX text format
215 void setLyXFamily(std::string const &, FontInfo &);
217 /// Set series after LyX text format
218 void setLyXSeries(std::string const &, FontInfo &);
220 /// Set shape after LyX text format
221 void setLyXShape(std::string const &, FontInfo &);
223 /// Set size after LyX text format
224 void setLyXSize(std::string const &, FontInfo &);
226 /// Sets color after LyX text format
227 void setLyXColor(std::string const &, FontInfo &);
229 /// Returns misc flag after LyX text format
230 FontState setLyXMisc(std::string const &);
232 /// Read a font specification from Lexer. Used for layout files.
233 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
235 /// Write a font specification. Used for layout files.
236 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);