]> git.lyx.org Git - lyx.git/blob - src/mathed/math_metricsinfo.C
small up/down tweaking
[lyx.git] / src / mathed / math_metricsinfo.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include <config.h>
6
7 #include "math_metricsinfo.h"
8 #include "math_support.h"
9 #include "debug.h"
10 #include "frontends/Painter.h"
11
12
13
14 MathMetricsBase::MathMetricsBase()
15         : font(), style(LM_ST_TEXT), fontname("mathnormal"),
16           restrictwidth(false), textwidth(0)
17 {}
18
19
20
21
22 MathMetricsInfo::MathMetricsInfo()
23         : fullredraw(false)
24 {}
25
26
27
28
29 MathPainterInfo::MathPainterInfo(Painter & p)
30         : pain(p)
31 {}
32
33
34 void MathPainterInfo::draw(int x, int y, char c)
35 {
36         pain.text(x, y, c, base.font);
37 }
38
39
40 MathStyles smallerScriptStyle(MathStyles st)
41 {
42         switch (st) {
43                 case LM_ST_DISPLAY:
44                 case LM_ST_TEXT:
45                         return LM_ST_SCRIPT;
46                 case LM_ST_SCRIPT:
47                 case LM_ST_SCRIPTSCRIPT:
48                         return LM_ST_SCRIPTSCRIPT;
49         }
50         // shut up compiler
51         lyxerr << "should not happen\n";
52         return LM_ST_DISPLAY;
53 }
54
55 MathScriptChanger::MathScriptChanger(MathMetricsBase & mb)
56         : MathStyleChanger(mb, smallerScriptStyle(mb.style))
57 {}
58
59
60
61 MathStyles smallerFracStyle(MathStyles st)
62 {
63         switch (st) {
64                 case LM_ST_DISPLAY:
65                         return LM_ST_TEXT;
66                 case LM_ST_TEXT:
67                         return LM_ST_SCRIPT;
68                 case LM_ST_SCRIPT:
69                 case LM_ST_SCRIPTSCRIPT:
70                         return LM_ST_SCRIPTSCRIPT;
71         }
72         // shut up compiler
73         lyxerr << "should not happen\n";
74         return LM_ST_DISPLAY;
75 }
76
77 MathFracChanger::MathFracChanger(MathMetricsBase & mb)
78         : MathStyleChanger(mb, smallerFracStyle(mb.style))
79 {}
80
81
82
83 MathArrayChanger::MathArrayChanger(MathMetricsBase & mb)
84         : MathStyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
85 {}
86
87
88 MathShapeChanger::MathShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
89         : MathChanger<LyXFont, LyXFont::FONT_SHAPE>(font)
90 {
91         save_ = orig_.shape();
92         orig_.setShape(shape);
93 }
94
95 MathShapeChanger::~MathShapeChanger()
96 {
97         orig_.setShape(save_);
98 }
99
100
101
102 MathStyleChanger::MathStyleChanger(MathMetricsBase & mb, MathStyles style)
103         :       MathChanger<MathMetricsBase>(mb)
104 {
105         static const int diff[4][4]  = { { 0, 0, -3, -5 },
106                                          { 0, 0, -3, -5 },
107                                          { 3, 3,  0, -2 },
108                                          { 5, 5,  2,  0 } };
109         save_ = mb;
110         int t = diff[mb.style][style];
111         if (t > 0)
112                 while (t--)
113                         mb.font.incSize();
114         else
115                 while (t++)
116                         mb.font.decSize();
117         mb.style = style;
118 }
119
120 MathStyleChanger::~MathStyleChanger()
121 {
122         orig_ = save_;
123 }
124
125
126
127 MathFontSetChanger::MathFontSetChanger(MathMetricsBase & mb, char const * name)
128         :       MathChanger<MathMetricsBase>(mb)
129 {
130         save_ = mb;
131         mb.fontname = name;
132         augmentFont(mb.font, name);
133 }
134
135 MathFontSetChanger::~MathFontSetChanger()
136 {
137         orig_ = save_;
138 }
139
140
141 MathWidthChanger::MathWidthChanger(MathMetricsBase & mb, int w)
142         :       MathChanger<MathMetricsBase>(mb)
143 {
144         save_ = mb;
145         mb.restrictwidth = true;
146         mb.textwidth     = w;
147 }
148
149
150 MathWidthChanger::~MathWidthChanger()
151 {
152         orig_ = save_;
153 }