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"
25 InsetMathColor::InsetMathColor(bool oldstyle, ColorCode color)
26 : InsetMathNest(1), oldstyle_(oldstyle),
27 color_(from_utf8(lcolor.getLaTeXName(color)))
31 InsetMathColor::InsetMathColor(bool oldstyle, docstring const & color)
32 : InsetMathNest(1), oldstyle_(oldstyle), color_(color)
36 Inset * InsetMathColor::clone() const
38 return new InsetMathColor(*this);
42 void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
44 cell(0).metrics(mi, dim);
49 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
51 ColorCode origcol = pi.base.font.color();
52 pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_)));
53 cell(0).draw(pi, x + 1, y);
54 pi.base.font.setColor(origcol);
55 drawMarkers(pi, x, y);
56 setPosCache(pi, x, y);
60 /// color "none" (reset to default) needs special treatment
61 static bool normalcolor(docstring const & color)
63 return color == "none";
67 void InsetMathColor::validate(LaTeXFeatures & features) const
69 InsetMathNest::validate(features);
70 if (!normalcolor(color_))
71 features.require("color");
75 void InsetMathColor::write(WriteStream & os) const
77 if (normalcolor(color_))
78 // reset to default color inside another color inset
79 os << "{\\normalcolor " << cell(0) << '}';
81 os << "{\\color{" << color_ << '}' << cell(0) << '}';
83 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
87 void InsetMathColor::normalize(NormalStream & os) const
89 os << "[color " << color_ << ' ' << cell(0) << ']';
93 void InsetMathColor::infoize(odocstream & os) const
95 os << "Color: " << color_;