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