]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
Remove a conversion to_utf8() inside FontSetChanger
[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  * \author Stefan Schimanski
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef METRICSINFO_H
14 #define METRICSINFO_H
15
16 #include "Changes.h"
17 #include "ColorCode.h"
18 #include "FontInfo.h"
19
20 #include "support/strfwd.h"
21 #include "support/Changer.h"
22
23
24 #include <string>
25
26
27 namespace lyx {
28
29 namespace frontend { class Painter; }
30 class BufferView;
31 class Inset;
32 class MacroContext;
33
34
35 /// Standard Sizes (mode styles)
36 /// note: These values are hard-coded in changeStyle
37 enum Styles {
38         ///
39         LM_ST_DISPLAY = 0,
40         ///
41         LM_ST_TEXT,
42         ///
43         LM_ST_SCRIPT,
44         ///
45         LM_ST_SCRIPTSCRIPT
46 };
47
48
49 //
50 // This is the part common to MetricsInfo and PainterInfo
51 //
52 class MetricsBase {
53 public:
54         ///
55         MetricsBase();
56         ///
57         MetricsBase(BufferView * bv, FontInfo font, int textwidth);
58
59         /// the current view
60         BufferView * bv;
61         /// current font
62         FontInfo font;
63         /// current math style (display/text/script/..)
64         Styles style;
65         /// name of current font - mathed specific
66         std::string fontname;
67         /// This is the width available in pixels
68         int textwidth;
69
70         /// Temporarily change a full font.
71         Changer changeFontSet(std::string const & font, bool cond = true);
72         /// Temporarily change the font size and the math style.
73         Changer changeStyle(Styles style, bool cond = true);
74         // Temporarily change to the style suitable for use in fractions
75         Changer changeFrac(bool cond = true);
76         // Temporarily change the style to (script)script style
77         Changer changeScript(bool cond = true);
78         ///
79         int solidLineThickness() const { return solid_line_thickness_; }
80         ///
81         int solidLineOffset() const { return solid_line_offset_; }
82         ///
83         int dottedLineThickness() const { return dotted_line_thickness_; }
84 private:
85         int solid_line_thickness_;
86         int solid_line_offset_;
87         int dotted_line_thickness_;
88 };
89
90
91 //
92 // This contains a MetricsBase and information that's only relevant during
93 // the first phase of the two-phase draw
94 //
95 class MetricsInfo {
96 public:
97         ///
98         MetricsInfo();
99         ///
100         MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
101                     MacroContext const & mc);
102
103         ///
104         MetricsBase base;
105         /// The context to resolve macros
106         MacroContext const & macrocontext;
107 };
108
109
110 //
111 // This contains a MetricsBase and information that's only relevant during
112 // the second phase of the two-phase draw
113 //
114 class PainterInfo {
115 public:
116         ///
117         PainterInfo(BufferView * bv, frontend::Painter & pain);
118         ///
119         void draw(int x, int y, char_type c);
120         ///
121         void draw(int x, int y, docstring const & str);
122         /// Determines the background color for the specified inset based on the
123         /// selection state, the background color inherited from the parent inset 
124         /// and the inset's own background color.
125         /// \param sel whether to take the selection state into account
126         ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
127
128         /// Determines the text color based on the intended color, the
129         /// change tracking state and the selection state. 
130         /// \param color what the color should be by default
131         Color textColor(Color const & color) const;
132
133         ///
134         MetricsBase base;
135         ///
136         frontend::Painter & pain;
137         /// Whether the text at this point is right-to-left (for InsetNewline)
138         bool ltr_pos;
139         /// The change the parent is part of (change tracking)
140         Change change_;
141         /// Whether the parent is selected as a whole
142         bool selected;
143         /// Whether the spell checker is enabled for the parent
144         bool do_spellcheck;
145         ///
146         bool full_repaint;
147         /// Current background color
148         ColorCode background_color;
149 };
150
151 class TextMetricsInfo {};
152
153 } // namespace lyx
154
155 #endif