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