]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
Transfer current_font and real_current_font from Text to Cursor.
[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         bool full_repaint;
101 };
102
103 class TextMetricsInfo {};
104
105 enum ScreenUpdateStrategy {
106         NoScreenUpdate,
107         SingleParUpdate,
108         FullScreenUpdate,
109         DecorationUpdate
110 };
111
112 class ViewMetricsInfo
113 {
114 public:
115         ViewMetricsInfo()
116                         : p1(0), p2(0), y1(0), y2(0),
117                         update_strategy(FullScreenUpdate), size(0)
118                 {}
119         ViewMetricsInfo(pit_type p1, pit_type p2, int y1, int y2,
120                         ScreenUpdateStrategy updatestrategy, pit_type size)
121                         : p1(p1), p2(p2), y1(y1), y2(y2),
122                         update_strategy(updatestrategy), size(size)
123                 {}
124
125         pit_type p1;
126         pit_type p2;
127         int y1;
128         int y2;
129         ScreenUpdateStrategy update_strategy;
130         pit_type size;
131 };
132
133
134 // Generic base for temporarily changing things.
135 // The original state gets restored when the Changer is destructed.
136
137 template <class Struct, class Temp = Struct>
138 class Changer {
139 public:
140         ///
141         Changer(Struct & orig) : orig_(orig) {}
142 protected:
143         ///
144         Struct & orig_;
145         ///
146         Temp save_;
147 };
148
149
150
151 // temporarily change some aspect of a font
152 class FontChanger : public Changer<Font> {
153 public:
154         ///
155         FontChanger(Font & orig, docstring const & font);
156         FontChanger(MetricsBase & mb, char const * const font);
157         ///
158         ~FontChanger();
159 };
160
161
162 // temporarily change a full font
163 class FontSetChanger : public Changer<MetricsBase> {
164 public:
165         ///
166         FontSetChanger(MetricsBase & mb, docstring const & font);
167         FontSetChanger(MetricsBase & mb, char const * const font);
168         ///
169         ~FontSetChanger();
170 };
171
172
173 // temporarily change the style
174 class StyleChanger : public Changer<MetricsBase> {
175 public:
176         ///
177         StyleChanger(MetricsBase & mb, Styles style);
178         ///
179         ~StyleChanger();
180 };
181
182
183 // temporarily change the style to script style
184 class ScriptChanger : public StyleChanger {
185 public:
186         ///
187         ScriptChanger(MetricsBase & mb);
188 };
189
190
191 // temporarily change the style suitable for use in fractions
192 class FracChanger : public StyleChanger {
193 public:
194         ///
195         FracChanger(MetricsBase & mb);
196 };
197
198
199 // temporarily change the style suitable for use in tabulars and arrays
200 class ArrayChanger : public StyleChanger {
201 public:
202         ///
203         ArrayChanger(MetricsBase & mb);
204 };
205
206
207
208 // temporarily change the shape of a font
209 class ShapeChanger : public Changer<Font, Font::FONT_SHAPE> {
210 public:
211         ///
212         ShapeChanger(Font & font, Font::FONT_SHAPE shape);
213         ///
214         ~ShapeChanger();
215 };
216
217
218 // temporarily change the available text width
219 class WidthChanger : public Changer<MetricsBase>
220 {
221 public:
222         ///
223         WidthChanger(MetricsBase & mb, int width);
224         ///
225         ~WidthChanger();
226 };
227
228
229 // temporarily change the used color
230 class ColorChanger : public Changer<Font, std::string> {
231 public:
232         ///
233         ColorChanger(Font & font, std::string const & color);
234         ///
235         ~ColorChanger();
236 };
237
238 } // namespace lyx
239
240 #endif