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
120 /// Whether the spell checker is enabled for the parent
124 /// Current background color
125 ColorCode background_color;
128 class TextMetricsInfo {};
131 /// Generic base for temporarily changing things. The derived class is
132 /// responsible for restoring the original state when the Changer is
134 template <class Struct, class Temp = Struct>
138 Changer(Struct & orig, Temp const & save) : orig_(orig), save_(save) {}
140 Changer(Struct & orig) : orig_(orig), save_(orig) {}
149 // temporarily change some aspect of a font
150 class FontChanger : public Changer<FontInfo> {
153 FontChanger(FontInfo & orig, docstring const & font);
154 FontChanger(MetricsBase & mb, char const * const font);
160 // temporarily change a full font
161 class FontSetChanger : public Changer<MetricsBase> {
164 FontSetChanger(MetricsBase & mb, docstring const & font,
165 bool really_change_font = true);
166 FontSetChanger(MetricsBase & mb, char const * const font,
167 bool really_change_font = true);
176 // temporarily change the style
177 class StyleChanger : public Changer<MetricsBase> {
180 StyleChanger(MetricsBase & mb, Styles style);
186 // temporarily change the style to script style
187 class ScriptChanger : public StyleChanger {
190 ScriptChanger(MetricsBase & mb);
194 // temporarily change the style suitable for use in fractions
195 class FracChanger : public StyleChanger {
198 FracChanger(MetricsBase & mb);
202 // temporarily change the style suitable for use in tabulars and arrays
203 class ArrayChanger : public StyleChanger {
206 ArrayChanger(MetricsBase & mb);
211 // temporarily change the shape of a font
212 class ShapeChanger : public Changer<FontInfo, FontShape> {
215 ShapeChanger(FontInfo & font, FontShape shape);
221 // temporarily change the available text width
222 class WidthChanger : public Changer<MetricsBase>
226 WidthChanger(MetricsBase & mb, int width);
232 // temporarily change the used color
233 class ColorChanger : public Changer<FontInfo, ColorCode> {
236 ColorChanger(FontInfo & font, ColorCode color,
237 bool really_change_color = true);