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