]> git.lyx.org Git - lyx.git/blob - src/mathed/math_colorinset.C
support for color in math
[lyx.git] / src / mathed / math_colorinset.C
1 /**
2  * \file math_colorinset.C
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 "math_colorinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "math_support.h"
17
18 #include "LaTeXFeatures.h"
19
20 #include "support/std_ostream.h"
21
22 using std::auto_ptr;
23
24
25 MathColorInset::MathColorInset()
26         : MathNestInset(2)
27 {}
28
29
30 auto_ptr<InsetBase> MathColorInset::clone() const
31 {
32         return auto_ptr<InsetBase>(new MathColorInset(*this));
33 }
34
35
36 void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
37 {
38         FontSetChanger dummy(mi.base, "textnormal");
39         w_ = mathed_char_width(mi.base.font, '[');
40         MathNestInset::metrics(mi);
41         dim_   = cell(0).dim();
42         dim_  += cell(1).dim();
43         dim_.wid += 2 * w_ + 4;
44         metricsMarkers();
45         dim = dim_;
46 }
47
48
49 void MathColorInset::draw(PainterInfo & pi, int x, int y) const
50 {
51         FontSetChanger dummy(pi.base, "textnormal");
52         drawMarkers(pi, x, y);
53
54         drawStrBlack(pi, x, y, "[");
55         x += w_;
56         cell(0).draw(pi, x, y);
57         x += cell(0).width();
58         drawStrBlack(pi, x, y, "]");
59         x += w_ + 2;
60
61         ColorChanger dummy1(pi.base.font, asString(cell(0)));
62         cell(1).draw(pi, x, y);
63 }
64
65
66 void MathColorInset::validate(LaTeXFeatures & features) const
67 {
68         MathNestInset::validate(features);
69         features.require("color");
70 }
71
72
73 void MathColorInset::write(WriteStream & os) const
74 {
75         os << "\\color" << '{' << cell(0) << '}' << '{' << cell(1) << '}';
76 }
77
78
79 void MathColorInset::normalize(NormalStream & os) const
80 {
81         os << "[color " << cell(0) << ' ' << cell(1) << ']';
82 }
83
84
85 void MathColorInset::infoize(std::ostream & os) const
86 {
87         os << "Color: " << cell(0);
88 }