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