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