]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.cpp
Fixed some lines that were too long. It compiled afterwards.
[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 <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, Font 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, Font 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)
54 {
55         base.bv = bv;
56 }
57
58
59 void PainterInfo::draw(int x, int y, char_type c)
60 {
61         pain.text(x, y, c, base.font);
62 }
63
64
65 void PainterInfo::draw(int x, int y, docstring const & str)
66 {
67         pain.text(x, y, str, base.font);
68 }
69
70
71 Styles smallerScriptStyle(Styles st)
72 {
73         switch (st) {
74                 case LM_ST_DISPLAY:
75                 case LM_ST_TEXT:
76                         return LM_ST_SCRIPT;
77                 case LM_ST_SCRIPT:
78                 case LM_ST_SCRIPTSCRIPT:
79                 default: // shut up compiler
80                         return LM_ST_SCRIPTSCRIPT;
81         }
82 }
83
84 ScriptChanger::ScriptChanger(MetricsBase & mb)
85         : StyleChanger(mb, smallerScriptStyle(mb.style))
86 {}
87
88
89
90 Styles smallerFracStyle(Styles st)
91 {
92         switch (st) {
93                 case LM_ST_DISPLAY:
94                         return LM_ST_TEXT;
95                 case LM_ST_TEXT:
96                         return LM_ST_SCRIPT;
97                 case LM_ST_SCRIPT:
98                 case LM_ST_SCRIPTSCRIPT:
99                 default: // shut up compiler
100                         return LM_ST_SCRIPTSCRIPT;
101         }
102 }
103
104
105 FracChanger::FracChanger(MetricsBase & mb)
106         : StyleChanger(mb, smallerFracStyle(mb.style))
107 {}
108
109
110
111 ArrayChanger::ArrayChanger(MetricsBase & mb)
112         : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
113 {}
114
115
116
117 ShapeChanger::ShapeChanger(Font & font, Font::FONT_SHAPE shape)
118         : Changer<Font, Font::FONT_SHAPE>(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         Font::FONT_SIZE oldsize = save_.font.size();
164         mb.fontname = name;
165         mb.font = 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         Font::FONT_SIZE oldsize = save_.font.size();
176         mb.fontname = to_utf8(name);
177         mb.font = 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(Font & font, string const & color)
206         : Changer<Font, 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