]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.h
Merge the unicode branch into trunk.
[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 BufferView;
21
22 namespace lyx {
23 namespace frontend {
24 class Painter;
25 }
26 }
27
28
29 /// Standard Sizes (mode styles)
30 enum Styles {
31         ///
32         LM_ST_DISPLAY = 0,
33         ///
34         LM_ST_TEXT,
35         ///
36         LM_ST_SCRIPT,
37         ///
38         LM_ST_SCRIPTSCRIPT
39 };
40
41
42 //
43 // This is the part common to MetricsInfo and PainterInfo
44 //
45 class MetricsBase {
46 public:
47         ///
48         MetricsBase();
49         ///
50         MetricsBase(BufferView * bv, LyXFont const & font, int textwidth);
51
52         /// the current view
53         BufferView * bv;
54         /// current font
55         LyXFont font;
56         /// current math style (display/text/script/..)
57         Styles style;
58         /// name of current font - mathed specific
59         std::string fontname;
60         /// This is the width available in pixels
61         int textwidth;
62 };
63
64
65 //
66 // This contains a MetricsBase and information that's only relevant during
67 // the first phase of the two-phase draw
68 //
69 class MetricsInfo {
70 public:
71         ///
72         MetricsInfo();
73         ///
74         MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth);
75
76         ///
77         MetricsBase base;
78 };
79
80
81 //
82 // This contains a MetricsBase and information that's only relevant during
83 // the second phase of the two-phase draw
84 //
85 class PainterInfo {
86 public:
87         ///
88         PainterInfo(BufferView * bv, lyx::frontend::Painter & pain);
89         ///
90         void draw(int x, int y, lyx::char_type c);
91         ///
92         void draw(int x, int y, lyx::docstring const & str);
93
94         ///
95         MetricsBase base;
96         ///
97         lyx::frontend::Painter & pain;
98         /// Whether the text at this point is right-to-left (for InsetNewline)
99         bool ltr_pos;
100         /// Whether the parent is deleted (change tracking)
101         bool erased_;
102 };
103
104 class TextMetricsInfo {};
105
106 class ViewMetricsInfo
107 {
108 public:
109         ViewMetricsInfo()
110                 : p1(0), p2(0), y1(0), y2(0),
111                   singlepar(false), size(0) {}
112         ViewMetricsInfo(lyx::pit_type p1, lyx::pit_type p2, int y1, int y2,
113                         bool singlepar, lyx::pit_type size)
114                 : p1(p1), p2(p2), y1(y1), y2(y2),
115                   singlepar(singlepar), size(size) {}
116         lyx::pit_type p1;
117         lyx::pit_type p2;
118         int y1;
119         int y2;
120         bool singlepar;
121         lyx::pit_type size;
122 };
123
124
125 // Generic base for temporarily changing things.
126 // The original state gets restored when the Changer is destructed.
127
128 template <class Struct, class Temp = Struct>
129 class Changer {
130 public:
131         ///
132         Changer(Struct & orig) : orig_(orig) {}
133 protected:
134         ///
135         Struct & orig_;
136         ///
137         Temp save_;
138 };
139
140
141
142 // temporarily change some aspect of a font
143 class FontChanger : public Changer<LyXFont> {
144 public:
145         ///
146         FontChanger(LyXFont & orig, char const * font);
147         ///
148         ~FontChanger();
149 };
150
151
152 // temporarily change a full font
153 class FontSetChanger : public Changer<MetricsBase> {
154 public:
155         ///
156         FontSetChanger(MetricsBase & mb, char 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 #endif