3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "BufferView.h"
15 #include "metricsinfo.h"
17 #include "mathed/MathSupport.h"
19 #include "frontends/Painter.h"
21 #include <boost/assert.hpp>
29 MetricsBase::MetricsBase()
30 : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
35 MetricsBase::MetricsBase(BufferView * b, LyXFont const & f, int w)
36 : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
42 MetricsInfo::MetricsInfo()
46 MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth)
47 : base(bv, font, textwidth)
52 PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
53 : pain(painter), ltr_pos(false), erased_(false)
59 void PainterInfo::draw(int x, int y, char_type c)
61 pain.text(x, y, c, base.font);
65 void PainterInfo::draw(int x, int y, docstring const & str)
67 pain.text(x, y, str, base.font);
71 Styles smallerScriptStyle(Styles st)
78 case LM_ST_SCRIPTSCRIPT:
79 default: // shut up compiler
80 return LM_ST_SCRIPTSCRIPT;
84 ScriptChanger::ScriptChanger(MetricsBase & mb)
85 : StyleChanger(mb, smallerScriptStyle(mb.style))
90 Styles smallerFracStyle(Styles st)
98 case LM_ST_SCRIPTSCRIPT:
99 default: // shut up compiler
100 return LM_ST_SCRIPTSCRIPT;
105 FracChanger::FracChanger(MetricsBase & mb)
106 : StyleChanger(mb, smallerFracStyle(mb.style))
111 ArrayChanger::ArrayChanger(MetricsBase & mb)
112 : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
117 ShapeChanger::ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
118 : Changer<LyXFont, LyXFont::FONT_SHAPE>(font)
120 save_ = orig_.shape();
121 orig_.setShape(shape);
125 ShapeChanger::~ShapeChanger()
127 orig_.setShape(save_);
132 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
133 : Changer<MetricsBase>(mb)
135 static const int diff[4][4] =
141 int t = diff[mb.style][style];
152 StyleChanger::~StyleChanger()
159 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
160 : Changer<MetricsBase>(mb)
163 LyXFont::FONT_SIZE oldsize = save_.font.size();
166 augmentFont(mb.font, from_ascii(name));
167 mb.font.setSize(oldsize);
171 FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name)
172 : Changer<MetricsBase>(mb)
175 LyXFont::FONT_SIZE oldsize = save_.font.size();
176 mb.fontname = to_utf8(name);
178 augmentFont(mb.font, name);
179 mb.font.setSize(oldsize);
183 FontSetChanger::~FontSetChanger()
189 WidthChanger::WidthChanger(MetricsBase & mb, int w)
190 : Changer<MetricsBase>(mb)
197 WidthChanger::~WidthChanger()
205 ColorChanger::ColorChanger(LyXFont & font, string const & color)
206 : Changer<LyXFont, string>(font)
208 save_ = lcolor.getFromLyXName(color);
209 font.setColor(lcolor.getFromLyXName(color));
213 ColorChanger::~ColorChanger()
215 orig_.setColor(lcolor.getFromLyXName(save_));