]> git.lyx.org Git - lyx.git/blob - src/mathed/math_symbolinset.C
more trivial tweaks to mathed bindings
[lyx.git] / src / mathed / math_symbolinset.C
1
2 #ifdef __GNUG__
3 #pragma implementation 
4 #endif
5
6 #include <config.h>
7
8 #include "math_symbolinset.h"
9 #include "math_mathmlstream.h"
10 #include "math_streamstr.h"
11 #include "math_support.h"
12 #include "math_parser.h"
13 #include "LaTeXFeatures.h"
14 #include "debug.h"
15
16
17 MathSymbolInset::MathSymbolInset(const latexkeys * l)
18         : sym_(l), h_(0)
19 {}
20
21
22 MathSymbolInset::MathSymbolInset(const char * name)
23         : sym_(in_word_set(name)), h_(0)
24 {}
25
26
27 MathSymbolInset::MathSymbolInset(string const & name)
28         : sym_(in_word_set(name.c_str())), h_(0)
29 {}
30
31
32
33 MathInset * MathSymbolInset::clone() const
34 {
35         return new MathSymbolInset(*this);
36 }
37
38
39 string MathSymbolInset::name() const
40 {
41         return sym_->name;
42 }
43
44
45 void MathSymbolInset::metrics(MathMetricsInfo & mi) const
46 {
47         //lyxerr << "metrics: symbol: '" << sym_->name
48         //      << "' in font: '" << sym_->inset
49         //      << "' drawn as: '" << sym_->draw
50         //      << "'\n";
51         MathFontSetChanger dummy(mi.base, sym_->inset.c_str());
52         mathed_string_dim(mi.base.font, sym_->draw, dim_);
53         // correct height for broken cmex and wasy font
54         if (sym_->inset == "cmex" || sym_->inset == "wasy") {
55                 h_ = 4 * dim_.d / 5;
56                 dim_.a += h_;
57                 dim_.d -= h_;
58         }
59         if (isRelOp())
60                 dim_.w += 6;
61         // seperate things a bit
62         dim_.w += 2;
63
64         scriptable_ = false;
65         if (mi.base.style == LM_ST_DISPLAY)
66                 if (sym_->inset == "cmex" || sym_->extra == "funclim")
67                         scriptable_ = true;
68 }
69
70
71 void MathSymbolInset::draw(MathPainterInfo & pi, int x, int y) const
72 {
73         //lyxerr << "metrics: symbol: '" << sym_->name
74         //      << "' in font: '" << sym_->inset
75         //      << "' drawn as: '" << sym_->draw
76         //      << "'\n";
77         if (isRelOp())
78                 x += 3;
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(MathAtom const & at) const
146 {
147         MathSymbolInset const * q = at->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         os.pendingSpace(true);
177 }
178
179
180 void MathSymbolInset::infoize(std::ostream & os) const
181 {
182         os << "Symbol: " << name();
183 }