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