Consider the case where there is not any layout name.
[lyx.git] / src / metricsinfo.h
blobc924bd94672d581095a27aa16290e30f3346aee3
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
9 * Full author contact details are available in file CREDITS.
12 #ifndef METRICSINFO_H
13 #define METRICSINFO_H
15 #include "lyxfont.h"
16 #include "support/types.h"
18 #include <string>
20 class Painter;
21 class BufferView;
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
38 // This is the part common to MetricsInfo and PainterInfo
40 class MetricsBase {
41 public:
42 ///
43 MetricsBase();
44 ///
45 MetricsBase(BufferView * bv, LyXFont const & font, int textwidth);
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;
61 // This contains a MetricsBase and information that's only relevant during
62 // the first phase of the two-phase draw
64 class MetricsInfo {
65 public:
66 ///
67 MetricsInfo();
68 ///
69 MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth);
71 ///
72 MetricsBase base;
77 // This contains a MetricsBase and information that's only relevant during
78 // the second phase of the two-phase draw
80 class PainterInfo {
81 public:
82 ///
83 PainterInfo(BufferView * bv, Painter & pain);
84 ///
85 void draw(int x, int y, char c);
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;
95 class TextMetricsInfo {};
97 class ViewMetricsInfo
99 public:
100 ViewMetricsInfo(lyx::pit_type p1, lyx::pit_type p2, int y1, int y2,
101 bool singlepar) : p1(p1), p2(p2), y1(y1), y2(y2),
102 singlepar(singlepar) {}
103 lyx::pit_type p1;
104 lyx::pit_type p2;
105 int y1;
106 int y2;
107 bool singlepar;
111 // Generic base for temporarily changing things.
112 // The original state gets restored when the Changer is destructed.
114 template <class Struct, class Temp = Struct>
115 class Changer {
116 public:
118 Changer(Struct & orig) : orig_(orig) {}
119 protected:
121 Struct & orig_;
123 Temp save_;
128 // temporarily change some aspect of a font
129 class FontChanger : public Changer<LyXFont> {
130 public:
132 FontChanger(LyXFont & orig, char const * font);
134 ~FontChanger();
138 // temporarily change a full font
139 class FontSetChanger : public Changer<MetricsBase> {
140 public:
142 FontSetChanger(MetricsBase & mb, char const * font);
144 ~FontSetChanger();
148 // temporarily change the style
149 class StyleChanger : public Changer<MetricsBase> {
150 public:
152 StyleChanger(MetricsBase & mb, Styles style);
154 ~StyleChanger();
158 // temporarily change the style to script style
159 class ScriptChanger : public StyleChanger {
160 public:
162 ScriptChanger(MetricsBase & mb);
166 // temporarily change the style suitable for use in fractions
167 class FracChanger : public StyleChanger {
168 public:
170 FracChanger(MetricsBase & mb);
174 // temporarily change the style suitable for use in tabulars and arrays
175 class ArrayChanger : public StyleChanger {
176 public:
178 ArrayChanger(MetricsBase & mb);
183 // temporarily change the shape of a font
184 class ShapeChanger : public Changer<LyXFont, LyXFont::FONT_SHAPE> {
185 public:
187 ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape);
189 ~ShapeChanger();
193 // temporarily change the available text width
194 class WidthChanger : public Changer<MetricsBase>
196 public:
198 WidthChanger(MetricsBase & mb, int width);
200 ~WidthChanger();
204 // temporarily change the used color
205 class ColorChanger : public Changer<LyXFont, std::string> {
206 public:
208 ColorChanger(LyXFont & font, std::string const & color);
210 ~ColorChanger();
213 #endif