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