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