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