]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.h
two-phase-drawing for InsetText & InsetTabular
[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
40         string fontname;
41         /// if this is set...
42         bool restrictwidth;
43         /// ... this is valid
44         int textwidth;
45 };
46
47
48 //
49 // This contains a Metricsbase and Information that's only relevant during
50 // the first phase of the two-phase draw
51 //
52 struct MetricsInfo {
53         ///
54         MetricsInfo();
55         ///
56         MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth);
57
58         ///
59         MetricsBase base;
60 };
61
62
63 //
64 // This contains a Metricsbase and Information that's only relevant during
65 // the second phase of the two-phase draw
66 //
67 struct PainterInfo {
68         ///
69         explicit PainterInfo(BufferView * bv);
70         ///
71         void draw(int x, int y, char c);
72
73         ///
74         MetricsBase base;
75         ///
76         Painter & pain;
77         /// width of current item
78         int width;
79 };
80
81
82 struct TextMetricsInfo {};
83
84
85 // Generic base for temporarily changing things.
86 // The original state gets restored when the Changer is destructed.
87
88 template <class Struct, class Temp = Struct>
89 struct Changer {
90         ///
91         Changer(Struct & orig) : orig_(orig) {}
92 protected:
93         ///
94         Struct & orig_;
95         ///
96         Temp save_;
97 };
98
99
100
101 // temporarily change some aspect of a font
102 struct FontChanger : public Changer<LyXFont> {
103         ///
104         FontChanger(LyXFont & orig, char const * font);
105         ///
106         ~FontChanger();
107 };
108
109
110 // temporarily change a full font
111 struct FontSetChanger : public Changer<MetricsBase> {
112         ///
113         FontSetChanger(MetricsBase & mb, char const * font);
114         ///
115         ~FontSetChanger();
116 };
117
118
119 // temporarily change the style
120 struct StyleChanger : public Changer<MetricsBase> {
121         ///
122         StyleChanger(MetricsBase & mb, Styles style);
123         ///
124         ~StyleChanger();
125 };
126
127
128 // temporarily change the style to script style
129 struct ScriptChanger : public StyleChanger {
130         ///
131         ScriptChanger(MetricsBase & mb);
132 };
133
134
135 // temporarily change the style suitable for use in fractions
136 struct FracChanger : public StyleChanger {
137         ///
138         FracChanger(MetricsBase & mb);
139 };
140
141
142 // temporarily change the style suitable for use in tabulars and arrays
143 struct ArrayChanger : public StyleChanger {
144         ///
145         ArrayChanger(MetricsBase & mb);
146 };
147
148
149
150 // temporarily change the shape of a font
151 struct ShapeChanger : public Changer<LyXFont, LyXFont::FONT_SHAPE> {
152         ///
153         ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape);
154         ///
155         ~ShapeChanger();
156 };
157
158
159 // temporarily change the available text width
160 struct WidthChanger : public Changer<MetricsBase>
161 {
162         ///
163         WidthChanger(MetricsBase & mb, int width);
164         ///
165         ~WidthChanger();
166 };
167
168
169 #endif