]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
8db78d5ce1a492fe52e7ada0ecbf491cc1df9ba2
[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         ///
130         FontFamily family_;
131         ///
132         FontSeries series_;
133         ///
134         FontShape shape_;
135         ///
136         FontSize size_;
137         ///
138         ColorCode color_;
139         ///
140         ColorCode background_;
141         /// The color used for painting
142         Color paint_color_;
143         ///
144         FontState emph_;
145         ///
146         FontState underbar_;
147         ///
148         FontState noun_;
149         ///
150         FontState number_;
151 };
152
153
154 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
155 {
156         return lhs.family_ == rhs.family_
157                 && lhs.series_ == rhs.series_
158                 && lhs.shape_ == rhs.shape_
159                 && lhs.size_ == rhs.size_
160                 && lhs.color_ == rhs.color_
161                 && lhs.background_ == rhs.background_
162                 && lhs.emph_ == rhs.emph_
163                 && lhs.underbar_ == rhs.underbar_
164                 && lhs.noun_ == rhs.noun_
165                 && lhs.number_ == rhs.number_;
166 }
167
168
169 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
170 {
171         return !operator==(lhs, rhs);
172 }
173
174 /// Sane font.
175 extern FontInfo const sane_font;
176 /// All inherit font.
177 extern FontInfo const inherit_font;
178 /// All ignore font.
179 extern FontInfo const ignore_font;
180
181 } // namespace lyx
182
183 #endif // TEX2LYX_FONT_H
184 #endif