]> git.lyx.org Git - lyx.git/blob - src/mathed/math_symbolinset.C
more 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, dim_);
51         // correct height for broken cmex and wasy font
52         if (sym_->inset == "cmex" || sym_->inset == "wasy") {
53                 h_ = 4 * dim_.d / 5;
54                 dim_.a += h_;
55                 dim_.d -= h_;
56         }
57         if (isRelOp())
58                 dim_.w += 6;
59         // seperate things a bit
60         dim_.w += 2;
61
62         scriptable_ = false;
63         if (mi.base.style == LM_ST_DISPLAY)
64                 if (sym_->inset == "cmex" || sym_->extra == "funclim")
65                         scriptable_ = true;
66 }
67
68
69 void MathSymbolInset::draw(MathPainterInfo & pi, int x, int y) const
70 {
71         //lyxerr << "metrics: symbol: '" << sym_->name
72         //      << "' in font: '" << sym_->inset
73         //      << "' drawn as: '" << sym_->draw
74         //      << "'\n";
75         if (isRelOp())
76                 x += 3;
77         x += 1;
78         MathFontSetChanger dummy(pi.base, sym_->inset.c_str());
79         drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
80 }
81
82
83 bool MathSymbolInset::isRelOp() const
84 {
85         return sym_->extra == "mathrel";
86 }
87
88
89 bool MathSymbolInset::isScriptable() const
90 {
91         return scriptable_;
92 }
93
94
95 bool MathSymbolInset::takesLimits() const
96 {
97         return
98                 sym_->inset == "cmex" ||
99                 sym_->inset == "lyxboldsymb" ||
100                 sym_->extra == "funclim";
101 }
102
103
104 void MathSymbolInset::validate(LaTeXFeatures & features) const
105 {
106         if (sym_->inset == "msa" || sym_->inset == "msb")
107                 features.require("amssymb");
108 }
109
110
111 void MathSymbolInset::normalize(NormalStream & os) const
112 {
113         os << "[symbol " << name() << "]";
114 }
115
116
117 void MathSymbolInset::maplize(MapleStream & os) const
118 {
119         if (name() == "cdot")
120                 os << '*';
121         else if (name() == "infty")
122                 os << "infinity";
123         else
124                 os << name();
125 }
126
127 void MathSymbolInset::mathematicize(MathematicaStream & os) const
128 {
129         if ( name() == "pi")    { os << "Pi"; return;}
130         if ( name() == "infty") { os << "Infinity"; return;}
131         os << name();
132 }
133
134
135 char const * MathMLtype(string const & s)
136 {
137         if (s == "mathop")
138                 return "mo";
139         return "mi";
140 }
141
142
143 bool MathSymbolInset::match(MathAtom const & at) const
144 {
145         MathSymbolInset const * q = at->asSymbolInset();
146         return q && name() == q->name();
147 }
148
149
150 void MathSymbolInset::mathmlize(MathMLStream & os) const
151 {
152         char const * type = MathMLtype(sym_->extra);
153         os << '<' << type << "> ";
154         if (sym_->xmlname == "x") // unknown so far
155                 os << name();
156         else
157                 os << sym_->xmlname;
158         os << " </" << type << '>';
159 }
160
161
162 void MathSymbolInset::octavize(OctaveStream & os) const
163 {
164         if (name() == "cdot")
165                 os << '*';
166         else
167                 os << name();
168 }
169
170
171 void MathSymbolInset::write(WriteStream & os) const
172 {
173         os << '\\' << name() << ' ';
174 }
175
176
177 void MathSymbolInset::infoize(ostream & os) const
178 {
179         os << "Symbol: " << name();
180 }