2 * \file InsetMathColor.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 "InsetMathColor.h"
15 #include "MathMLStream.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
19 #include "LaTeXFeatures.h"
21 #include "support/std_ostream.h"
29 /// color "none" (reset to default) needs special treatment
30 bool normalcolor(string const & color)
32 return color == "none";
38 InsetMathColor::InsetMathColor(bool oldstyle, LColor_color const & color)
39 : InsetMathNest(1), oldstyle_(oldstyle),
40 color_(lcolor.getLaTeXName(color))
44 InsetMathColor::InsetMathColor(bool oldstyle, string const & color)
45 : InsetMathNest(1), oldstyle_(oldstyle), color_(color)
49 auto_ptr<InsetBase> InsetMathColor::doClone() const
51 return auto_ptr<InsetBase>(new InsetMathColor(*this));
55 void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
57 cell(0).metrics(mi, dim);
63 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
65 LColor_color origcol = pi.base.font.color();
66 pi.base.font.setColor(lcolor.getFromLaTeXName(color_));
67 cell(0).draw(pi, x + 1, y);
68 pi.base.font.setColor(origcol);
69 drawMarkers(pi, x, y);
70 setPosCache(pi, x, y);
74 void InsetMathColor::validate(LaTeXFeatures & features) const
76 InsetMathNest::validate(features);
77 if (!normalcolor(color_))
78 features.require("color");
82 void InsetMathColor::write(WriteStream & os) const
84 if (normalcolor(color_))
85 // reset to default color inside another color inset
86 os << "{\\normalcolor " << cell(0) << '}';
88 os << "{\\color" << '{' << color_ << '}' << cell(0) << '}';
90 os << "\\textcolor" << '{' << color_ << "}{" << cell(0) << '}';
94 void InsetMathColor::normalize(NormalStream & os) const
96 os << "[color " << color_ << ' ' << cell(0) << ']';
100 void InsetMathColor::infoize(std::ostream & os) const
102 os << "Color: " << color_;