2 * \file InsetMathColor.cpp
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 "MathStream.h"
16 #include "MathSupport.h"
17 #include "LaTeXFeatures.h"
19 #include "support/std_ostream.h"
27 InsetMathColor::InsetMathColor(bool oldstyle, Color_color const & color)
28 : InsetMathNest(1), oldstyle_(oldstyle),
29 color_(from_utf8(lcolor.getLaTeXName(color)))
33 InsetMathColor::InsetMathColor(bool oldstyle, docstring const & color)
34 : InsetMathNest(1), oldstyle_(oldstyle), color_(color)
38 auto_ptr<Inset> InsetMathColor::doClone() const
40 return auto_ptr<Inset>(new InsetMathColor(*this));
44 bool InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
46 cell(0).metrics(mi, dim);
55 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
57 Color_color origcol = pi.base.font.color();
58 pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_)));
59 cell(0).draw(pi, x + 1, y);
60 pi.base.font.setColor(origcol);
61 drawMarkers(pi, x, y);
62 setPosCache(pi, x, y);
66 /// color "none" (reset to default) needs special treatment
67 static bool normalcolor(docstring const & color)
69 return color == "none";
73 void InsetMathColor::validate(LaTeXFeatures & features) const
75 InsetMathNest::validate(features);
76 if (!normalcolor(color_))
77 features.require("color");
81 void InsetMathColor::write(WriteStream & os) const
83 if (normalcolor(color_))
84 // reset to default color inside another color inset
85 os << "{\\normalcolor " << cell(0) << '}';
87 os << "{\\color{" << color_ << '}' << cell(0) << '}';
89 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
93 void InsetMathColor::normalize(NormalStream & os) const
95 os << "[color " << color_ << ' ' << cell(0) << ']';
99 void InsetMathColor::infoize(odocstream & os) const
101 os << "Color: " << color_;