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