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