2 * \file math_colorinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "math_colorinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "math_support.h"
18 #include "LaTeXFeatures.h"
21 #include "support/std_ostream.h"
28 // color "none" (reset to default) needs special treatment
29 bool normalcolor(MathArray const & ar)
31 return (asString(ar) == "none");
37 MathColorInset::MathColorInset(bool oldstyle)
38 : MathNestInset(2), oldstyle_(oldstyle)
42 auto_ptr<InsetBase> MathColorInset::doClone() const
44 return auto_ptr<InsetBase>(new MathColorInset(*this));
48 void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
50 cell(1).metrics(mi, dim);
51 if (editing(mi.base.bv)) {
52 FontSetChanger dummy(mi.base, "textnormal");
55 w_ = mathed_char_width(mi.base.font, '[');
58 dim.wid += 2 * w_ + 4;
65 void MathColorInset::draw(PainterInfo & pi, int x, int y) const
68 if (editing(pi.base.bv)) {
69 FontSetChanger dummy(pi.base, "textnormal");
70 drawMarkers(pi, x, y);
71 drawStrBlack(pi, x, y, "[");
73 cell(0).draw(pi, x, y);
75 drawStrBlack(pi, x, y, "]");
79 LColor_color origcol = pi.base.font.color();
80 pi.base.font.setColor(lcolor.getFromGUIName(asString(cell(0))));
81 cell(1).draw(pi, x, y);
82 pi.base.font.setColor(origcol);
83 if (editing(pi.base.bv))
84 setPosCache(pi, x0, y);
88 void MathColorInset::validate(LaTeXFeatures & features) const
90 MathNestInset::validate(features);
91 if (!normalcolor(cell(0)))
92 features.require("color");
96 void MathColorInset::write(WriteStream & os) const
98 if (normalcolor(cell(0)))
99 os << "{\\normalcolor " << cell(1) << '}';
101 os << "{\\color" << '{' << cell(0) << '}' << cell(1) << '}';
103 os << "\\textcolor" << '{' << cell(0) << "}{" << cell(1) << '}';
107 void MathColorInset::normalize(NormalStream & os) const
109 os << "[color " << cell(0) << ' ' << cell(1) << ']';
113 void MathColorInset::infoize(std::ostream & os) const
115 os << "Color: " << cell(0);