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