]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.C
Really fix start_of_appendix output
[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 "BufferView.h"
14 #include "LColor.h"
15 #include "metricsinfo.h"
16
17 #include "mathed/math_support.h"
18
19 #include "frontends/Painter.h"
20
21 #include <boost/assert.hpp>
22
23 using std::string;
24
25
26 MetricsBase::MetricsBase()
27         : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
28           textwidth(0)
29 {}
30
31
32 MetricsBase::MetricsBase(BufferView * b, LyXFont const & f, int w)
33         : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
34           textwidth(w)
35 {}
36
37
38
39 MetricsInfo::MetricsInfo()
40 {}
41
42
43 MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth)
44         : base(bv, font, textwidth)
45 {}
46
47
48
49 PainterInfo::PainterInfo(BufferView * bv, Painter & painter)
50         : pain(painter), ltr_pos(false)
51 {
52         base.bv = bv;
53 }
54
55
56 void PainterInfo::draw(int x, int y, char c)
57 {
58         pain.text(x, y, c, base.font);
59 }
60
61
62 Styles smallerScriptStyle(Styles st)
63 {
64         switch (st) {
65                 case LM_ST_DISPLAY:
66                 case LM_ST_TEXT:
67                         return LM_ST_SCRIPT;
68                 case LM_ST_SCRIPT:
69                 case LM_ST_SCRIPTSCRIPT:
70                 default: // shut up compiler
71                         return LM_ST_SCRIPTSCRIPT;
72         }
73 }
74
75 ScriptChanger::ScriptChanger(MetricsBase & mb)
76         : StyleChanger(mb, smallerScriptStyle(mb.style))
77 {}
78
79
80
81 Styles smallerFracStyle(Styles st)
82 {
83         switch (st) {
84                 case LM_ST_DISPLAY:
85                         return LM_ST_TEXT;
86                 case LM_ST_TEXT:
87                         return LM_ST_SCRIPT;
88                 case LM_ST_SCRIPT:
89                 case LM_ST_SCRIPTSCRIPT:
90                 default: // shut up compiler
91                         return LM_ST_SCRIPTSCRIPT;
92         }
93 }
94
95
96 FracChanger::FracChanger(MetricsBase & mb)
97         : StyleChanger(mb, smallerFracStyle(mb.style))
98 {}
99
100
101
102 ArrayChanger::ArrayChanger(MetricsBase & mb)
103         : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
104 {}
105
106
107 ShapeChanger::ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
108         : Changer<LyXFont, LyXFont::FONT_SHAPE>(font)
109 {
110         save_ = orig_.shape();
111         orig_.setShape(shape);
112 }
113
114 ShapeChanger::~ShapeChanger()
115 {
116         orig_.setShape(save_);
117 }
118
119
120
121 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
122         :       Changer<MetricsBase>(mb)
123 {
124         static const int diff[4][4] =
125                 { { 0, 0, -3, -5 },
126                   { 0, 0, -3, -5 },
127                   { 3, 3,  0, -2 },
128                   { 5, 5,  2,  0 } };
129         save_ = mb;
130         int t = diff[mb.style][style];
131         if (t > 0)
132                 while (t--)
133                         mb.font.incSize();
134         else
135                 while (t++)
136                         mb.font.decSize();
137         mb.style = style;
138 }
139
140
141 StyleChanger::~StyleChanger()
142 {
143         orig_ = save_;
144 }
145
146
147
148 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
149         :       Changer<MetricsBase>(mb)
150 {
151         save_ = mb;
152         LyXFont::FONT_SIZE oldsize = save_.font.size();
153         mb.fontname = name;
154         mb.font = LyXFont();
155         augmentFont(mb.font, name);
156         mb.font.setSize(oldsize);
157 }
158
159
160 FontSetChanger::~FontSetChanger()
161 {
162         orig_ = save_;
163 }
164
165
166 WidthChanger::WidthChanger(MetricsBase & mb, int w)
167         :       Changer<MetricsBase>(mb)
168 {
169         save_ = mb;
170         mb.textwidth = w;
171 }
172
173
174 WidthChanger::~WidthChanger()
175 {
176         orig_ = save_;
177 }
178
179
180
181
182 ColorChanger::ColorChanger(LyXFont & font, string const & color)
183         : Changer<LyXFont, string>(font)
184 {
185         save_ = lcolor.getFromLyXName(color);
186         font.setColor(lcolor.getFromLyXName(color));
187 }
188
189
190 ColorChanger::~ColorChanger()
191 {
192         orig_.setColor(lcolor.getFromLyXName(save_));
193 }