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