]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.h
Support lgathered and rgathered math environments
[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
18 class BufferView;
19
20 namespace lyx {
21 namespace frontend {
22 class Painter;
23 }
24 }
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, LyXFont const & font, int textwidth);
49
50         /// the current view
51         BufferView * bv;
52         /// current font
53         LyXFont 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, LyXFont 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, lyx::frontend::Painter & pain);
87         ///
88         void draw(int x, int y, lyx::char_type c);
89         ///
90         void draw(int x, int y, lyx::docstring const & str);
91
92         ///
93         MetricsBase base;
94         ///
95         lyx::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
102 class TextMetricsInfo {};
103
104 class ViewMetricsInfo
105 {
106 public:
107         ViewMetricsInfo()
108                 : p1(0), p2(0), y1(0), y2(0),
109                   singlepar(false), size(0) {}
110         ViewMetricsInfo(lyx::pit_type p1, lyx::pit_type p2, int y1, int y2,
111                         bool singlepar, lyx::pit_type size)
112                 : p1(p1), p2(p2), y1(y1), y2(y2),
113                   singlepar(singlepar), size(size) {}
114         lyx::pit_type p1;
115         lyx::pit_type p2;
116         int y1;
117         int y2;
118         bool singlepar;
119         lyx::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, char const * font);
145         ///
146         ~FontChanger();
147 };
148
149
150 // temporarily change a full font
151 class FontSetChanger : public Changer<MetricsBase> {
152 public:
153         ///
154         FontSetChanger(MetricsBase & mb, char const * font);
155         ///
156         ~FontSetChanger();
157 };
158
159
160 // temporarily change the style
161 class StyleChanger : public Changer<MetricsBase> {
162 public:
163         ///
164         StyleChanger(MetricsBase & mb, Styles style);
165         ///
166         ~StyleChanger();
167 };
168
169
170 // temporarily change the style to script style
171 class ScriptChanger : public StyleChanger {
172 public:
173         ///
174         ScriptChanger(MetricsBase & mb);
175 };
176
177
178 // temporarily change the style suitable for use in fractions
179 class FracChanger : public StyleChanger {
180 public:
181         ///
182         FracChanger(MetricsBase & mb);
183 };
184
185
186 // temporarily change the style suitable for use in tabulars and arrays
187 class ArrayChanger : public StyleChanger {
188 public:
189         ///
190         ArrayChanger(MetricsBase & mb);
191 };
192
193
194
195 // temporarily change the shape of a font
196 class ShapeChanger : public Changer<LyXFont, LyXFont::FONT_SHAPE> {
197 public:
198         ///
199         ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape);
200         ///
201         ~ShapeChanger();
202 };
203
204
205 // temporarily change the available text width
206 class WidthChanger : public Changer<MetricsBase>
207 {
208 public:
209         ///
210         WidthChanger(MetricsBase & mb, int width);
211         ///
212         ~WidthChanger();
213 };
214
215
216 // temporarily change the used color
217 class ColorChanger : public Changer<LyXFont, std::string> {
218 public:
219         ///
220         ColorChanger(LyXFont & font, std::string const & color);
221         ///
222         ~ColorChanger();
223 };
224
225 #endif