]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
* gcc does not like missing characters in keywords
[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 "ColorCode.h"
16 #include "FontInfo.h"
17
18 #include "support/strfwd.h"
19 #include "support/types.h"
20
21 #include <string>
22
23 class BufferView;
24
25 namespace lyx {
26
27 namespace frontend { class Painter; }
28
29
30 /// Standard Sizes (mode styles)
31 enum Styles {
32         ///
33         LM_ST_DISPLAY = 0,
34         ///
35         LM_ST_TEXT,
36         ///
37         LM_ST_SCRIPT,
38         ///
39         LM_ST_SCRIPTSCRIPT
40 };
41
42
43 //
44 // This is the part common to MetricsInfo and PainterInfo
45 //
46 class MetricsBase {
47 public:
48         ///
49         MetricsBase();
50         ///
51         MetricsBase(BufferView * bv, FontInfo const & font, int textwidth);
52
53         /// the current view
54         BufferView * bv;
55         /// current font
56         FontInfo font;
57         /// current math style (display/text/script/..)
58         Styles style;
59         /// name of current font - mathed specific
60         std::string fontname;
61         /// This is the width available in pixels
62         int textwidth;
63 };
64
65
66 //
67 // This contains a MetricsBase and information that's only relevant during
68 // the first phase of the two-phase draw
69 //
70 class MetricsInfo {
71 public:
72         ///
73         MetricsInfo();
74         ///
75         MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth);
76
77         ///
78         MetricsBase base;
79 };
80
81
82 //
83 // This contains a MetricsBase and information that's only relevant during
84 // the second phase of the two-phase draw
85 //
86 class PainterInfo {
87 public:
88         ///
89         PainterInfo(BufferView * bv, frontend::Painter & pain);
90         ///
91         void draw(int x, int y, char_type c);
92         ///
93         void draw(int x, int y, docstring const & str);
94
95         ///
96         MetricsBase base;
97         ///
98         frontend::Painter & pain;
99         /// Whether the text at this point is right-to-left (for InsetNewline)
100         bool ltr_pos;
101         /// Whether the parent is deleted (change tracking)
102         bool erased_;
103         ///
104         bool full_repaint;
105         ///
106         ColorCode background_color;
107 };
108
109 class TextMetricsInfo {};
110
111 enum ScreenUpdateStrategy {
112         NoScreenUpdate,
113         SingleParUpdate,
114         FullScreenUpdate,
115         DecorationUpdate
116 };
117
118 class ViewMetricsInfo
119 {
120 public:
121         ViewMetricsInfo()
122                         : p1(0), p2(0), y1(0), y2(0),
123                         update_strategy(FullScreenUpdate), size(0)
124                 {}
125         ViewMetricsInfo(pit_type p1, pit_type p2, int y1, int y2,
126                         ScreenUpdateStrategy updatestrategy, pit_type size)
127                         : p1(p1), p2(p2), y1(y1), y2(y2),
128                         update_strategy(updatestrategy), size(size)
129                 {}
130
131         pit_type p1;
132         pit_type p2;
133         int y1;
134         int y2;
135         ScreenUpdateStrategy update_strategy;
136         pit_type size;
137 };
138
139
140 // Generic base for temporarily changing things.
141 // The original state gets restored when the Changer is destructed.
142
143 template <class Struct, class Temp = Struct>
144 class Changer {
145 public:
146         ///
147         Changer(Struct & orig) : orig_(orig) {}
148 protected:
149         ///
150         Struct & orig_;
151         ///
152         Temp save_;
153 };
154
155
156
157 // temporarily change some aspect of a font
158 class FontChanger : public Changer<FontInfo> {
159 public:
160         ///
161         FontChanger(FontInfo & orig, docstring const & font);
162         FontChanger(MetricsBase & mb, char const * const font);
163         ///
164         ~FontChanger();
165 };
166
167
168 // temporarily change a full font
169 class FontSetChanger : public Changer<MetricsBase> {
170 public:
171         ///
172         FontSetChanger(MetricsBase & mb, docstring const & font);
173         FontSetChanger(MetricsBase & mb, char const * const font);
174         ///
175         ~FontSetChanger();
176 };
177
178
179 // temporarily change the style
180 class StyleChanger : public Changer<MetricsBase> {
181 public:
182         ///
183         StyleChanger(MetricsBase & mb, Styles style);
184         ///
185         ~StyleChanger();
186 };
187
188
189 // temporarily change the style to script style
190 class ScriptChanger : public StyleChanger {
191 public:
192         ///
193         ScriptChanger(MetricsBase & mb);
194 };
195
196
197 // temporarily change the style suitable for use in fractions
198 class FracChanger : public StyleChanger {
199 public:
200         ///
201         FracChanger(MetricsBase & mb);
202 };
203
204
205 // temporarily change the style suitable for use in tabulars and arrays
206 class ArrayChanger : public StyleChanger {
207 public:
208         ///
209         ArrayChanger(MetricsBase & mb);
210 };
211
212
213
214 // temporarily change the shape of a font
215 class ShapeChanger : public Changer<FontInfo, FontShape> {
216 public:
217         ///
218         ShapeChanger(FontInfo & font, FontShape shape);
219         ///
220         ~ShapeChanger();
221 };
222
223
224 // temporarily change the available text width
225 class WidthChanger : public Changer<MetricsBase>
226 {
227 public:
228         ///
229         WidthChanger(MetricsBase & mb, int width);
230         ///
231         ~WidthChanger();
232 };
233
234
235 // temporarily change the used color
236 class ColorChanger : public Changer<FontInfo, std::string> {
237 public:
238         ///
239         ColorChanger(FontInfo & font, std::string const & color);
240         ///
241         ~ColorChanger();
242 };
243
244 } // namespace lyx
245
246 #endif