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