]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
Merge branch 'master' of git.lyx.org:lyx
[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 uuline,
48                 FontState uwave,
49                 FontState noun,
50                 FontState number)
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)
55         {}
56
57         /// Decreases font size by one
58         FontInfo & decSize();
59         /// Increases font size by one
60         FontInfo & incSize();
61
62         /// \name Accessor methods
63         //@{
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; }
90         //@}
91
92         ///
93         void update(FontInfo const & newfont, bool toggleall);
94
95         /** Reduce font to fall back to template where possible.
96             Equal fields are reduced to INHERIT */
97         void reduce(FontInfo const & tmplt);
98
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;
103
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; }
109
110         ///
111         docstring asCSS() const;
112
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
116         {
117                 if (noun_ == FONT_ON)
118                         return SMALLCAPS_SHAPE;
119                 if (emph_ == FONT_ON)
120                         return (shape_ == ITALIC_SHAPE) ? UP_SHAPE : ITALIC_SHAPE;
121                 return shape_;
122         }
123
124         bool isSymbolFont() const
125         {
126                 switch (family_) {
127                 case SYMBOL_FAMILY:
128                 case CMSY_FAMILY:
129                 case CMM_FAMILY:
130                 case CMEX_FAMILY:
131                 case MSA_FAMILY:
132                 case MSB_FAMILY:
133                 case STMARY_FAMILY:
134                 case WASY_FAMILY:
135                 case ESINT_FAMILY:
136                         return true;
137                 default:
138                         return false;
139                 }
140         }
141
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);
149
150 private:
151         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
152
153         ///
154         FontFamily family_;
155         ///
156         FontSeries series_;
157         ///
158         FontShape shape_;
159         ///
160         FontSize size_;
161         ///
162         ColorCode color_;
163         ///
164         ColorCode background_;
165         /// The color used for painting
166         Color paint_color_;
167         ///
168         FontState emph_;
169         ///
170         FontState underbar_;
171         ///
172         FontState strikeout_;
173         ///
174         FontState uuline_;
175         ///
176         FontState uwave_;
177         ///
178         FontState noun_;
179         ///
180         FontState number_;
181 };
182
183
184 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
185 {
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_;
199 }
200
201
202 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
203 {
204         return !operator==(lhs, rhs);
205 }
206
207 /// Sane font.
208 extern FontInfo const sane_font;
209 /// All inherit font.
210 extern FontInfo const inherit_font;
211 /// All ignore font.
212 extern FontInfo const ignore_font;
213
214 /// Set family after LyX text format
215 void setLyXFamily(std::string const &, FontInfo &);
216
217 /// Set series after LyX text format
218 void setLyXSeries(std::string const &, FontInfo &);
219
220 /// Set shape after LyX text format
221 void setLyXShape(std::string const &, FontInfo &);
222
223 /// Set size after LyX text format
224 void setLyXSize(std::string const &, FontInfo &);
225
226 /// Sets color after LyX text format
227 void setLyXColor(std::string const &, FontInfo &);
228
229 /// Returns misc flag after LyX text format
230 FontState setLyXMisc(std::string const &);
231
232 /// Read a font specification from Lexer. Used for layout files.
233 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
234
235 /// Write a font specification. Used for layout files.
236 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);
237
238 } // namespace lyx
239
240 #endif