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.
15 #include "InsetMathColor.h"
16 #include "LaTeXFeatures.h"
18 #include "MathStream.h"
19 #include "MathSupport.h"
20 #include "MetricsInfo.h"
27 InsetMathColor::InsetMathColor(bool oldstyle, ColorCode 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 Inset * InsetMathColor::clone() const
40 return new InsetMathColor(*this);
44 void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
46 cell(0).metrics(mi, dim);
51 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
53 ColorCode origcol = pi.base.font.color();
54 pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_)));
55 cell(0).draw(pi, x + 1, y);
56 pi.base.font.setColor(origcol);
57 drawMarkers(pi, x, y);
58 setPosCache(pi, x, y);
62 /// color "none" (reset to default) needs special treatment
63 static bool normalcolor(docstring const & color)
65 return color == "none";
69 void InsetMathColor::validate(LaTeXFeatures & features) const
71 InsetMathNest::validate(features);
72 if (!normalcolor(color_))
73 features.require("color");
77 void InsetMathColor::write(WriteStream & os) const
79 if (normalcolor(color_))
80 // reset to default color inside another color inset
81 os << "{\\normalcolor " << cell(0) << '}';
83 os << "{\\color{" << color_ << '}' << cell(0) << '}';
85 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
89 void InsetMathColor::normalize(NormalStream & os) const
91 os << "[color " << color_ << ' ' << cell(0) << ']';
95 void InsetMathColor::infoize(odocstream & os) const
97 os << "Color: " << color_;