]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
Allow autoconf 2.69 and automake 1.12
[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_ == UP_SHAPE) ? ITALIC_SHAPE : UP_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 WASY_FAMILY:
131                 case ESINT_FAMILY:
132                         return true;
133                 default:
134                         return false;
135                 }
136         }
137
138 private:
139         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
140
141         ///
142         FontFamily family_;
143         ///
144         FontSeries series_;
145         ///
146         FontShape shape_;
147         ///
148         FontSize size_;
149         ///
150         ColorCode color_;
151         ///
152         ColorCode background_;
153         /// The color used for painting
154         Color paint_color_;
155         ///
156         FontState emph_;
157         ///
158         FontState underbar_;
159         ///
160         FontState strikeout_;
161         ///
162         FontState uuline_;
163         ///
164         FontState uwave_;
165         ///
166         FontState noun_;
167         ///
168         FontState number_;
169 };
170
171
172 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
173 {
174         return lhs.family_ == rhs.family_
175                 && lhs.series_ == rhs.series_
176                 && lhs.shape_ == rhs.shape_
177                 && lhs.size_ == rhs.size_
178                 && lhs.color_ == rhs.color_
179                 && lhs.background_ == rhs.background_
180                 && lhs.emph_ == rhs.emph_
181                 && lhs.underbar_ == rhs.underbar_
182                 && lhs.strikeout_ == rhs.strikeout_
183                 && lhs.uuline_ == rhs.uuline_
184                 && lhs.uwave_ == rhs.uwave_
185                 && lhs.noun_ == rhs.noun_
186                 && lhs.number_ == rhs.number_;
187 }
188
189
190 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
191 {
192         return !operator==(lhs, rhs);
193 }
194
195 /// Sane font.
196 extern FontInfo const sane_font;
197 /// All inherit font.
198 extern FontInfo const inherit_font;
199 /// All ignore font.
200 extern FontInfo const ignore_font;
201
202 /// Set family after LyX text format
203 void setLyXFamily(std::string const &, FontInfo &);
204
205 /// Set series after LyX text format
206 void setLyXSeries(std::string const &, FontInfo &);
207
208 /// Set shape after LyX text format
209 void setLyXShape(std::string const &, FontInfo &);
210
211 /// Set size after LyX text format
212 void setLyXSize(std::string const &, FontInfo &);
213
214 /// Sets color after LyX text format
215 void setLyXColor(std::string const &, FontInfo &);
216
217 /// Returns misc flag after LyX text format
218 FontState setLyXMisc(std::string const &);
219
220 /// Read a font specification from Lexer. Used for layout files.
221 FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
222
223 } // namespace lyx
224
225 #endif