]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.h
- Link against qt-mt333.lib which is what the current qt3 cvs produces
[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         ///
88         MetricsBase base;
89         ///
90         Painter & pain;
91         /// Whether the text at this point is right-to-left (for InsetNewline)
92         bool ltr_pos;
93 };
94
95 class TextMetricsInfo {};
96
97 class ViewMetricsInfo
98 {
99 public:
100         ViewMetricsInfo(lyx::pit_type p1, lyx::pit_type p2,
101                         int y1, int y2) : p1(p1), p2(p2), y1(y1), y2(y2) {}
102         lyx::pit_type p1;
103         lyx::pit_type p2;
104         int y1;
105         int y2;
106 };
107
108
109 // Generic base for temporarily changing things.
110 // The original state gets restored when the Changer is destructed.
111
112 template <class Struct, class Temp = Struct>
113 class Changer {
114 public:
115         ///
116         Changer(Struct & orig) : orig_(orig) {}
117 protected:
118         ///
119         Struct & orig_;
120         ///
121         Temp save_;
122 };
123
124
125
126 // temporarily change some aspect of a font
127 class FontChanger : public Changer<LyXFont> {
128 public:
129         ///
130         FontChanger(LyXFont & orig, char const * font);
131         ///
132         ~FontChanger();
133 };
134
135
136 // temporarily change a full font
137 class FontSetChanger : public Changer<MetricsBase> {
138 public:
139         ///
140         FontSetChanger(MetricsBase & mb, char const * font);
141         ///
142         ~FontSetChanger();
143 };
144
145
146 // temporarily change the style
147 class StyleChanger : public Changer<MetricsBase> {
148 public:
149         ///
150         StyleChanger(MetricsBase & mb, Styles style);
151         ///
152         ~StyleChanger();
153 };
154
155
156 // temporarily change the style to script style
157 class ScriptChanger : public StyleChanger {
158 public:
159         ///
160         ScriptChanger(MetricsBase & mb);
161 };
162
163
164 // temporarily change the style suitable for use in fractions
165 class FracChanger : public StyleChanger {
166 public:
167         ///
168         FracChanger(MetricsBase & mb);
169 };
170
171
172 // temporarily change the style suitable for use in tabulars and arrays
173 class ArrayChanger : public StyleChanger {
174 public:
175         ///
176         ArrayChanger(MetricsBase & mb);
177 };
178
179
180
181 // temporarily change the shape of a font
182 class ShapeChanger : public Changer<LyXFont, LyXFont::FONT_SHAPE> {
183 public:
184         ///
185         ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape);
186         ///
187         ~ShapeChanger();
188 };
189
190
191 // temporarily change the available text width
192 class WidthChanger : public Changer<MetricsBase>
193 {
194 public:
195         ///
196         WidthChanger(MetricsBase & mb, int width);
197         ///
198         ~WidthChanger();
199 };
200
201
202 // temporarily change the used color
203 class ColorChanger : public Changer<LyXFont, std::string> {
204 public:
205         ///
206         ColorChanger(LyXFont & font, std::string const & color);
207         ///
208         ~ColorChanger();
209 };
210
211 #endif