]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.h
mathed uglyfication
[lyx.git] / src / metricsinfo.h
1 // -*- C++ -*-
2 /**
3  * \file metricsinfo.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef METRICSINFO_H
13 #define METRICSINFO_H
14
15 #include "lyxfont.h"
16
17 #include <string>
18
19 class Painter;
20 class BufferView;
21
22
23 /// Standard Sizes (mode styles)
24 enum Styles {
25         ///
26         LM_ST_DISPLAY = 0,
27         ///
28         LM_ST_TEXT,
29         ///
30         LM_ST_SCRIPT,
31         ///
32         LM_ST_SCRIPTSCRIPT
33 };
34
35
36 //
37 // This is the part common to MetricsInfo and PainterInfo
38 //
39 struct MetricsBase {
40         ///
41         MetricsBase();
42         ///
43         MetricsBase(BufferView * bv, LyXFont const & font, int textwidth);
44
45         /// the current view
46         BufferView * bv;
47         /// current font
48         LyXFont font;
49         /// current math style (display/text/script/..)
50         Styles style;
51         /// name of current font - mathed specific
52         std::string fontname;
53         /// This is the width available in pixels
54         int textwidth;
55 };
56
57
58 //
59 // This contains a Metricsbase and Information that's only relevant during
60 // the first phase of the two-phase draw
61 //
62 struct MetricsInfo {
63         ///
64         MetricsInfo();
65         ///
66         MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth);
67
68         ///
69         MetricsBase base;
70 };
71
72
73 //
74 // This contains a Metricsbase and Information that's only relevant during
75 // the second phase of the two-phase draw
76 //
77 struct PainterInfo {
78         ///
79         explicit PainterInfo(BufferView * bv);
80         ///
81         void draw(int x, int y, char c);
82
83         ///
84         MetricsBase base;
85         ///
86         Painter & pain;
87         /// width of current item
88         int width;
89 };
90
91
92 struct TextMetricsInfo {};
93
94
95 // Generic base for temporarily changing things.
96 // The original state gets restored when the Changer is destructed.
97
98 template <class Struct, class Temp = Struct>
99 struct Changer {
100         ///
101         Changer(Struct & orig) : orig_(orig) {}
102 protected:
103         ///
104         Struct & orig_;
105         ///
106         Temp save_;
107 };
108
109
110
111 // temporarily change some aspect of a font
112 struct FontChanger : public Changer<LyXFont> {
113         ///
114         FontChanger(LyXFont & orig, char const * font);
115         ///
116         ~FontChanger();
117 };
118
119
120 // temporarily change a full font
121 struct FontSetChanger : public Changer<MetricsBase> {
122         ///
123         FontSetChanger(MetricsBase & mb, char const * font);
124         ///
125         ~FontSetChanger();
126 };
127
128
129 // temporarily change the style
130 struct StyleChanger : public Changer<MetricsBase> {
131         ///
132         StyleChanger(MetricsBase & mb, Styles style);
133         ///
134         ~StyleChanger();
135 };
136
137
138 // temporarily change the style to script style
139 struct ScriptChanger : public StyleChanger {
140         ///
141         ScriptChanger(MetricsBase & mb);
142 };
143
144
145 // temporarily change the style suitable for use in fractions
146 struct FracChanger : public StyleChanger {
147         ///
148         FracChanger(MetricsBase & mb);
149 };
150
151
152 // temporarily change the style suitable for use in tabulars and arrays
153 struct ArrayChanger : public StyleChanger {
154         ///
155         ArrayChanger(MetricsBase & mb);
156 };
157
158
159
160 // temporarily change the shape of a font
161 struct ShapeChanger : public Changer<LyXFont, LyXFont::FONT_SHAPE> {
162         ///
163         ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape);
164         ///
165         ~ShapeChanger();
166 };
167
168
169 // temporarily change the available text width
170 struct WidthChanger : public Changer<MetricsBase>
171 {
172         ///
173         WidthChanger(MetricsBase & mb, int width);
174         ///
175         ~WidthChanger();
176 };
177
178
179 // temporarily change the used color
180 struct ColorChanger : public Changer<LyXFont, std::string> {
181         ///
182         ColorChanger(LyXFont & font, std::string const & color);
183         ///
184         ~ColorChanger();
185 };
186
187 #endif