X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_colorinset.C;h=5a87a63f8501f03ca1abb569607505252c49957c;hb=12ac7f339e14c4f76a24f45a21c0697303099145;hp=6c4bdf527d6be213bcf45c817f5a7600f679791e;hpb=45d3b8c89c1489b02a744f4bce2aa20d1f64cac6;p=lyx.git diff --git a/src/mathed/math_colorinset.C b/src/mathed/math_colorinset.C index 6c4bdf527d..5a87a63f85 100644 --- a/src/mathed/math_colorinset.C +++ b/src/mathed/math_colorinset.C @@ -16,14 +16,15 @@ #include "math_support.h" #include "LaTeXFeatures.h" +#include "LColor.h" #include "support/std_ostream.h" using std::auto_ptr; -MathColorInset::MathColorInset() - : MathNestInset(2) +MathColorInset::MathColorInset(bool oldstyle) + : MathNestInset(2), oldstyle_(oldstyle) {} @@ -35,31 +36,39 @@ auto_ptr MathColorInset::clone() const void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const { - FontSetChanger dummy(mi.base, "textnormal"); - w_ = mathed_char_width(mi.base.font, '['); - MathNestInset::metrics(mi); - dim_ = cell(0).dim(); - dim_ += cell(1).dim(); - dim_.wid += 2 * w_ + 4; - metricsMarkers(); - dim = dim_; + cell(1).metrics(mi, dim); + if (editing(mi.base.bv)) { + FontSetChanger dummy(mi.base, "textnormal"); + cell(0).metrics(mi); + dim += cell(0).dim(); + w_ = mathed_char_width(mi.base.font, '['); + dim.asc += 4; + dim.des += 4; + dim.wid += 2 * w_ + 4; + metricsMarkers(dim); + } + dim_ = dim; } void MathColorInset::draw(PainterInfo & pi, int x, int y) const { - FontSetChanger dummy(pi.base, "textnormal"); - drawMarkers(pi, x, y); - - drawStrBlack(pi, x, y, "["); - x += w_; - cell(0).draw(pi, x, y); - x += cell(0).width(); - drawStrBlack(pi, x, y, "]"); - x += w_ + 2; - - ColorChanger dummy1(pi.base.font, asString(cell(0))); + if (editing(pi.base.bv)) { + FontSetChanger dummy(pi.base, "textnormal"); + drawMarkers(pi, x, y); + drawStrBlack(pi, x, y, "["); + x += w_; + cell(0).draw(pi, x, y); + x += cell(0).width(); + drawStrBlack(pi, x, y, "]"); + x += w_ + 2; + } + + LColor_color origcol = pi.base.font.color(); + pi.base.font.setColor(lcolor.getFromGUIName(asString(cell(0)))); cell(1).draw(pi, x, y); + pi.base.font.setColor(origcol); + setPosCache(pi, x, y); } @@ -72,7 +81,10 @@ void MathColorInset::validate(LaTeXFeatures & features) const void MathColorInset::write(WriteStream & os) const { - os << "\\color" << '{' << cell(0) << '}' << '{' << cell(1) << '}'; + if (oldstyle_) + os << "{\\color" << '{' << cell(0) << '}' << cell(1) << '}'; + else + os << "\\textcolor" << '{' << cell(0) << "}{" << cell(1) << '}'; }