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/math_support.h"
19 #include "frontends/Painter.h"
21 #include <boost/assert.hpp>
26 MetricsBase::MetricsBase()
27 : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
32 MetricsBase::MetricsBase(BufferView * b, LyXFont const & f, int w)
33 : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
39 MetricsInfo::MetricsInfo()
43 MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth)
44 : base(bv, font, textwidth)
49 PainterInfo::PainterInfo(BufferView * bv, Painter & painter)
50 : pain(painter), ltr_pos(false), erased_(false)
56 void PainterInfo::draw(int x, int y, char c)
58 pain.text(x, y, c, base.font);
62 void PainterInfo::draw(int x, int y, std::string const & str)
64 pain.text(x, y, str, base.font);
68 Styles smallerScriptStyle(Styles st)
75 case LM_ST_SCRIPTSCRIPT:
76 default: // shut up compiler
77 return LM_ST_SCRIPTSCRIPT;
81 ScriptChanger::ScriptChanger(MetricsBase & mb)
82 : StyleChanger(mb, smallerScriptStyle(mb.style))
87 Styles smallerFracStyle(Styles st)
95 case LM_ST_SCRIPTSCRIPT:
96 default: // shut up compiler
97 return LM_ST_SCRIPTSCRIPT;
102 FracChanger::FracChanger(MetricsBase & mb)
103 : StyleChanger(mb, smallerFracStyle(mb.style))
108 ArrayChanger::ArrayChanger(MetricsBase & mb)
109 : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
113 ShapeChanger::ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
114 : Changer<LyXFont, LyXFont::FONT_SHAPE>(font)
116 save_ = orig_.shape();
117 orig_.setShape(shape);
120 ShapeChanger::~ShapeChanger()
122 orig_.setShape(save_);
127 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
128 : Changer<MetricsBase>(mb)
130 static const int diff[4][4] =
136 int t = diff[mb.style][style];
147 StyleChanger::~StyleChanger()
154 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
155 : Changer<MetricsBase>(mb)
158 LyXFont::FONT_SIZE oldsize = save_.font.size();
161 augmentFont(mb.font, name);
162 mb.font.setSize(oldsize);
166 FontSetChanger::~FontSetChanger()
172 WidthChanger::WidthChanger(MetricsBase & mb, int w)
173 : Changer<MetricsBase>(mb)
180 WidthChanger::~WidthChanger()
188 ColorChanger::ColorChanger(LyXFont & font, string const & color)
189 : Changer<LyXFont, string>(font)
191 save_ = lcolor.getFromLyXName(color);
192 font.setColor(lcolor.getFromLyXName(color));
196 ColorChanger::~ColorChanger()
198 orig_.setColor(lcolor.getFromLyXName(save_));