]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.C
Point fix, earlier forgotten
[lyx.git] / src / metricsinfo.C
1 /**
2  * \file metricsinfo.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "metricsinfo.h"
14 #include "mathed/math_support.h"
15 #include "frontends/Painter.h"
16 #include "debug.h"
17 #include "BufferView.h"
18
19
20
21 MetricsBase::MetricsBase()
22         : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
23           textwidth(0)
24 {}
25
26
27
28 MetricsBase::MetricsBase(BufferView * b, LyXFont const & f, int w)
29         : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
30           textwidth(w)
31 {}
32
33
34
35 MetricsInfo::MetricsInfo()
36 {}
37
38
39 MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth)
40         : base(bv, font, textwidth)
41 {}
42
43
44
45 PainterInfo::PainterInfo(BufferView * bv)
46         : pain(bv->painter())
47 {
48         base.bv = bv;
49 }
50
51
52 void PainterInfo::draw(int x, int y, char c)
53 {
54         pain.text(x, y, c, base.font);
55 }
56
57
58 Styles smallerScriptStyle(Styles st)
59 {
60         switch (st) {
61                 case LM_ST_DISPLAY:
62                 case LM_ST_TEXT:
63                         return LM_ST_SCRIPT;
64                 case LM_ST_SCRIPT:
65                 case LM_ST_SCRIPTSCRIPT:
66                 default: // shut up compiler
67                         return LM_ST_SCRIPTSCRIPT;
68         }
69 }
70
71 ScriptChanger::ScriptChanger(MetricsBase & mb)
72         : StyleChanger(mb, smallerScriptStyle(mb.style))
73 {}
74
75
76
77 Styles smallerFracStyle(Styles st)
78 {
79         switch (st) {
80                 case LM_ST_DISPLAY:
81                         return LM_ST_TEXT;
82                 case LM_ST_TEXT:
83                         return LM_ST_SCRIPT;
84                 case LM_ST_SCRIPT:
85                 case LM_ST_SCRIPTSCRIPT:
86                 default: // shut up compiler
87                         return LM_ST_SCRIPTSCRIPT;
88         }
89 }
90
91
92 FracChanger::FracChanger(MetricsBase & mb)
93         : StyleChanger(mb, smallerFracStyle(mb.style))
94 {}
95
96
97
98 ArrayChanger::ArrayChanger(MetricsBase & mb)
99         : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
100 {}
101
102
103 ShapeChanger::ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
104         : Changer<LyXFont, LyXFont::FONT_SHAPE>(font)
105 {
106         save_ = orig_.shape();
107         orig_.setShape(shape);
108 }
109
110 ShapeChanger::~ShapeChanger()
111 {
112         orig_.setShape(save_);
113 }
114
115
116
117 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
118         :       Changer<MetricsBase>(mb)
119 {
120         static const int diff[4][4]  = { { 0, 0, -3, -5 },
121                                          { 0, 0, -3, -5 },
122                                          { 3, 3,  0, -2 },
123                                          { 5, 5,  2,  0 } };
124         save_ = mb;
125         int t = diff[mb.style][style];
126         if (t > 0)
127                 while (t--)
128                         mb.font.incSize();
129         else
130                 while (t++)
131                         mb.font.decSize();
132         mb.style = style;
133 }
134
135
136 StyleChanger::~StyleChanger()
137 {
138         orig_ = save_;
139 }
140
141
142
143 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
144         :       Changer<MetricsBase>(mb)
145 {
146         save_ = mb;
147         mb.fontname = name;
148         augmentFont(mb.font, name);
149 }
150
151 FontSetChanger::~FontSetChanger()
152 {
153         orig_ = save_;
154 }
155
156
157 WidthChanger::WidthChanger(MetricsBase & mb, int w)
158         :       Changer<MetricsBase>(mb)
159 {
160         save_ = mb;
161         mb.textwidth     = w;
162 }
163
164
165 WidthChanger::~WidthChanger()
166 {
167         orig_ = save_;
168 }