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