From c88eaf877ec9b9f7e41658af5b4b3b55e6078cd6 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Tue, 27 Apr 2010 21:31:28 +0000 Subject: [PATCH] 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 --- src/MetricsInfo.cpp | 49 +++++++++++++++++------------- src/MetricsInfo.h | 9 ++++-- src/mathed/InsetMathDecoration.cpp | 10 +++--- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp index 2ddca9b359..05fc0658b1 100644 --- a/src/MetricsInfo.cpp +++ b/src/MetricsInfo.cpp @@ -227,37 +227,44 @@ StyleChanger::~StyleChanger() // ///////////////////////////////////////////////////////////////////////// -FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name) - : Changer(mb) +FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name, + bool really_change_font) + : Changer(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(mb) +FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name, + bool really_change_font) + : Changer(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_; } diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h index a711a2a416..6297c7b4a0 100644 --- a/src/MetricsInfo.h +++ b/src/MetricsInfo.h @@ -153,10 +153,15 @@ public: class FontSetChanger : public Changer { 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_; }; diff --git a/src/mathed/InsetMathDecoration.cpp b/src/mathed/InsetMathDecoration.cpp index 1cb3aebcc1..37fae79911 100644 --- a/src/mathed/InsetMathDecoration.cpp +++ b/src/mathed/InsetMathDecoration.cpp @@ -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);