]> git.lyx.org Git - lyx.git/blob - src/mathed/math_symbolinset.C
cosmetics
[lyx.git] / src / mathed / math_symbolinset.C
1 #include <config.h>
2
3 #include "math_symbolinset.h"
4 #include "math_mathmlstream.h"
5 #include "math_streamstr.h"
6 #include "math_support.h"
7 #include "math_parser.h"
8 #include "LaTeXFeatures.h"
9 #include "debug.h"
10
11
12 using std::ostream;
13
14
15 MathSymbolInset::MathSymbolInset(const latexkeys * l)
16         : sym_(l), h_(0)
17 {}
18
19
20 MathSymbolInset::MathSymbolInset(const char * name)
21         : sym_(in_word_set(name)), h_(0)
22 {}
23
24
25 MathSymbolInset::MathSymbolInset(string const & name)
26         : sym_(in_word_set(name.c_str())), h_(0)
27 {}
28
29
30
31 MathInset * MathSymbolInset::clone() const
32 {
33         return new MathSymbolInset(*this);
34 }
35
36
37 string MathSymbolInset::name() const
38 {
39         return sym_->name;
40 }
41
42
43 void MathSymbolInset::metrics(MathMetricsInfo & mi) const
44 {
45         //lyxerr << "metrics: symbol: '" << sym_->name
46         //      << "' in font: '" << sym_->inset
47         //      << "' drawn as: '" << sym_->draw
48         //      << "'\n";
49         MathFontSetChanger dummy(mi.base, sym_->inset.c_str());
50         mathed_string_dim(mi.base.font, sym_->draw, ascent_, descent_, width_);
51         // correct height for broken cmex font
52         if (sym_->inset == "cmex") {
53                 h_ = 4 * descent_ / 5;
54                 ascent_  += h_;
55                 descent_ -= h_;
56         }
57         if (isRelOp())
58                 width_ += 6;
59         // seperate things a bit
60         if (sym_->draw.size() > 1)
61                 width_ += 2;
62
63         scriptable_ = false;
64         if (mi.base.style == LM_ST_DISPLAY)
65                 if (sym_->inset == "cmex" || sym_->extra == "funclim")
66                         scriptable_ = true;
67 }
68
69
70 void MathSymbolInset::draw(MathPainterInfo & pi, int x, int y) const
71 {
72         //lyxerr << "metrics: symbol: '" << sym_->name
73         //      << "' in font: '" << sym_->inset
74         //      << "' drawn as: '" << sym_->draw
75         //      << "'\n";
76         if (isRelOp())
77                 x += 3;
78         if (sym_->draw.size() > 1)
79                 x += 1;
80         MathFontSetChanger dummy(pi.base, sym_->inset.c_str());
81         drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
82 }
83
84
85 bool MathSymbolInset::isRelOp() const
86 {
87         return sym_->extra == "mathrel";
88 }
89
90
91 bool MathSymbolInset::isScriptable() const
92 {
93         return scriptable_;
94 }
95
96
97 bool MathSymbolInset::takesLimits() const
98 {
99         return
100                 sym_->inset == "cmex" ||
101                 sym_->inset == "lyxboldsymb" ||
102                 sym_->extra == "funclim";
103 }
104
105
106 void MathSymbolInset::validate(LaTeXFeatures & features) const
107 {
108         if (sym_->inset == "msa" || sym_->inset == "msb")
109                 features.require("amssymb");
110 }
111
112
113 void MathSymbolInset::normalize(NormalStream & os) const
114 {
115         os << "[symbol " << name() << "]";
116 }
117
118
119 void MathSymbolInset::maplize(MapleStream & os) const
120 {
121         if (name() == "cdot")
122                 os << '*';
123         else if (name() == "infty")
124                 os << "infinity";
125         else
126                 os << name();
127 }
128
129 void MathSymbolInset::mathematicize(MathematicaStream & os) const
130 {
131         if ( name() == "pi")    { os << "Pi"; return;}
132         if ( name() == "infty") { os << "Infinity"; return;}
133         os << name();
134 }
135
136
137 char const * MathMLtype(string const & s)
138 {
139         if (s == "mathop")
140                 return "mo";
141         return "mi";
142 }
143
144
145 bool MathSymbolInset::match(MathInset * p) const
146 {
147         MathSymbolInset const * q = p->asSymbolInset();
148         return q && name() == q->name();
149 }
150
151
152 void MathSymbolInset::mathmlize(MathMLStream & os) const
153 {
154         char const * type = MathMLtype(sym_->extra);
155         os << '<' << type << "> ";
156         if (sym_->xmlname == "x") // unknown so far
157                 os << name();
158         else
159                 os << sym_->xmlname;
160         os << " </" << type << '>';
161 }
162
163
164 void MathSymbolInset::octavize(OctaveStream & os) const
165 {
166         if (name() == "cdot")
167                 os << '*';
168         else
169                 os << name();
170 }
171
172
173 void MathSymbolInset::write(WriteStream & os) const
174 {
175         os << '\\' << name() << ' ';
176 }
177
178
179 void MathSymbolInset::infoize(ostream & os) const
180 {
181         os << "Symbol: " << name();
182 }