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