]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
Reduce horizontal spacing for simple inline equations
[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                 style_(LM_ST_TEXT), color_(color), background_(background), 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         MathStyle style() const {return style_; }
73         void setStyle(MathStyle s) { style_ = s; }
74         FontState emph() const { return emph_; }
75         void setEmph(FontState e) { emph_ = e; }
76         FontState underbar() const { return underbar_; }
77         void setUnderbar(FontState u) { underbar_ = u; }
78         FontState strikeout() const { return strikeout_; }
79         void setStrikeout(FontState s) { strikeout_ = s; }
80         FontState uuline() const { return uuline_; }
81         void setUuline(FontState s) { uuline_ = s; }
82         FontState uwave() const { return uwave_; }
83         void setUwave(FontState s) { uwave_ = s; }
84         FontState noun() const { return noun_; }
85         void setNoun(FontState n) { noun_ = n; }
86         FontState number() const { return number_; }
87         void setNumber(FontState n) { number_ = n; }
88         ColorCode color() const { return color_; }
89         void setColor(ColorCode c) { color_ = c; }
90         ColorCode background() const { return background_; }
91         void setBackground(ColorCode b) { background_ = b; }
92         //@}
93
94         ///
95         void update(FontInfo const & newfont, bool toggleall);
96
97         /** Reduce font to fall back to template where possible.
98             Equal fields are reduced to INHERIT */
99         void reduce(FontInfo const & tmplt);
100
101         /// Realize font from a template (INHERIT are realized)
102         FontInfo & realize(FontInfo const & tmplt);
103         /// Is a given font fully resolved?
104         bool resolved() const;
105
106         /// The real color of the font. This can be the color that is 
107         /// set for painting, the color of the font or a default color.
108         Color realColor() const;
109         /// Sets the color which is used during painting
110         void setPaintColor(Color c) { paint_color_ = c; }
111
112         /// Compute the font size, taking size and math style into account.
113         double realSize() const;
114
115         ///
116         docstring asCSS() const;
117
118         /// Converts logical attributes to concrete shape attribute
119         /// Try hard to inline this as it shows up with 4.6 % in the profiler.
120         FontShape realShape() const
121         {
122                 if (noun_ == FONT_ON)
123                         return SMALLCAPS_SHAPE;
124                 if (emph_ == FONT_ON)
125                         return (shape_ == ITALIC_SHAPE) ? UP_SHAPE : ITALIC_SHAPE;
126                 return shape_;
127         }
128
129         bool isSymbolFont() const
130         {
131                 switch (family_) {
132                 case SYMBOL_FAMILY:
133                 case CMSY_FAMILY:
134                 case CMM_FAMILY:
135                 case CMEX_FAMILY:
136                 case MSA_FAMILY:
137                 case MSB_FAMILY:
138                 case STMARY_FAMILY:
139                 case WASY_FAMILY:
140                 case ESINT_FAMILY:
141                         return true;
142                 default:
143                         return false;
144                 }
145         }
146
147         /// Temporarily replace the color with \param color.
148         Changer changeColor(ColorCode const color);
149         /// Temporarily replace the shape with \param shape.
150         Changer changeShape(FontShape const shape);
151         /// Temporarily replace the style
152         Changer changeStyle(MathStyle style);
153         /// Temporarily replace the FontInfo with \param font, and optionally
154         /// \param realize the \param font against the current FontInfo.
155         Changer change(FontInfo font, bool realize = false);
156
157 private:
158         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
159
160         ///
161         FontFamily family_;
162         ///
163         FontSeries series_;
164         ///
165         FontShape shape_;
166         ///
167         FontSize size_;
168         ///
169         MathStyle style_;
170         ///
171         ColorCode color_;
172         ///
173         ColorCode background_;
174         /// The color used for painting
175         Color paint_color_;
176         ///
177         FontState emph_;
178         ///
179         FontState underbar_;
180         ///
181         FontState strikeout_;
182         ///
183         FontState uuline_;
184         ///
185         FontState uwave_;
186         ///
187         FontState noun_;
188         ///
189         FontState number_;
190 };
191
192
193 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
194 {
195         return lhs.family_ == rhs.family_
196                 && lhs.series_ == rhs.series_
197                 && lhs.shape_ == rhs.shape_
198                 && lhs.size_ == rhs.size_
199                 && lhs.color_ == rhs.color_
200                 && lhs.background_ == rhs.background_
201                 && lhs.emph_ == rhs.emph_
202                 && lhs.underbar_ == rhs.underbar_
203                 && lhs.strikeout_ == rhs.strikeout_
204                 && lhs.uuline_ == rhs.uuline_
205                 && lhs.uwave_ == rhs.uwave_
206                 && lhs.noun_ == rhs.noun_
207                 && lhs.number_ == rhs.number_;
208 }
209
210
211 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
212 {
213         return !operator==(lhs, rhs);
214 }
215
216 /// Sane font.
217 extern FontInfo const sane_font;
218 /// All inherit font.
219 extern FontInfo const inherit_font;
220 /// All ignore font.
221 extern FontInfo const ignore_font;
222
223 /// Set family after LyX text format
224 void setLyXFamily(std::string const &, FontInfo &);
225
226 /// Set series after LyX text format
227 void setLyXSeries(std::string const &, FontInfo &);
228
229 /// Set shape after LyX text format
230 void setLyXShape(std::string const &, FontInfo &);
231
232 /// Set size after LyX text format
233 void setLyXSize(std::string const &, FontInfo &);
234
235 /// Sets color after LyX text format
236 void setLyXColor(std::string const &, FontInfo &);
237
238 /// Returns misc flag after LyX text format
239 FontState setLyXMisc(std::string const &);
240
241 /// Read a font specification from Lexer. Used for layout files.
242 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
243
244 /// Write a font specification. Used for layout files.
245 void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);
246
247 } // namespace lyx
248
249 #endif