2 * \file MetricsInfo.cpp
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 "support/docstring.h"
23 #include <boost/assert.hpp>
31 MetricsBase::MetricsBase()
32 : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
37 MetricsBase::MetricsBase(BufferView * b, FontInfo const & f, int w)
38 : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
43 MetricsInfo::MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth,
44 MacroContext const & mc)
45 : base(bv, font, textwidth), macrocontext(mc)
49 PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
50 : pain(painter), ltr_pos(false), erased_(false), full_repaint(true),
51 background_color(Color_background)
57 void PainterInfo::draw(int x, int y, char_type c)
59 pain.text(x, y, c, base.font);
63 void PainterInfo::draw(int x, int y, docstring const & str)
65 pain.text(x, y, str, base.font);
69 Styles smallerScriptStyle(Styles st)
76 case LM_ST_SCRIPTSCRIPT:
77 default: // shut up compiler
78 return LM_ST_SCRIPTSCRIPT;
82 ScriptChanger::ScriptChanger(MetricsBase & mb)
83 : StyleChanger(mb, smallerScriptStyle(mb.style))
88 Styles smallerFracStyle(Styles st)
96 case LM_ST_SCRIPTSCRIPT:
97 default: // shut up compiler
98 return LM_ST_SCRIPTSCRIPT;
103 FracChanger::FracChanger(MetricsBase & mb)
104 : StyleChanger(mb, smallerFracStyle(mb.style))
109 ArrayChanger::ArrayChanger(MetricsBase & mb)
110 : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
114 ShapeChanger::ShapeChanger(FontInfo & font, FontShape shape)
115 : Changer<FontInfo, FontShape>(font)
117 save_ = orig_.shape();
118 orig_.setShape(shape);
122 ShapeChanger::~ShapeChanger()
124 orig_.setShape(save_);
129 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
130 : Changer<MetricsBase>(mb)
132 static const int diff[4][4] =
138 int t = diff[mb.style][style];
149 StyleChanger::~StyleChanger()
156 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
157 : Changer<MetricsBase>(mb)
160 FontSize oldsize = save_.font.size();
163 augmentFont(mb.font, from_ascii(name));
164 mb.font.setSize(oldsize);
168 FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name)
169 : Changer<MetricsBase>(mb)
172 FontSize oldsize = save_.font.size();
173 mb.fontname = to_utf8(name);
175 augmentFont(mb.font, name);
176 mb.font.setSize(oldsize);
180 FontSetChanger::~FontSetChanger()
186 WidthChanger::WidthChanger(MetricsBase & mb, int w)
187 : Changer<MetricsBase>(mb)
194 WidthChanger::~WidthChanger()
202 ColorChanger::ColorChanger(FontInfo & font, string const & color)
203 : Changer<FontInfo, string>(font)
205 save_ = lcolor.getFromLyXName(color);
206 font.setColor(lcolor.getFromLyXName(color));
210 ColorChanger::~ColorChanger()
212 orig_.setColor(lcolor.getFromLyXName(save_));