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