]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathColor.cpp
Move Color::color enum to ColorCode.h
[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 "Color.h"
14 #include "InsetMathColor.h"
15 #include "MathData.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
18 #include "LaTeXFeatures.h"
19
20 #include "support/std_ostream.h"
21
22
23 namespace lyx {
24
25 InsetMathColor::InsetMathColor(bool oldstyle, ColorCode color)
26         : InsetMathNest(1), oldstyle_(oldstyle),
27           color_(from_utf8(lcolor.getLaTeXName(color)))
28 {}
29
30
31 InsetMathColor::InsetMathColor(bool oldstyle, docstring const & color)
32         : InsetMathNest(1), oldstyle_(oldstyle), color_(color)
33 {}
34
35
36 Inset * InsetMathColor::clone() const
37 {
38         return new InsetMathColor(*this);
39 }
40
41
42 void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
43 {
44         cell(0).metrics(mi, dim);
45         metricsMarkers(dim);
46         // Cache the inset dimension. 
47         setDimCache(mi, dim);
48 }
49
50
51 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
52 {
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);
59 }
60
61
62 /// color "none" (reset to default) needs special treatment
63 static bool normalcolor(docstring const & color)
64 {
65         return color == "none";
66 }
67
68
69 void InsetMathColor::validate(LaTeXFeatures & features) const
70 {
71         InsetMathNest::validate(features);
72         if (!normalcolor(color_))
73                 features.require("color");
74 }
75
76
77 void InsetMathColor::write(WriteStream & os) const
78 {
79         if (normalcolor(color_))
80                 // reset to default color inside another color inset
81                 os << "{\\normalcolor " << cell(0) << '}';
82         else if (oldstyle_)
83                 os << "{\\color{" << color_ << '}' << cell(0) << '}';
84         else
85                 os << "\\textcolor{" << color_ << "}{" << cell(0) << '}';
86 }
87
88
89 void InsetMathColor::normalize(NormalStream & os) const
90 {
91         os << "[color " << color_ << ' ' << cell(0) << ']';
92 }
93
94
95 void InsetMathColor::infoize(odocstream & os) const
96 {
97         os << "Color: " << color_;
98 }
99
100
101 } // namespace lyx