Author: forenr
Date: Tue Jun  1 16:19:40 2010
New Revision: 34582
URL: http://www.lyx.org/trac/changeset/34582

Log:
Fix bug #6729: Wrong fonts when using \underbar in math.
See also r34312.

Modified:
   lyx-devel/branches/BRANCH_1_6_X/src/MetricsInfo.cpp
   lyx-devel/branches/BRANCH_1_6_X/src/MetricsInfo.h
   lyx-devel/branches/BRANCH_1_6_X/src/mathed/InsetMathDecoration.cpp
   lyx-devel/branches/BRANCH_1_6_X/status.16x

Modified: lyx-devel/branches/BRANCH_1_6_X/src/MetricsInfo.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/MetricsInfo.cpp Tue Jun  1 15:39:44 
2010        (r34581)
+++ lyx-devel/branches/BRANCH_1_6_X/src/MetricsInfo.cpp Tue Jun  1 16:19:40 
2010        (r34582)
@@ -227,45 +227,52 @@
 //
 /////////////////////////////////////////////////////////////////////////
 
-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();
-       docstring const oldname = from_ascii(save_.fontname);
-       mb.fontname = name;
-       mb.font = sane_font;
-       augmentFont(mb.font, from_ascii(name));
-       mb.font.setSize(oldsize);
-       if (string(name) != "lyxtex"
-           && ((isTextFont(oldname) && oldcolor != Color_foreground)
-               || (isMathFont(oldname) && oldcolor != Color_math)))
-               mb.font.setColor(oldcolor);
+       if (change_) {
+               save_ = mb;
+               FontSize oldsize = save_.font.size();
+               ColorCode oldcolor = save_.font.color();
+               docstring const oldname = from_ascii(save_.fontname);
+               mb.fontname = name;
+               mb.font = sane_font;
+               augmentFont(mb.font, from_ascii(name));
+               mb.font.setSize(oldsize);
+               if (string(name) != "lyxtex"
+                   && ((isTextFont(oldname) && oldcolor != Color_foreground)
+                       || (isMathFont(oldname) && oldcolor != Color_math)))
+                       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();
-       docstring const oldname = from_ascii(save_.fontname);
-       mb.fontname = to_utf8(name);
-       mb.font = sane_font;
-       augmentFont(mb.font, name);
-       mb.font.setSize(oldsize);
-       if (name != "lyxtex"
-           && ((isTextFont(oldname) && oldcolor != Color_foreground)
-               || (isMathFont(oldname) && oldcolor != Color_math)))
-               mb.font.setColor(oldcolor);
+       if (change_) {
+               save_ = mb;
+               FontSize oldsize = save_.font.size();
+               ColorCode oldcolor = save_.font.color();
+               docstring const oldname = from_ascii(save_.fontname);
+               mb.fontname = to_utf8(name);
+               mb.font = sane_font;
+               augmentFont(mb.font, name);
+               mb.font.setSize(oldsize);
+               if (name != "lyxtex"
+                   && ((isTextFont(oldname) && oldcolor != Color_foreground)
+                       || (isMathFont(oldname) && oldcolor != Color_math)))
+                       mb.font.setColor(oldcolor);
+       }
 }
 
 
 FontSetChanger::~FontSetChanger()
 {
-       orig_ = save_;
+       if (change_)
+               orig_ = save_;
 }
 
 

Modified: lyx-devel/branches/BRANCH_1_6_X/src/MetricsInfo.h
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/MetricsInfo.h   Tue Jun  1 15:39:44 
2010        (r34581)
+++ lyx-devel/branches/BRANCH_1_6_X/src/MetricsInfo.h   Tue Jun  1 16:19:40 
2010        (r34582)
@@ -152,10 +152,15 @@
 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_;
 };
 
 

Modified: lyx-devel/branches/BRANCH_1_6_X/src/mathed/InsetMathDecoration.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/mathed/InsetMathDecoration.cpp  Tue Jun 
 1 15:39:44 2010        (r34581)
+++ lyx-devel/branches/BRANCH_1_6_X/src/mathed/InsetMathDecoration.cpp  Tue Jun 
 1 16:19:40 2010        (r34582)
@@ -112,10 +112,9 @@
 
 void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       bool const upshape = currentMode() == TEXT_MODE
-                               && mi.base.font.color() == Color_math;
-       ShapeChanger dummy(mi.base.font, upshape ?
-                               UP_SHAPE : mi.base.font.shape());
+       bool really_change_font = currentMode() == TEXT_MODE
+                               && isMathFont(from_ascii(mi.base.fontname));
+       FontSetChanger dummy(mi.base, "textnormal", really_change_font);
 
        cell(0).metrics(mi, dim);
 
@@ -136,10 +135,9 @@
 
 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
 {
-       bool const upshape = currentMode() == TEXT_MODE
-                               && pi.base.font.color() == Color_math;
-       ShapeChanger dummy(pi.base.font, upshape ?
-                               UP_SHAPE : pi.base.font.shape());
+       bool really_change_font = currentMode() == TEXT_MODE
+                               && isMathFont(from_ascii(pi.base.fontname));
+       FontSetChanger dummy(pi.base, "textnormal", really_change_font);
 
        cell(0).draw(pi, x + 1, y);
        Dimension const & dim0 = cell(0).dimension(*pi.base.bv);

Modified: lyx-devel/branches/BRANCH_1_6_X/status.16x
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/status.16x  Tue Jun  1 15:39:44 2010        
(r34581)
+++ lyx-devel/branches/BRANCH_1_6_X/status.16x  Tue Jun  1 16:19:40 2010        
(r34582)
@@ -118,6 +118,8 @@
 - Correctly paint the button for external material when the "Preview"
   attribute is not defined (bug 6677).
 
+- Use right font for rendering the \underbar macro in math (bug 6729).
+
 
 * DOCUMENTATION AND LOCALIZATION
 

Reply via email to