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 <boost/assert.hpp>
29 MetricsBase::MetricsBase()
30 : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
35 MetricsBase::MetricsBase(BufferView * b, Font const & f, int w)
36 : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
42 MetricsInfo::MetricsInfo()
46 MetricsInfo::MetricsInfo(BufferView * bv, Font 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), full_repaint(true),
54 background_color(Color::background)
60 void PainterInfo::draw(int x, int y, char_type c)
62 pain.text(x, y, c, base.font);
66 void PainterInfo::draw(int x, int y, docstring const & str)
68 pain.text(x, y, str, base.font);
72 Styles smallerScriptStyle(Styles st)
79 case LM_ST_SCRIPTSCRIPT:
80 default: // shut up compiler
81 return LM_ST_SCRIPTSCRIPT;
85 ScriptChanger::ScriptChanger(MetricsBase & mb)
86 : StyleChanger(mb, smallerScriptStyle(mb.style))
91 Styles smallerFracStyle(Styles st)
99 case LM_ST_SCRIPTSCRIPT:
100 default: // shut up compiler
101 return LM_ST_SCRIPTSCRIPT;
106 FracChanger::FracChanger(MetricsBase & mb)
107 : StyleChanger(mb, smallerFracStyle(mb.style))
112 ArrayChanger::ArrayChanger(MetricsBase & mb)
113 : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
118 ShapeChanger::ShapeChanger(Font & font, Font::FONT_SHAPE shape)
119 : Changer<Font, Font::FONT_SHAPE>(font)
121 save_ = orig_.shape();
122 orig_.setShape(shape);
126 ShapeChanger::~ShapeChanger()
128 orig_.setShape(save_);
133 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
134 : Changer<MetricsBase>(mb)
136 static const int diff[4][4] =
142 int t = diff[mb.style][style];
153 StyleChanger::~StyleChanger()
160 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
161 : Changer<MetricsBase>(mb)
164 Font::FONT_SIZE oldsize = save_.font.size();
167 augmentFont(mb.font, from_ascii(name));
168 mb.font.setSize(oldsize);
172 FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name)
173 : Changer<MetricsBase>(mb)
176 Font::FONT_SIZE oldsize = save_.font.size();
177 mb.fontname = to_utf8(name);
179 augmentFont(mb.font, name);
180 mb.font.setSize(oldsize);
184 FontSetChanger::~FontSetChanger()
190 WidthChanger::WidthChanger(MetricsBase & mb, int w)
191 : Changer<MetricsBase>(mb)
198 WidthChanger::~WidthChanger()
206 ColorChanger::ColorChanger(Font & font, string const & color)
207 : Changer<Font, string>(font)
209 save_ = lcolor.getFromLyXName(color);
210 font.setColor(lcolor.getFromLyXName(color));
214 ColorChanger::~ColorChanger()
216 orig_.setColor(lcolor.getFromLyXName(save_));