]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
prepare Qt 5.6 builds
[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 #include "support/strfwd.h"
22
23 namespace lyx {
24
25 class Lexer;
26
27 ///
28 class FontInfo
29 {
30 public:
31         ///
32         FontInfo();
33         ///
34         FontInfo(
35                 FontFamily family,
36                 FontSeries series,
37                 FontShape shape,
38                 FontSize size,
39                 ColorCode color,
40                 ColorCode background,
41                 FontState emph,
42                 FontState underbar,
43                 FontState strikeout,
44                 FontState uuline,
45                 FontState uwave,
46                 FontState noun,
47                 FontState number)
48                 : family_(family), series_(series), shape_(shape), size_(size), 
49                 color_(color), background_(background), paint_color_(), emph_(emph),
50                 underbar_(underbar), strikeout_(strikeout), uuline_(uuline),
51                 uwave_(uwave), noun_(noun), number_(number)
52         {}
53
54         /// Decreases font size by one
55         FontInfo & decSize();
56         /// Increases font size by one
57         FontInfo & incSize();
58
59         /// \name Accessor methods
60         //@{
61         FontFamily family() const { return family_; }
62         void setFamily(FontFamily f) { family_ = f; }
63         FontSeries series() const { return series_; }
64         void setSeries(FontSeries s) { series_ = s; }
65         FontShape shape() const { return shape_; }
66         void setShape(FontShape s) { shape_ = s; }
67         FontSize size() const { return size_; }
68         void setSize(FontSize s) { size_ = s; }
69         FontState emph() const { return emph_; }
70         void setEmph(FontState e) { emph_ = e; }
71         FontState underbar() const { return underbar_; }
72         void setUnderbar(FontState u) { underbar_ = u; }
73         FontState strikeout() const { return strikeout_; }
74         void setStrikeout(FontState s) { strikeout_ = s; }
75         FontState uuline() const { return uuline_; }
76         void setUuline(FontState s) { uuline_ = s; }
77         FontState uwave() const { return uwave_; }
78         void setUwave(FontState s) { uwave_ = s; }
79         FontState noun() const { return noun_; }
80         void setNoun(FontState n) { noun_ = n; }
81         FontState number() const { return number_; }
82         void setNumber(FontState n) { number_ = n; }
83         ColorCode color() const { return color_; }
84         void setColor(ColorCode c) { color_ = c; }
85         ColorCode background() const { return background_; }
86         void setBackground(ColorCode b) { background_ = b; }
87         //@}
88
89         ///
90         void update(FontInfo const & newfont, bool toggleall);
91
92         /** Reduce font to fall back to template where possible.
93             Equal fields are reduced to INHERIT */
94         void reduce(FontInfo const & tmplt);
95
96         /// Realize font from a template (INHERIT are realized)
97         FontInfo & realize(FontInfo const & tmplt);
98         /// Is a given font fully resolved?
99         bool resolved() const;
100
101         /// The real color of the font. This can be the color that is 
102         /// set for painting, the color of the font or a default color.
103         Color realColor() const;
104         /// Sets the color which is used during painting
105         void setPaintColor(Color c) { paint_color_ = c; }
106
107         ///
108         docstring asCSS() const;
109
110         /// Converts logical attributes to concrete shape attribute
111         /// Try hard to inline this as it shows up with 4.6 % in the profiler.
112         FontShape realShape() const
113         {
114                 if (noun_ == FONT_ON)
115                         return SMALLCAPS_SHAPE;
116                 if (emph_ == FONT_ON)
117                         return (shape_ == ITALIC_SHAPE) ? UP_SHAPE : ITALIC_SHAPE;
118                 return shape_;
119         }
120
121         bool isSymbolFont() const
122         {
123                 switch (family_) {
124                 case SYMBOL_FAMILY:
125                 case CMSY_FAMILY:
126                 case CMM_FAMILY:
127                 case CMEX_FAMILY:
128                 case MSA_FAMILY:
129                 case MSB_FAMILY:
130                 case STMARY_FAMILY:
131                 case WASY_FAMILY:
132                 case ESINT_FAMILY:
133                         return true;
134                 default:
135                         return false;
136                 }
137         }
138
139 private:
140         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
141
142         ///
143         FontFamily family_;
144         ///
145         FontSeries series_;
146         ///
147         FontShape shape_;
148         ///
149         FontSize size_;
150         ///
151         ColorCode color_;
152         ///
153         ColorCode background_;
154         /// The color used for painting
155         Color paint_color_;
156         ///
157         FontState emph_;
158         ///
159         FontState underbar_;
160         ///
161         FontState strikeout_;
162         ///
163         FontState uuline_;
164         ///
165         FontState uwave_;
166         ///
167         FontState noun_;
168         ///
169         FontState number_;
170 };
171
172
173 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
174 {
175         return lhs.family_ == rhs.family_
176                 && lhs.series_ == rhs.series_
177                 && lhs.shape_ == rhs.shape_
178                 && lhs.size_ == rhs.size_
179                 && lhs.color_ == rhs.color_
180                 && lhs.background_ == rhs.background_
181                 && lhs.emph_ == rhs.emph_
182                 && lhs.underbar_ == rhs.underbar_
183                 && lhs.strikeout_ == rhs.strikeout_
184                 && lhs.uuline_ == rhs.uuline_
185                 && lhs.uwave_ == rhs.uwave_
186                 && lhs.noun_ == rhs.noun_
187                 && lhs.number_ == rhs.number_;
188 }
189
190
191 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
192 {
193         return !operator==(lhs, rhs);
194 }
195
196 /// Sane font.
197 extern FontInfo const sane_font;
198 /// All inherit font.
199 extern FontInfo const inherit_font;
200 /// All ignore font.
201 extern FontInfo const ignore_font;
202
203 /// Set family after LyX text format
204 void setLyXFamily(std::string const &, FontInfo &);
205
206 /// Set series after LyX text format
207 void setLyXSeries(std::string const &, FontInfo &);
208
209 /// Set shape after LyX text format
210 void setLyXShape(std::string const &, FontInfo &);
211
212 /// Set size after LyX text format
213 void setLyXSize(std::string const &, FontInfo &);
214
215 /// Sets color after LyX text format
216 void setLyXColor(std::string const &, FontInfo &);
217
218 /// Returns misc flag after LyX text format
219 FontState setLyXMisc(std::string const &);
220
221 /// Read a font specification from Lexer. Used for layout files.
222 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
223
224 /// Write a font specification. Used for layout files.
225 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);
226
227 } // namespace lyx
228
229 #endif