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);
48 // Cache the inset dimension.
53 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
55 ColorCode origcol = pi.base.font.color();
56 pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_)));
57 cell(0).draw(pi, x + 1, y);
58 pi.base.font.setColor(origcol);
59 drawMarkers(pi, x, y);
60 setPosCache(pi, x, y);
64 /// color "none" (reset to default) needs special treatment
65 static bool normalcolor(docstring const & color)
67 return color == "none";
71 void InsetMathColor::validate(LaTeXFeatures & features) const
73 InsetMathNest::validate(features);
74 if (!normalcolor(color_))
75 features.require("color");
79 void InsetMathColor::write(WriteStream & os) const
81 if (normalcolor(color_))
82 // reset to default color inside another color inset
83 os << "{\\normalcolor " << cell(0) << '}';
85 os << "{\\color{" << color_ << '}' << cell(0) << '}';
87 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
91 void InsetMathColor::normalize(NormalStream & os) const
93 os << "[color " << color_ << ' ' << cell(0) << ']';
97 void InsetMathColor::infoize(odocstream & os) const
99 os << "Color: " << color_;