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"
24 InsetMathColor::InsetMathColor(bool oldstyle, Color_color const & color)
25 : InsetMathNest(1), oldstyle_(oldstyle),
26 color_(from_utf8(lcolor.getLaTeXName(color)))
30 InsetMathColor::InsetMathColor(bool oldstyle, docstring const & color)
31 : InsetMathNest(1), oldstyle_(oldstyle), color_(color)
35 Inset * InsetMathColor::clone() const
37 return new InsetMathColor(*this);
41 bool InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
43 cell(0).metrics(mi, dim);
52 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
54 Color_color origcol = pi.base.font.color();
55 pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_)));
56 cell(0).draw(pi, x + 1, y);
57 pi.base.font.setColor(origcol);
58 drawMarkers(pi, x, y);
59 setPosCache(pi, x, y);
63 /// color "none" (reset to default) needs special treatment
64 static bool normalcolor(docstring const & color)
66 return color == "none";
70 void InsetMathColor::validate(LaTeXFeatures & features) const
72 InsetMathNest::validate(features);
73 if (!normalcolor(color_))
74 features.require("color");
78 void InsetMathColor::write(WriteStream & os) const
80 if (normalcolor(color_))
81 // reset to default color inside another color inset
82 os << "{\\normalcolor " << cell(0) << '}';
84 os << "{\\color{" << color_ << '}' << cell(0) << '}';
86 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
90 void InsetMathColor::normalize(NormalStream & os) const
92 os << "[color " << color_ << ' ' << cell(0) << ']';
96 void InsetMathColor::infoize(odocstream & os) const
98 os << "Color: " << color_;