]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.cpp
some de-boostification
[lyx.git] / src / MetricsInfo.cpp
1 /**
2  * \file MetricsInfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "BufferView.h"
14 #include "Color.h"
15 #include "MetricsInfo.h"
16
17 #include "mathed/MathSupport.h"
18
19 #include "frontends/Painter.h"
20
21 #include "support/docstring.h"
22
23 #include <boost/assert.hpp>
24
25
26 namespace lyx {
27
28 using std::string;
29
30
31 MetricsBase::MetricsBase()
32         : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
33           textwidth(0)
34 {}
35
36
37 MetricsBase::MetricsBase(BufferView * b, FontInfo const & f, int w)
38         : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
39           textwidth(w)
40 {}
41
42
43 MetricsInfo::MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, 
44         MacroContext const & mc)
45         : base(bv, font, textwidth), macrocontext(mc)
46 {}
47
48
49 PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
50         : pain(painter), ltr_pos(false), erased_(false), full_repaint(true),
51         background_color(Color_background)
52 {
53         base.bv = bv;
54 }
55
56
57 void PainterInfo::draw(int x, int y, char_type c)
58 {
59         pain.text(x, y, c, base.font);
60 }
61
62
63 void PainterInfo::draw(int x, int y, docstring const & str)
64 {
65         pain.text(x, y, str, base.font);
66 }
67
68
69 Styles smallerScriptStyle(Styles st)
70 {
71         switch (st) {
72                 case LM_ST_DISPLAY:
73                 case LM_ST_TEXT:
74                         return LM_ST_SCRIPT;
75                 case LM_ST_SCRIPT:
76                 case LM_ST_SCRIPTSCRIPT:
77                 default: // shut up compiler
78                         return LM_ST_SCRIPTSCRIPT;
79         }
80 }
81
82 ScriptChanger::ScriptChanger(MetricsBase & mb)
83         : StyleChanger(mb, smallerScriptStyle(mb.style))
84 {}
85
86
87
88 Styles smallerFracStyle(Styles st)
89 {
90         switch (st) {
91                 case LM_ST_DISPLAY:
92                         return LM_ST_TEXT;
93                 case LM_ST_TEXT:
94                         return LM_ST_SCRIPT;
95                 case LM_ST_SCRIPT:
96                 case LM_ST_SCRIPTSCRIPT:
97                 default: // shut up compiler
98                         return LM_ST_SCRIPTSCRIPT;
99         }
100 }
101
102
103 FracChanger::FracChanger(MetricsBase & mb)
104         : StyleChanger(mb, smallerFracStyle(mb.style))
105 {}
106
107
108
109 ArrayChanger::ArrayChanger(MetricsBase & mb)
110         : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
111 {}
112
113
114 ShapeChanger::ShapeChanger(FontInfo & font, FontShape shape)
115         : Changer<FontInfo, FontShape>(font)
116 {
117         save_ = orig_.shape();
118         orig_.setShape(shape);
119 }
120
121
122 ShapeChanger::~ShapeChanger()
123 {
124         orig_.setShape(save_);
125 }
126
127
128
129 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
130         :       Changer<MetricsBase>(mb)
131 {
132         static const int diff[4][4] =
133                 { { 0, 0, -3, -5 },
134                   { 0, 0, -3, -5 },
135                   { 3, 3,  0, -2 },
136                   { 5, 5,  2,  0 } };
137         save_ = mb;
138         int t = diff[mb.style][style];
139         if (t > 0)
140                 while (t--)
141                         mb.font.incSize();
142         else
143                 while (t++)
144                         mb.font.decSize();
145         mb.style = style;
146 }
147
148
149 StyleChanger::~StyleChanger()
150 {
151         orig_ = save_;
152 }
153
154
155
156 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
157         :       Changer<MetricsBase>(mb)
158 {
159         save_ = mb;
160         FontSize oldsize = save_.font.size();
161         mb.fontname = name;
162         mb.font = sane_font;
163         augmentFont(mb.font, from_ascii(name));
164         mb.font.setSize(oldsize);
165 }
166
167
168 FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name)
169         :       Changer<MetricsBase>(mb)
170 {
171         save_ = mb;
172         FontSize oldsize = save_.font.size();
173         mb.fontname = to_utf8(name);
174         mb.font = sane_font;
175         augmentFont(mb.font, name);
176         mb.font.setSize(oldsize);
177 }
178
179
180 FontSetChanger::~FontSetChanger()
181 {
182         orig_ = save_;
183 }
184
185
186 WidthChanger::WidthChanger(MetricsBase & mb, int w)
187         :       Changer<MetricsBase>(mb)
188 {
189         save_ = mb;
190         mb.textwidth = w;
191 }
192
193
194 WidthChanger::~WidthChanger()
195 {
196         orig_ = save_;
197 }
198
199
200
201
202 ColorChanger::ColorChanger(FontInfo & font, string const & color)
203         : Changer<FontInfo, string>(font)
204 {
205         save_ = lcolor.getFromLyXName(color);
206         font.setColor(lcolor.getFromLyXName(color));
207 }
208
209
210 ColorChanger::~ColorChanger()
211 {
212         orig_.setColor(lcolor.getFromLyXName(save_));
213 }
214
215
216 } // namespace lyx