]> git.lyx.org Git - lyx.git/blob - src/mathed/math_metricsinfo.C
several fixes concerning font size in scripts/fractions/etc
[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
53 MathScriptChanger::MathScriptChanger(MathMetricsBase & mb)
54         : MathStyleChanger(mb, smallerScriptStyle(mb.style))
55 {}
56
57
58
59 MathStyles smallerFracStyle(MathStyles st)
60 {
61         switch (st) {
62                 case LM_ST_DISPLAY:
63                         return LM_ST_TEXT;
64                 case LM_ST_TEXT:
65                         return LM_ST_SCRIPT;
66                 case LM_ST_SCRIPT:
67                 case LM_ST_SCRIPTSCRIPT:
68                         return LM_ST_SCRIPTSCRIPT;
69         }
70         // shut up compiler
71         lyxerr << "should not happen\n";
72         return LM_ST_DISPLAY;
73 }
74
75
76 MathFracChanger::MathFracChanger(MathMetricsBase & mb)
77         : MathStyleChanger(mb, smallerFracStyle(mb.style))
78 {}
79
80
81
82 MathShapeChanger::MathShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
83         : MathChanger<LyXFont, LyXFont::FONT_SHAPE>(font)
84 {
85         save_ = orig_.shape();
86         orig_.setShape(shape);
87 }
88
89 MathShapeChanger::~MathShapeChanger()
90 {
91         orig_.setShape(save_);
92 }
93
94
95
96
97 MathStyleChanger::MathStyleChanger(MathMetricsBase & mb, MathStyles style)
98         :       MathChanger<MathMetricsBase>(mb)
99 {
100         static const int diff[4][4]  = { { 0, 0, -3, -5 },
101                                          { 0, 0, -3, -5 },
102                                          { 3, 3,  0, -2 },
103                                          { 5, 5,  2,  0 } };
104         save_ = mb;
105         int t = diff[mb.style][style];
106         if (t > 0) 
107                 while (t--)
108                         mb.font.incSize();
109         else 
110                 while (t++)
111                         mb.font.decSize();
112         mb.style = style;
113 }
114
115
116 MathStyleChanger::~MathStyleChanger()
117 {
118         orig_ = save_;
119 }
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 }
151