]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
29f26f2d8f71bc0d2f067f2e9bf21d71f092d200
[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), 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         Color drawColor() const { return draw_color_; }
79         void setDrawColor(Color c) { draw_color_ = c; }
80         ///@}
81
82         ///
83         void update(FontInfo const & newfont, bool toggleall);
84
85         /** Reduce font to fall back to template where possible.
86             Equal fields are reduced to INHERIT */
87         void reduce(FontInfo const & tmplt);
88
89         /// Realize font from a template (INHERIT are realized)
90         FontInfo & realize(FontInfo const & tmplt);
91         /// Is a given font fully resolved?
92         bool resolved() const;
93
94         ///
95         Color realColor() const;
96
97         /// Converts logical attributes to concrete shape attribute
98         /// Try hard to inline this as it shows up with 4.6 % in the profiler.
99         FontShape realShape() const
100         {
101                 if (noun_ == FONT_ON)
102                         return SMALLCAPS_SHAPE;
103                 if (emph_ == FONT_ON)
104                         return (shape_ == UP_SHAPE) ? ITALIC_SHAPE : UP_SHAPE;
105                 return shape_;
106         }
107
108         bool isSymbolFont() const
109         {
110                 switch (family_) {
111                 case SYMBOL_FAMILY:
112                 case CMSY_FAMILY:
113                 case CMM_FAMILY:
114                 case CMEX_FAMILY:
115                 case MSA_FAMILY:
116                 case MSB_FAMILY:
117                 case WASY_FAMILY:
118                 case ESINT_FAMILY:
119                         return true;
120                 default:
121                         return false;
122                 }
123         }
124
125 private:
126         friend bool operator==(FontInfo const & lhs, FontInfo const & rhs);
127
128         ///
129         FontFamily family_;
130         ///
131         FontSeries series_;
132         ///
133         FontShape shape_;
134         ///
135         FontSize size_;
136         ///
137         ColorCode color_;
138         ///
139         ColorCode background_;
140         ///
141         Color draw_color_;
142         ///
143         FontState emph_;
144         ///
145         FontState underbar_;
146         ///
147         FontState noun_;
148         ///
149         FontState number_;
150 };
151
152
153 inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
154 {
155         return lhs.family_ == rhs.family_
156                 && lhs.series_ == rhs.series_
157                 && lhs.shape_ == rhs.shape_
158                 && lhs.size_ == rhs.size_
159                 && lhs.color_ == rhs.color_
160                 && lhs.background_ == rhs.background_
161                 && lhs.emph_ == rhs.emph_
162                 && lhs.underbar_ == rhs.underbar_
163                 && lhs.noun_ == rhs.noun_
164                 && lhs.number_ == rhs.number_;
165 }
166
167
168 inline bool operator!=(FontInfo const & lhs, FontInfo const & rhs)
169 {
170         return !operator==(lhs, rhs);
171 }
172
173 /// Sane font.
174 extern FontInfo const sane_font;
175 /// All inherit font.
176 extern FontInfo const inherit_font;
177 /// All ignore font.
178 extern FontInfo const ignore_font;
179
180 } // namespace lyx
181
182 #endif // TEX2LYX_FONT_H
183 #endif