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
67 if (editing(pi.base.bv)) {
68 FontSetChanger dummy(pi.base, "textnormal");
69 drawMarkers(pi, x, y);
70 drawStrBlack(pi, x, y, "[");
72 cell(0).draw(pi, x, y);
74 drawStrBlack(pi, x, y, "]");
78 LColor_color origcol = pi.base.font.color();
79 pi.base.font.setColor(lcolor.getFromGUIName(asString(cell(0))));
80 cell(1).draw(pi, x, y);
81 pi.base.font.setColor(origcol);
82 setPosCache(pi, x, y);
86 void MathColorInset::validate(LaTeXFeatures & features) const
88 MathNestInset::validate(features);
89 if (!normalcolor(cell(0)))
90 features.require("color");
94 void MathColorInset::write(WriteStream & os) const
96 if (normalcolor(cell(0)))
97 os << "{\\normalcolor " << cell(1) << '}';
99 os << "{\\color" << '{' << cell(0) << '}' << cell(1) << '}';
101 os << "\\textcolor" << '{' << cell(0) << "}{" << cell(1) << '}';
105 void MathColorInset::normalize(NormalStream & os) const
107 os << "[color " << cell(0) << ' ' << cell(1) << ']';
111 void MathColorInset::infoize(std::ostream & os) const
113 os << "Color: " << cell(0);