]> git.lyx.org Git - lyx.git/blob - src/mathed/math_symbolinset.C
several smallish changes/bugfixes/left overs from Porto
[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 if (name() == "infty")
119                 os << "infinity";
120         else
121                 os << name();
122 }
123
124
125 char const * MathMLtype(string const & s)
126 {
127         if (s == "mathop")
128                 return "mo";
129         return "mi";
130 }
131
132
133 bool MathSymbolInset::match(MathInset * p) const
134 {
135         MathSymbolInset const * q = p->asSymbolInset();
136         return q && name() == q->name();
137 }
138
139
140 void MathSymbolInset::mathmlize(MathMLStream & os) const
141 {
142         char const * type = MathMLtype(sym_->extra);
143         os << '<' << type << "> ";
144         if (sym_->xmlname == "x") // unknown so far
145                 os << name();
146         else
147                 os << sym_->xmlname;
148         os << " </" << type << '>';
149 }
150
151
152 void MathSymbolInset::octavize(OctaveStream & os) const
153 {
154         if (name() == "cdot")
155                 os << '*';
156         else
157                 os << name();
158 }
159
160
161 void MathSymbolInset::write(WriteStream & os) const
162 {
163         os << '\\' << name() << ' ';
164 }
165
166
167 void MathSymbolInset::infoize(ostream & os) const
168 {
169         os << '\\' << name();
170 }