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