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