mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-21 23:09:40 +00:00
Changing only the shape does not always work. For example,
\mathbb{\underbar{a}} is not correctly rendered on screen. We really have to change the font set, but not always. This cannot be done using an "if" statement, as when the FontSetChanger scope ends, everything is restored, defeating our change. Thus, this has to be done in the FontSetChanger class itself. This is easily accomplished by introducing a boolean with a default value of true for really changing a font set. This will also be useful in other cases that I am discovering. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34312 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
dbb5ac93ea
commit
c88eaf877e
@ -227,37 +227,44 @@ StyleChanger::~StyleChanger()
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
|
||||
: Changer<MetricsBase>(mb)
|
||||
FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name,
|
||||
bool really_change_font)
|
||||
: Changer<MetricsBase>(mb), change_(really_change_font)
|
||||
{
|
||||
save_ = mb;
|
||||
FontSize oldsize = save_.font.size();
|
||||
ColorCode oldcolor = save_.font.color();
|
||||
mb.fontname = name;
|
||||
mb.font = sane_font;
|
||||
augmentFont(mb.font, from_ascii(name));
|
||||
mb.font.setSize(oldsize);
|
||||
mb.font.setColor(oldcolor);
|
||||
if (change_) {
|
||||
save_ = mb;
|
||||
FontSize oldsize = save_.font.size();
|
||||
ColorCode oldcolor = save_.font.color();
|
||||
mb.fontname = name;
|
||||
mb.font = sane_font;
|
||||
augmentFont(mb.font, from_ascii(name));
|
||||
mb.font.setSize(oldsize);
|
||||
mb.font.setColor(oldcolor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name)
|
||||
: Changer<MetricsBase>(mb)
|
||||
FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name,
|
||||
bool really_change_font)
|
||||
: Changer<MetricsBase>(mb), change_(really_change_font)
|
||||
{
|
||||
save_ = mb;
|
||||
FontSize oldsize = save_.font.size();
|
||||
ColorCode oldcolor = save_.font.color();
|
||||
mb.fontname = to_utf8(name);
|
||||
mb.font = sane_font;
|
||||
augmentFont(mb.font, name);
|
||||
mb.font.setSize(oldsize);
|
||||
mb.font.setColor(oldcolor);
|
||||
if (change_) {
|
||||
save_ = mb;
|
||||
FontSize oldsize = save_.font.size();
|
||||
ColorCode oldcolor = save_.font.color();
|
||||
mb.fontname = to_utf8(name);
|
||||
mb.font = sane_font;
|
||||
augmentFont(mb.font, name);
|
||||
mb.font.setSize(oldsize);
|
||||
mb.font.setColor(oldcolor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FontSetChanger::~FontSetChanger()
|
||||
{
|
||||
orig_ = save_;
|
||||
if (change_)
|
||||
orig_ = save_;
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,10 +153,15 @@ public:
|
||||
class FontSetChanger : public Changer<MetricsBase> {
|
||||
public:
|
||||
///
|
||||
FontSetChanger(MetricsBase & mb, docstring const & font);
|
||||
FontSetChanger(MetricsBase & mb, char const * const font);
|
||||
FontSetChanger(MetricsBase & mb, docstring const & font,
|
||||
bool really_change_font = true);
|
||||
FontSetChanger(MetricsBase & mb, char const * const font,
|
||||
bool really_change_font = true);
|
||||
///
|
||||
~FontSetChanger();
|
||||
private:
|
||||
///
|
||||
bool change_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -105,10 +105,9 @@ InsetMath::mode_type InsetMathDecoration::currentMode() const
|
||||
|
||||
void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
bool const upshape = currentMode() == TEXT_MODE
|
||||
bool really_change_font = currentMode() == TEXT_MODE
|
||||
&& isMathFont(from_ascii(mi.base.fontname));
|
||||
ShapeChanger dummy(mi.base.font, upshape ?
|
||||
UP_SHAPE : mi.base.font.shape());
|
||||
FontSetChanger dummy(mi.base, "textnormal", really_change_font);
|
||||
|
||||
cell(0).metrics(mi, dim);
|
||||
|
||||
@ -129,10 +128,9 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
|
||||
void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
bool const upshape = currentMode() == TEXT_MODE
|
||||
bool really_change_font = currentMode() == TEXT_MODE
|
||||
&& isMathFont(from_ascii(pi.base.fontname));
|
||||
ShapeChanger dummy(pi.base.font, upshape ?
|
||||
UP_SHAPE : pi.base.font.shape());
|
||||
FontSetChanger dummy(pi.base, "textnormal", really_change_font);
|
||||
|
||||
cell(0).draw(pi, x + 1, y);
|
||||
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user