]> git.lyx.org Git - lyx.git/blobdiff - src/MetricsInfo.cpp
Fix #10778 (issue with CJK and language nesting)
[lyx.git] / src / MetricsInfo.cpp
index 788709cd49cccc413d88582dc21c44256dbc63dd..71d7a39de1a75c4e356d1967a9fc3093d284bc11 100644 (file)
@@ -66,7 +66,7 @@ MetricsInfo::MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth,
 
 PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
        : pain(painter), ltr_pos(false), change_(), selected(false),
-       full_repaint(true), background_color(Color_background)
+       do_spellcheck(true), full_repaint(true), background_color(Color_background)
 {
        base.bv = bv;
 }
@@ -86,7 +86,7 @@ void PainterInfo::draw(int x, int y, docstring const & str)
 
 ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
 {
-       ColorCode const color_bg = inset->backgroundColor();
+       ColorCode const color_bg = inset->backgroundColor(*this);
 
        if (selected && sel)
                // This inset is in a selection
@@ -107,6 +107,16 @@ ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
 }
 
 
+Color PainterInfo::textColor(Color const & color) const
+{
+       if (change_.changed()) 
+               return change_.color();
+       if (selected)
+               return Color_selectiontext;
+       return color;
+}
+
+
 /////////////////////////////////////////////////////////////////////////
 //
 // ScriptChanger
@@ -176,9 +186,8 @@ ArrayChanger::ArrayChanger(MetricsBase & mb)
 /////////////////////////////////////////////////////////////////////////
 
 ShapeChanger::ShapeChanger(FontInfo & font, FontShape shape)
-       : Changer<FontInfo, FontShape>(font)
+       : Changer<FontInfo, FontShape>(font, font.shape())
 {
-       save_ = orig_.shape();
        orig_.setShape(shape);
 }
 
@@ -203,7 +212,6 @@ StyleChanger::StyleChanger(MetricsBase & mb, Styles style)
                  { 0, 0, -3, -5 },
                  { 3, 3,  0, -2 },
                  { 5, 5,  2,  0 } };
-       save_ = mb;
        int t = diff[mb.style][style];
        if (t > 0)
                while (t--)
@@ -227,33 +235,52 @@ 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();
-       mb.fontname = name;
-       mb.font = sane_font;
-       augmentFont(mb.font, from_ascii(name));
-       mb.font.setSize(oldsize);
+       if (change_) {
+               FontSize oldsize = save_.font.size();
+               ColorCode oldcolor = save_.font.color();
+               docstring const oldname = from_ascii(save_.fontname);
+               mb.fontname = name;
+               if (isMathFont(from_ascii(name)) || isMathFont(oldname))
+                       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();
-       mb.fontname = to_utf8(name);
-       mb.font = sane_font;
-       augmentFont(mb.font, name);
-       mb.font.setSize(oldsize);
+       if (change_) {
+               FontSize oldsize = save_.font.size();
+               ColorCode oldcolor = save_.font.color();
+               docstring const oldname = from_ascii(save_.fontname);
+               mb.fontname = to_utf8(name);
+               if (isMathFont(name) || isMathFont(oldname))
+                       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_;
 }
 
 
@@ -266,7 +293,6 @@ FontSetChanger::~FontSetChanger()
 WidthChanger::WidthChanger(MetricsBase & mb, int w)
        : Changer<MetricsBase>(mb)
 {
-       save_ = mb;
        mb.textwidth = w;
 }
 
@@ -283,17 +309,20 @@ WidthChanger::~WidthChanger()
 //
 /////////////////////////////////////////////////////////////////////////
 
-ColorChanger::ColorChanger(FontInfo & font, string const & color)
-       : Changer<FontInfo, string>(font)
+ColorChanger::ColorChanger(FontInfo & font, ColorCode color,
+                          bool really_change_color)
+       : Changer<FontInfo, ColorCode>(font, font.color()), change_(really_change_color)
 {
-       save_ = lcolor.getFromLyXName(color);
-       font.setColor(lcolor.getFromLyXName(color));
+       if (change_) {
+               font.setColor(color);
+       }
 }
 
 
 ColorChanger::~ColorChanger()
 {
-       orig_.setColor(lcolor.getFromLyXName(save_));
+       if (change_)
+               orig_.setColor(save_);
 }