Update NEWS preparing for alpha1
[lyx.git] / src / MetricsInfo.h
blobe091dc78308ff55760e03d2867223997332dbe59
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.
7 * \author André Pönitz
8 * \author Stefan Schimanski
10 * Full author contact details are available in file CREDITS.
13 #ifndef METRICSINFO_H
14 #define METRICSINFO_H
16 #include "ColorCode.h"
17 #include "FontInfo.h"
19 #include "support/strfwd.h"
20 #include "support/types.h"
22 #include <string>
24 class BufferView;
26 namespace lyx {
28 namespace frontend { class Painter; }
29 class MacroContext;
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
46 // This is the part common to MetricsInfo and PainterInfo
48 class MetricsBase {
49 public:
50 ///
51 MetricsBase();
52 ///
53 MetricsBase(BufferView * bv, FontInfo const & font, int textwidth);
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;
69 // This contains a MetricsBase and information that's only relevant during
70 // the first phase of the two-phase draw
72 class MetricsInfo {
73 public:
74 ///
75 MetricsInfo();
76 ///
77 MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, MacroContext const & mc);
79 ///
80 MetricsBase base;
81 /// The context to resolve macros
82 MacroContext const & macrocontext;
87 // This contains a MetricsBase and information that's only relevant during
88 // the second phase of the two-phase draw
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);
99 ///
100 MetricsBase base;
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_;
108 bool full_repaint;
110 ColorCode background_color;
113 class TextMetricsInfo {};
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:
122 Changer(Struct & orig) : orig_(orig) {}
123 protected:
125 Struct & orig_;
127 Temp save_;
132 // temporarily change some aspect of a font
133 class FontChanger : public Changer<FontInfo> {
134 public:
136 FontChanger(FontInfo & orig, docstring const & font);
137 FontChanger(MetricsBase & mb, char const * const font);
139 ~FontChanger();
143 // temporarily change a full font
144 class FontSetChanger : public Changer<MetricsBase> {
145 public:
147 FontSetChanger(MetricsBase & mb, docstring const & font);
148 FontSetChanger(MetricsBase & mb, char const * const font);
150 ~FontSetChanger();
154 // temporarily change the style
155 class StyleChanger : public Changer<MetricsBase> {
156 public:
158 StyleChanger(MetricsBase & mb, Styles style);
160 ~StyleChanger();
164 // temporarily change the style to script style
165 class ScriptChanger : public StyleChanger {
166 public:
168 ScriptChanger(MetricsBase & mb);
172 // temporarily change the style suitable for use in fractions
173 class FracChanger : public StyleChanger {
174 public:
176 FracChanger(MetricsBase & mb);
180 // temporarily change the style suitable for use in tabulars and arrays
181 class ArrayChanger : public StyleChanger {
182 public:
184 ArrayChanger(MetricsBase & mb);
189 // temporarily change the shape of a font
190 class ShapeChanger : public Changer<FontInfo, FontShape> {
191 public:
193 ShapeChanger(FontInfo & font, FontShape shape);
195 ~ShapeChanger();
199 // temporarily change the available text width
200 class WidthChanger : public Changer<MetricsBase>
202 public:
204 WidthChanger(MetricsBase & mb, int width);
206 ~WidthChanger();
210 // temporarily change the used color
211 class ColorChanger : public Changer<FontInfo, std::string> {
212 public:
214 ColorChanger(FontInfo & font, std::string const & color);
216 ~ColorChanger();
219 } // namespace lyx
221 #endif