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>
30 MetricsBase::MetricsBase()
31 : bv(0), font(), style(LM_ST_TEXT
), fontname("mathnormal"),
36 MetricsBase::MetricsBase(BufferView
* b
, FontInfo
const & f
, int w
)
37 : bv(b
), font(f
), style(LM_ST_TEXT
), fontname("mathnormal"),
42 MetricsInfo::MetricsInfo(BufferView
* bv
, FontInfo
const & font
, int textwidth
,
43 MacroContext
const & mc
)
44 : base(bv
, font
, textwidth
), macrocontext(mc
)
48 PainterInfo::PainterInfo(BufferView
* bv
, lyx::frontend::Painter
& painter
)
49 : pain(painter
), ltr_pos(false), erased_(false), full_repaint(true),
50 background_color(Color_background
)
56 void PainterInfo::draw(int x
, int y
, char_type c
)
58 pain
.text(x
, y
, c
, base
.font
);
62 void PainterInfo::draw(int x
, int y
, docstring
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(FontInfo
& font
, FontShape shape
)
114 : Changer
<FontInfo
, FontShape
>(font
)
116 save_
= orig_
.shape();
117 orig_
.setShape(shape
);
121 ShapeChanger::~ShapeChanger()
123 orig_
.setShape(save_
);
128 StyleChanger::StyleChanger(MetricsBase
& mb
, Styles style
)
129 : Changer
<MetricsBase
>(mb
)
131 static const int diff
[4][4] =
137 int t
= diff
[mb
.style
][style
];
148 StyleChanger::~StyleChanger()
155 FontSetChanger::FontSetChanger(MetricsBase
& mb
, char const * name
)
156 : Changer
<MetricsBase
>(mb
)
159 FontSize oldsize
= save_
.font
.size();
162 augmentFont(mb
.font
, from_ascii(name
));
163 mb
.font
.setSize(oldsize
);
167 FontSetChanger::FontSetChanger(MetricsBase
& mb
, docstring
const & name
)
168 : Changer
<MetricsBase
>(mb
)
171 FontSize oldsize
= save_
.font
.size();
172 mb
.fontname
= to_utf8(name
);
174 augmentFont(mb
.font
, name
);
175 mb
.font
.setSize(oldsize
);
179 FontSetChanger::~FontSetChanger()
185 WidthChanger::WidthChanger(MetricsBase
& mb
, int w
)
186 : Changer
<MetricsBase
>(mb
)
193 WidthChanger::~WidthChanger()
201 ColorChanger::ColorChanger(FontInfo
& font
, string
const & color
)
202 : Changer
<FontInfo
, string
>(font
)
204 save_
= lcolor
.getFromLyXName(color
);
205 font
.setColor(lcolor
.getFromLyXName(color
));
209 ColorChanger::~ColorChanger()
211 orig_
.setColor(lcolor
.getFromLyXName(save_
));