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"
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
27 using namespace lyx::support;
31 InsetMathColor::InsetMathColor(Buffer * buf, bool oldstyle, ColorCode color)
32 : InsetMathNest(buf, 1), w_(0), oldstyle_(oldstyle),
33 color_(from_utf8(lcolor.getLaTeXName(color)))
37 InsetMathColor::InsetMathColor(Buffer * buf, bool oldstyle,
38 docstring const & color)
39 : InsetMathNest(buf, 1), w_(0), oldstyle_(oldstyle), color_(color)
43 Inset * InsetMathColor::clone() const
45 return new InsetMathColor(*this);
49 void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
51 cell(0).metrics(mi, dim);
56 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
58 ColorCode origcol = pi.base.font.color();
59 pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_)));
60 cell(0).draw(pi, x + 1, y);
61 pi.base.font.setColor(origcol);
62 drawMarkers(pi, x, y);
63 setPosCache(pi, x, y);
67 /// color "none" (reset to default) needs special treatment
68 static bool normalcolor(docstring const & color)
70 return color == "none";
74 void InsetMathColor::validate(LaTeXFeatures & features) const
76 InsetMathNest::validate(features);
77 if (!normalcolor(color_))
78 features.require("color");
82 void InsetMathColor::write(WriteStream & os) const
84 if (normalcolor(color_))
85 // reset to default color inside another color inset
86 os << "{\\normalcolor " << cell(0) << '}';
88 os << "{\\color{" << color_ << '}' << cell(0) << '}';
90 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
94 void InsetMathColor::normalize(NormalStream & os) const
96 os << "[color " << color_ << ' ' << cell(0) << ']';
100 void InsetMathColor::infoize(odocstream & os) const
102 os << bformat(_("Color: %1$s"), color_);