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, FontInfo const & f, int w)
36 : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
41 MetricsInfo::MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth,
42 MacroContext const & mc)
43 : base(bv, font, textwidth), macrocontext(mc)
47 PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
48 : pain(painter), ltr_pos(false), erased_(false), full_repaint(true),
49 background_color(Color_background)
55 void PainterInfo::draw(int x, int y, char_type c)
57 pain.text(x, y, c, base.font);
61 void PainterInfo::draw(int x, int y, docstring const & str)
63 pain.text(x, y, str, base.font);
67 Styles smallerScriptStyle(Styles st)
74 case LM_ST_SCRIPTSCRIPT:
75 default: // shut up compiler
76 return LM_ST_SCRIPTSCRIPT;
80 ScriptChanger::ScriptChanger(MetricsBase & mb)
81 : StyleChanger(mb, smallerScriptStyle(mb.style))
86 Styles smallerFracStyle(Styles st)
94 case LM_ST_SCRIPTSCRIPT:
95 default: // shut up compiler
96 return LM_ST_SCRIPTSCRIPT;
101 FracChanger::FracChanger(MetricsBase & mb)
102 : StyleChanger(mb, smallerFracStyle(mb.style))
107 ArrayChanger::ArrayChanger(MetricsBase & mb)
108 : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
112 ShapeChanger::ShapeChanger(FontInfo & font, FontShape shape)
113 : Changer<FontInfo, FontShape>(font)
115 save_ = orig_.shape();
116 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 FontSize oldsize = save_.font.size();
161 augmentFont(mb.font, from_ascii(name));
162 mb.font.setSize(oldsize);
166 FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name)
167 : Changer<MetricsBase>(mb)
170 FontSize oldsize = save_.font.size();
171 mb.fontname = to_utf8(name);
173 augmentFont(mb.font, name);
174 mb.font.setSize(oldsize);
178 FontSetChanger::~FontSetChanger()
184 WidthChanger::WidthChanger(MetricsBase & mb, int w)
185 : Changer<MetricsBase>(mb)
192 WidthChanger::~WidthChanger()
200 ColorChanger::ColorChanger(FontInfo & font, string const & color)
201 : Changer<FontInfo, string>(font)
203 save_ = lcolor.getFromLyXName(color);
204 font.setColor(lcolor.getFromLyXName(color));
208 ColorChanger::~ColorChanger()
210 orig_.setColor(lcolor.getFromLyXName(save_));