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