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)
56 void PainterInfo::draw(int x, int y, char c)
58 pain.text(x, y, c, base.font);
62 Styles smallerScriptStyle(Styles st)
69 case LM_ST_SCRIPTSCRIPT:
70 default: // shut up compiler
71 return LM_ST_SCRIPTSCRIPT;
75 ScriptChanger::ScriptChanger(MetricsBase & mb)
76 : StyleChanger(mb, smallerScriptStyle(mb.style))
81 Styles smallerFracStyle(Styles st)
89 case LM_ST_SCRIPTSCRIPT:
90 default: // shut up compiler
91 return LM_ST_SCRIPTSCRIPT;
96 FracChanger::FracChanger(MetricsBase & mb)
97 : StyleChanger(mb, smallerFracStyle(mb.style))
102 ArrayChanger::ArrayChanger(MetricsBase & mb)
103 : StyleChanger(mb, mb.style == LM_ST_DISPLAY ? LM_ST_TEXT : mb.style)
107 ShapeChanger::ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape)
108 : Changer<LyXFont, LyXFont::FONT_SHAPE>(font)
110 save_ = orig_.shape();
111 orig_.setShape(shape);
114 ShapeChanger::~ShapeChanger()
116 orig_.setShape(save_);
121 StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
122 : Changer<MetricsBase>(mb)
124 static const int diff[4][4] =
130 int t = diff[mb.style][style];
141 StyleChanger::~StyleChanger()
148 FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
149 : Changer<MetricsBase>(mb)
152 LyXFont::FONT_SIZE oldsize = save_.font.size();
155 augmentFont(mb.font, name);
156 mb.font.setSize(oldsize);
160 FontSetChanger::~FontSetChanger()
166 WidthChanger::WidthChanger(MetricsBase & mb, int w)
167 : Changer<MetricsBase>(mb)
174 WidthChanger::~WidthChanger()
182 ColorChanger::ColorChanger(LyXFont & font, string const & color)
183 : Changer<LyXFont, string>(font)
185 save_ = lcolor.getFromLyXName(color);
186 font.setColor(lcolor.getFromLyXName(color));
190 ColorChanger::~ColorChanger()
192 orig_.setColor(lcolor.getFromLyXName(save_));