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