]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathColor.cpp
Cmake build: Adapt to compile after 0213e7b5c62f487bdddd95ff0b2de736f64b1dc3
[lyx.git] / src / mathed / InsetMathColor.cpp
1 /**
2  * \file InsetMathColor.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ColorSet.h"
14
15 #include "InsetMathColor.h"
16 #include "LaTeXFeatures.h"
17 #include "MathData.h"
18 #include "MathStream.h"
19 #include "MathSupport.h"
20 #include "MetricsInfo.h"
21
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
24
25 #include <ostream>
26
27 using namespace lyx::support;
28
29 namespace lyx {
30
31 InsetMathColor::InsetMathColor(Buffer * buf, bool oldstyle, ColorCode color)
32         : InsetMathNest(buf, 1), oldstyle_(oldstyle),
33           color_(from_utf8(lcolor.getLaTeXName(color)))
34 {}
35
36
37 InsetMathColor::InsetMathColor(Buffer * buf, bool oldstyle,
38                 docstring const & color)
39         : InsetMathNest(buf, 1), oldstyle_(oldstyle), color_(color)
40 {}
41
42
43 Inset * InsetMathColor::clone() const
44 {
45         return new InsetMathColor(*this);
46 }
47
48
49 void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
50 {
51         cell(0).metrics(mi, dim);
52         metricsMarkers(dim);
53 }
54
55
56 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
57 {
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);
64 }
65
66
67 /// color "none" (reset to default) needs special treatment
68 static bool normalcolor(docstring const & color)
69 {
70         return color == "none";
71 }
72
73
74 void InsetMathColor::validate(LaTeXFeatures & features) const
75 {
76         InsetMathNest::validate(features);
77         if (!normalcolor(color_))
78                 features.require("color");
79 }
80
81
82 void InsetMathColor::write(WriteStream & os) const
83 {
84         if (normalcolor(color_))
85                 // reset to default color inside another color inset
86                 os << "{\\normalcolor " << cell(0) << '}';
87         else if (oldstyle_)
88                 os << "{\\color{" << color_ << '}' << cell(0) << '}';
89         else
90                 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
91 }
92
93
94 void InsetMathColor::normalize(NormalStream & os) const
95 {
96         os << "[color " << color_ << ' ' << cell(0) << ']';
97 }
98
99
100 void InsetMathColor::infoize(odocstream & os) const
101 {
102         os << bformat(_("Color: %1$s"), color_);
103 }
104
105
106 } // namespace lyx