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