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