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