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