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