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