]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.h
add nls.m4
[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         PainterInfo(BufferView * bv, Painter & pain);
80         ///
81         void draw(int x, int y, char c);
82
83         ///
84         MetricsBase base;
85         ///
86         Painter & pain;
87 };
88
89
90 struct TextMetricsInfo {};
91
92
93 // Generic base for temporarily changing things.
94 // The original state gets restored when the Changer is destructed.
95
96 template <class Struct, class Temp = Struct>
97 struct Changer {
98         ///
99         Changer(Struct & orig) : orig_(orig) {}
100 protected:
101         ///
102         Struct & orig_;
103         ///
104         Temp save_;
105 };
106
107
108
109 // temporarily change some aspect of a font
110 struct FontChanger : public Changer<LyXFont> {
111         ///
112         FontChanger(LyXFont & orig, char const * font);
113         ///
114         ~FontChanger();
115 };
116
117
118 // temporarily change a full font
119 struct FontSetChanger : public Changer<MetricsBase> {
120         ///
121         FontSetChanger(MetricsBase & mb, char const * font);
122         ///
123         ~FontSetChanger();
124 };
125
126
127 // temporarily change the style
128 struct StyleChanger : public Changer<MetricsBase> {
129         ///
130         StyleChanger(MetricsBase & mb, Styles style);
131         ///
132         ~StyleChanger();
133 };
134
135
136 // temporarily change the style to script style
137 struct ScriptChanger : public StyleChanger {
138         ///
139         ScriptChanger(MetricsBase & mb);
140 };
141
142
143 // temporarily change the style suitable for use in fractions
144 struct FracChanger : public StyleChanger {
145         ///
146         FracChanger(MetricsBase & mb);
147 };
148
149
150 // temporarily change the style suitable for use in tabulars and arrays
151 struct ArrayChanger : public StyleChanger {
152         ///
153         ArrayChanger(MetricsBase & mb);
154 };
155
156
157
158 // temporarily change the shape of a font
159 struct ShapeChanger : public Changer<LyXFont, LyXFont::FONT_SHAPE> {
160         ///
161         ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape);
162         ///
163         ~ShapeChanger();
164 };
165
166
167 // temporarily change the available text width
168 struct WidthChanger : public Changer<MetricsBase>
169 {
170         ///
171         WidthChanger(MetricsBase & mb, int width);
172         ///
173         ~WidthChanger();
174 };
175
176
177 // temporarily change the used color
178 struct ColorChanger : public Changer<LyXFont, std::string> {
179         ///
180         ColorChanger(LyXFont & font, std::string const & color);
181         ///
182         ~ColorChanger();
183 };
184
185 #endif