4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Stefan Schimanski
10 * Full author contact details are available in file CREDITS.
17 #include "ColorCode.h"
20 #include "support/strfwd.h"
28 namespace frontend { class Painter; }
33 /// Standard Sizes (mode styles)
47 // This is the part common to MetricsInfo and PainterInfo
54 MetricsBase(BufferView * bv, FontInfo const & font, int textwidth);
60 /// current math style (display/text/script/..)
62 /// name of current font - mathed specific
64 /// This is the width available in pixels
70 // This contains a MetricsBase and information that's only relevant during
71 // the first phase of the two-phase draw
78 MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, MacroContext const & mc);
82 /// The context to resolve macros
83 MacroContext const & macrocontext;
88 // This contains a MetricsBase and information that's only relevant during
89 // the second phase of the two-phase draw
94 PainterInfo(BufferView * bv, frontend::Painter & pain);
96 void draw(int x, int y, char_type c);
98 void draw(int x, int y, docstring const & str);
99 /// Determines the background color for the specified inset based on the
100 /// selection state, the background color inherited from the parent inset
101 /// and the inset's own background color.
102 /// \param sel whether to take the selection state into account
103 ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
105 /// Determines the text color based on the intended color, the
106 /// change tracking state and the selection state.
107 /// \param color what the color should be by default
108 Color textColor(Color const & color) const;
113 frontend::Painter & pain;
114 /// Whether the text at this point is right-to-left (for InsetNewline)
116 /// The change the parent is part of (change tracking)
118 /// Whether the parent is selected as a whole
122 /// Current background color
123 ColorCode background_color;
126 class TextMetricsInfo {};
129 /// Generic base for temporarily changing things.
130 /// The original state gets restored when the Changer is destructed.
131 template <class Struct, class Temp = Struct>
135 Changer(Struct & orig) : orig_(orig) {}
145 // temporarily change some aspect of a font
146 class FontChanger : public Changer<FontInfo> {
149 FontChanger(FontInfo & orig, docstring const & font);
150 FontChanger(MetricsBase & mb, char const * const font);
156 // temporarily change a full font
157 class FontSetChanger : public Changer<MetricsBase> {
160 FontSetChanger(MetricsBase & mb, docstring const & font,
161 bool really_change_font = true);
162 FontSetChanger(MetricsBase & mb, char const * const font,
163 bool really_change_font = true);
172 // temporarily change the style
173 class StyleChanger : public Changer<MetricsBase> {
176 StyleChanger(MetricsBase & mb, Styles style);
182 // temporarily change the style to script style
183 class ScriptChanger : public StyleChanger {
186 ScriptChanger(MetricsBase & mb);
190 // temporarily change the style suitable for use in fractions
191 class FracChanger : public StyleChanger {
194 FracChanger(MetricsBase & mb);
198 // temporarily change the style suitable for use in tabulars and arrays
199 class ArrayChanger : public StyleChanger {
202 ArrayChanger(MetricsBase & mb);
207 // temporarily change the shape of a font
208 class ShapeChanger : public Changer<FontInfo, FontShape> {
211 ShapeChanger(FontInfo & font, FontShape shape);
217 // temporarily change the available text width
218 class WidthChanger : public Changer<MetricsBase>
222 WidthChanger(MetricsBase & mb, int width);
228 // temporarily change the used color
229 class ColorChanger : public Changer<FontInfo, ColorCode> {
232 ColorChanger(FontInfo & font, ColorCode color,
233 bool really_change_color = true);