]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
Provide proper fallback if a bibliography processor is not found
[lyx.git] / src / FontInfo.h
1 // -*- C++ -*-
2 /**
3  * \file src/FontInfo.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author Angus Leeming
10  * \author Dekel Tsur
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef FONT_PROPERTIES_H
16 #define FONT_PROPERTIES_H
17
18 #include "Color.h"
19 #include "ColorCode.h"
20 #include "FontEnums.h"
21
22 #include "support/Changer.h"
23 #include "support/strfwd.h"
24
25
26 namespace lyx {
27
28 class Lexer;
29
30 ///
31 class FontInfo
32 {
33 public:
34         ///
35         FontInfo();
36         ///
37         FontInfo(
38                 FontFamily family,
39                 FontSeries series,
40                 FontShape  shape,
41                 FontSize   size,
42                 ColorCode  color,
43                 ColorCode  background,
44                 FontState  emph,
45                 FontState  underbar,
46                 FontState  strikeout,
47                 FontState  xout,
48                 FontState  uuline,
49                 FontState  uwave,
50                 FontState  noun,
51                 FontState  number)
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)
56         {}
57
58         /// Decreases font size by one
59         FontInfo & decSize();
60         /// Increases font size by one
61         FontInfo & incSize();
62
63         /// \name Accessor methods
64         //@{
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; }
95         //@}
96
97         ///
98         void update(FontInfo const & newfont, bool toggleall);
99
100         /** Reduce font to fall back to template where possible.
101             Equal fields are reduced to INHERIT */
102         void reduce(FontInfo const & tmplt);
103
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;
108
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; }
114
115         /// Compute the font size, taking size and math style into account.
116         double realSize() const;
117
118         ///
119         docstring asCSS() const;
120
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
124         {
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;
130                 return shape_;
131         }
132
133         bool isSymbolFont() const
134         {
135                 switch (family_) {
136                 case SYMBOL_FAMILY:
137                 case CMSY_FAMILY:
138                 case CMM_FAMILY:
139                 case CMEX_FAMILY:
140                 case MSA_FAMILY:
141                 case MSB_FAMILY:
142                 case STMARY_FAMILY:
143                 case WASY_FAMILY:
144                 case ESINT_FAMILY:
145                         return true;
146                 default:
147                         return false;
148                 }
149         }
150
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);
160
161 private:
162         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
163
164         ///
165         FontFamily family_;
166         ///
167         FontSeries series_;
168         ///
169         FontShape shape_;
170         ///
171         FontSize size_;
172         ///
173         MathStyle style_;
174         ///
175         ColorCode color_;
176         ///
177         ColorCode background_;
178         /// The color used for painting
179         Color paint_color_;
180         ///
181         FontState emph_;
182         ///
183         FontState underbar_;
184         ///
185         FontState strikeout_;
186         ///
187         FontState xout_;
188         ///
189         FontState uuline_;
190         ///
191         FontState uwave_;
192         ///
193         FontState noun_;
194         ///
195         FontState number_;
196 };
197
198
199 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
200 {
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_;
215 }
216
217
218 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
219 {
220         return !operator==(lhs, rhs);
221 }
222
223 /// Sane font.
224 extern FontInfo const sane_font;
225 /// All inherit font.
226 extern FontInfo const inherit_font;
227 /// All ignore font.
228 extern FontInfo const ignore_font;
229
230 /// Set family after LyX text format
231 void setLyXFamily(std::string const &, FontInfo &);
232
233 /// Set series after LyX text format
234 void setLyXSeries(std::string const &, FontInfo &);
235
236 /// Set shape after LyX text format
237 void setLyXShape(std::string const &, FontInfo &);
238
239 /// Set size after LyX text format
240 void setLyXSize(std::string const &, FontInfo &);
241
242 /// Sets color after LyX text format
243 void setLyXColor(std::string const &, FontInfo &);
244
245 /// Returns misc flag after LyX text format
246 FontState setLyXMisc(std::string const &);
247
248 /// Read a font specification from Lexer. Used for layout files.
249 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
250
251 /// Write a font specification. Used for layout files.
252 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);
253
254 } // namespace lyx
255
256 #endif