]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.C
rename Inset to InsetOld
[lyx.git] / src / metricsinfo.C
1
2 #include <config.h>
3
4 #include "metricsinfo.h"
5 #include "mathed/math_support.h"
6 #include "frontends/Painter.h"
7 #include "debug.h"
8 #include "BufferView.h"
9
10
11
12 MetricsBase::MetricsBase()
13         : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
14           textwidth(0)
15 {}
16
17
18
19 MetricsBase::MetricsBase(BufferView * b, LyXFont const & f, int w)
20         : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
21           textwidth(w)
22 {}
23
24
25
26 MetricsInfo::MetricsInfo()
27 {}
28
29
30 MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth)
31         : base(bv, font, textwidth)
32 {}
33
34
35
36 PainterInfo::PainterInfo(BufferView * bv)
37         : pain(bv->painter())
38 {
39         base.bv = bv;
40 }
41
42
43 void PainterInfo::draw(int x, int y, char c)
44 {
45         pain.text(x, y, c, base.font);
46 }
47
48
49 Styles smallerScriptStyle(Styles st)
50 {
51         switch (st) {
52                 case LM_ST_DISPLAY:
53                 case LM_ST_TEXT:
54                         return LM_ST_SCRIPT;
55                 case LM_ST_SCRIPT:
56                 case LM_ST_SCRIPTSCRIPT:
57                 default: // shut up compiler
58                         return LM_ST_SCRIPTSCRIPT;
59         }
60 }
61
62 ScriptChanger::ScriptChanger(MetricsBase & mb)
63         : StyleChanger(mb, smallerScriptStyle(mb.style))
64 {}
65
66
67
68 Styles smallerFracStyle(Styles st)
69 {
70         switch (st) {
71                 case LM_ST_DISPLAY:
72                         return LM_ST_TEXT;
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
83 FracChanger::FracChanger(MetricsBase & mb)
84         : StyleChanger(mb, smallerFracStyle(mb.style))
85 {}
86
87
88
89 ArrayChanger::ArrayChanger(MetricsBase & mb)
90         : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
91 {}
92
93
94 ShapeChanger::ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
95         : Changer<LyXFont, LyXFont::FONT_SHAPE>(font)
96 {
97         save_ = orig_.shape();
98         orig_.setShape(shape);
99 }
100
101 ShapeChanger::~ShapeChanger()
102 {
103         orig_.setShape(save_);
104 }
105
106
107
108 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
109         :       Changer<MetricsBase>(mb)
110 {
111         static const int diff[4][4]  = { { 0, 0, -3, -5 },
112                                          { 0, 0, -3, -5 },
113                                          { 3, 3,  0, -2 },
114                                          { 5, 5,  2,  0 } };
115         save_ = mb;
116         int t = diff[mb.style][style];
117         if (t > 0)
118                 while (t--)
119                         mb.font.incSize();
120         else
121                 while (t++)
122                         mb.font.decSize();
123         mb.style = style;
124 }
125
126
127 StyleChanger::~StyleChanger()
128 {
129         orig_ = save_;
130 }
131
132
133
134 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
135         :       Changer<MetricsBase>(mb)
136 {
137         save_ = mb;
138         mb.fontname = name;
139         augmentFont(mb.font, name);
140 }
141
142 FontSetChanger::~FontSetChanger()
143 {
144         orig_ = save_;
145 }
146
147
148 WidthChanger::WidthChanger(MetricsBase & mb, int w)
149         :       Changer<MetricsBase>(mb)
150 {
151         save_ = mb;
152         mb.textwidth     = w;
153 }
154
155
156 WidthChanger::~WidthChanger()
157 {
158         orig_ = save_;
159 }