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