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