]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSymbol.C
make it compile again (hopefully)
[lyx.git] / src / mathed / InsetMathSymbol.C
1 /**
2  * \file InsetMathSymbol.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathSymbol.h"
14 #include "dimension.h"
15 #include "MathMLStream.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
18 #include "MathParser.h"
19 #include "MathAtom.h"
20 #include "LaTeXFeatures.h"
21 #include "debug.h"
22
23 using lyx::docstring;
24
25 using std::string;
26 using std::auto_ptr;
27
28
29 InsetMathSymbol::InsetMathSymbol(latexkeys const * l)
30         : sym_(l), h_(0), width_(0), scriptable_(false)
31 {}
32
33
34 InsetMathSymbol::InsetMathSymbol(char const * name)
35         : sym_(in_word_set(name)), h_(0), width_(0), scriptable_(false)
36 {}
37
38
39 InsetMathSymbol::InsetMathSymbol(string const & name)
40         : sym_(in_word_set(name.c_str())), h_(0), width_(0), scriptable_(false)
41 {}
42
43
44 auto_ptr<InsetBase> InsetMathSymbol::doClone() const
45 {
46         return auto_ptr<InsetBase>(new InsetMathSymbol(*this));
47 }
48
49
50 string InsetMathSymbol::name() const
51 {
52         return sym_->name;
53 }
54
55
56 void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
57 {
58         //lyxerr << "metrics: symbol: '" << sym_->name
59         //      << "' in font: '" << sym_->inset
60         //      << "' drawn as: '" << sym_->draw
61         //      << "'" << std::endl;
62
63         int const em = mathed_char_width(mi.base.font, 'M');
64         FontSetChanger dummy(mi.base, sym_->inset.c_str());
65         // FIXME UNICODE
66         mathed_string_dim(mi.base.font, lyx::from_utf8(sym_->draw), dim);
67         // correct height for broken cmex and wasy font
68 #if defined(__APPLE__) && defined(__GNUC__)
69         if (sym_->inset == "cmex") {
70                 h_ = 4 * dim.des / 5;
71                 dim.asc += 0*h_;
72                 dim.des -= h_;
73                 h_ = dim.asc;
74         } else if (sym_->inset == "wasy") {
75                 h_ = 4 * dim.des / 5;
76                 dim.asc += h_;
77                 dim.des -= h_;
78         }
79 #else
80         if (sym_->inset == "cmex" || sym_->inset == "wasy") {
81                 h_ = 4 * dim.des / 5;
82                 dim.asc += h_;
83                 dim.des -= h_;
84         }
85 #endif
86         // seperate things a bit
87         if (isRelOp())
88                 dim.wid += static_cast<int>(0.5 * em + 0.5);
89         else
90                 dim.wid += static_cast<int>(0.1667 * em + 0.5);
91
92         scriptable_ = false;
93         if (mi.base.style == LM_ST_DISPLAY)
94                 if (sym_->inset == "cmex" || sym_->extra == "funclim")
95                         scriptable_ = true;
96
97         width_ = dim.wid;
98 }
99
100
101 void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
102 {
103         //lyxerr << "metrics: symbol: '" << sym_->name
104         //      << "' in font: '" << sym_->inset
105         //      << "' drawn as: '" << sym_->draw
106         //      << "'" << std::endl;
107         int const em = mathed_char_width(pi.base.font, 'M');
108         if (isRelOp())
109                 x += static_cast<int>(0.25*em+0.5);
110         else
111                 x += static_cast<int>(0.0833*em+0.5);
112
113         FontSetChanger dummy(pi.base, sym_->inset.c_str());
114         // FIXME UNICODE
115         pi.draw(x, y - h_, lyx::from_utf8(sym_->draw));
116 }
117
118
119 bool InsetMathSymbol::isRelOp() const
120 {
121         return sym_->extra == "mathrel";
122 }
123
124
125 bool InsetMathSymbol::isScriptable() const
126 {
127         return scriptable_;
128 }
129
130
131 bool InsetMathSymbol::takesLimits() const
132 {
133         return
134                 sym_->inset == "cmex" ||
135                 sym_->inset == "lyxboldsymb" ||
136                 sym_->extra == "funclim";
137 }
138
139
140 void InsetMathSymbol::validate(LaTeXFeatures & features) const
141 {
142         if (!sym_->requires.empty())
143                 features.require(sym_->requires);
144 }
145
146
147 void InsetMathSymbol::normalize(NormalStream & os) const
148 {
149         os << "[symbol " << name() << ']';
150 }
151
152
153 void InsetMathSymbol::maple(MapleStream & os) const
154 {
155         if (name() == "cdot")
156                 os << '*';
157         else if (name() == "infty")
158                 os << "infinity";
159         else
160                 os << name();
161 }
162
163 void InsetMathSymbol::maxima(MaximaStream & os) const
164 {
165         if (name() == "cdot")
166                 os << '*';
167         else if (name() == "infty")
168                 os << "inf";
169         else if (name() == "pi")
170                 os << "%pi";
171         else
172                 os << name();
173 }
174
175
176 void InsetMathSymbol::mathematica(MathematicaStream & os) const
177 {
178         if ( name() == "pi")    { os << "Pi"; return;}
179         if ( name() == "infty") { os << "Infinity"; return;}
180         if ( name() == "cdot")  { os << '*'; return;}
181         os << name();
182 }
183
184
185 char const * MathMLtype(string const & s)
186 {
187         if (s == "mathop")
188                 return "mo";
189         return "mi";
190 }
191
192
193 void InsetMathSymbol::mathmlize(MathMLStream & os) const
194 {
195         char const * type = MathMLtype(sym_->extra);
196         os << '<' << type << "> ";
197         if (sym_->xmlname == "x") // unknown so far
198                 os << name();
199         else
200                 os << sym_->xmlname;
201         os << " </" << type << '>';
202 }
203
204
205 void InsetMathSymbol::octave(OctaveStream & os) const
206 {
207         if (name() == "cdot")
208                 os << '*';
209         else
210                 os << name();
211 }
212
213
214 void InsetMathSymbol::write(WriteStream & os) const
215 {
216         os << '\\' << name();
217         os.pendingSpace(true);
218 }
219
220
221 void InsetMathSymbol::infoize2(std::ostream & os) const
222 {
223         os << "Symbol: " << name();
224 }