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