]> git.lyx.org Git - lyx.git/blob - src/mathed/math_metricsinfo.C
the fontsize changing in arrays
[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 MathArrayChanger::MathArrayChanger(MathMetricsBase & mb)
85         : MathStyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
86 {}
87
88
89 MathShapeChanger::MathShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
90         : MathChanger<LyXFont, LyXFont::FONT_SHAPE>(font)
91 {
92         save_ = orig_.shape();
93         orig_.setShape(shape);
94 }
95
96 MathShapeChanger::~MathShapeChanger()
97 {
98         orig_.setShape(save_);
99 }
100
101
102
103 MathStyleChanger::MathStyleChanger(MathMetricsBase & mb, MathStyles style)
104         :       MathChanger<MathMetricsBase>(mb)
105 {
106         static const int diff[4][4]  = { { 0, 0, -3, -5 },
107                                          { 0, 0, -3, -5 },
108                                          { 3, 3,  0, -2 },
109                                          { 5, 5,  2,  0 } };
110         save_ = mb;
111         int t = diff[mb.style][style];
112         if (t > 0) 
113                 while (t--)
114                         mb.font.incSize();
115         else 
116                 while (t++)
117                         mb.font.decSize();
118         mb.style = style;
119 }
120
121 MathStyleChanger::~MathStyleChanger()
122 {
123         orig_ = save_;
124 }
125
126
127
128 MathFontSetChanger::MathFontSetChanger(MathMetricsBase & mb, char const * name)
129         :       MathChanger<MathMetricsBase>(mb)
130 {
131         save_ = mb;     
132         mb.fontname = name;
133         augmentFont(mb.font, name);
134 }
135
136 MathFontSetChanger::~MathFontSetChanger()
137 {
138         orig_ = save_;
139 }
140
141
142 MathWidthChanger::MathWidthChanger(MathMetricsBase & mb, int w)
143         :       MathChanger<MathMetricsBase>(mb)
144 {
145         save_ = mb;     
146         mb.restrictwidth = true;
147         mb.textwidth     = w;
148 }
149
150
151 MathWidthChanger::~MathWidthChanger()
152 {
153         orig_ = save_;
154 }
155