]> git.lyx.org Git - lyx.git/blob - src/mathed/math_stringinset.C
oh well
[lyx.git] / src / mathed / math_stringinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_stringinset.h"
8 #include "math_mathmlstream.h"
9 #include "math_streamstr.h"
10 #include "LColor.h"
11 #include "Painter.h"
12 #include "math_support.h"
13 #include "math_parser.h"
14 #include "LaTeXFeatures.h"
15 #include "debug.h"
16
17 #include <cctype>
18
19
20 MathStringInset::MathStringInset()
21         : str_(), code_(LM_TC_MIN)
22 {}
23
24 MathStringInset::MathStringInset(string const & s, MathTextCodes t)
25         : str_(s), code_(t)
26 {}
27
28
29 MathInset * MathStringInset::clone() const
30 {
31         return new MathStringInset(*this);
32 }
33
34
35 int MathStringInset::ascent() const
36 {
37         return mathed_string_ascent(font_, str_);
38 }
39
40
41 int MathStringInset::descent() const
42 {
43         return mathed_string_descent(font_, str_);
44 }
45
46
47 int MathStringInset::width() const
48 {
49         return mathed_string_width(font_, str_);
50 }
51
52
53 void MathStringInset::validate(LaTeXFeatures & features) const
54 {
55         //lyxerr << "stringinset amssymb" << endl;
56         if (code_ == LM_TC_MSA || code_ == LM_TC_MSB)
57                 features.require("amssymb");
58 }
59
60
61 void MathStringInset::metrics(MathMetricsInfo const & mi) const
62 {
63         whichFont(font_, code_, mi);
64 }
65
66
67 void MathStringInset::draw(Painter & pain, int x, int y) const
68 {
69         //lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
70         drawStr(pain, font_, x, y, str_);
71 }
72
73
74 void MathStringInset::normalize(NormalStream & os) const
75 {
76         os << "[string " << str_ << ' ' << "mathalpha" << "]";
77 }
78
79
80 void MathStringInset::maplize(MapleStream & os) const
81 {
82         if (code_ != LM_TC_VAR || str_.size() <= 1) {
83                 os << ' ' << str_ << ' ';
84                 return;
85         }
86
87         // insert '*' between adjacent chars if type is LM_TC_VAR
88         os << str_[0];
89         for (string::size_type i = 1; i < str_.size(); ++i)
90                 os << '*' << str_[i];
91 }
92
93
94 void MathStringInset::octavize(OctaveStream & os) const
95 {
96         if (code_ != LM_TC_VAR || str_.size() <= 1) {
97                 os << ' ' << str_ << ' ';
98                 return;
99         }
100
101         // insert '*' between adjacent chars if type is LM_TC_VAR
102         os << str_[0];
103         for (string::size_type i = 1; i < str_.size(); ++i)
104                 os << '*' << str_[i];
105 }
106
107
108 void MathStringInset::mathmlize(MathMLStream & os) const
109 {
110         if (code_ == LM_TC_VAR)
111                 os << "<mi> " << str_ << " </mi>";
112         else if (code_ == LM_TC_CONST)
113                 os << "<mn> " << str_ << " </mn>";
114         else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM)
115                 os << "<mtext> " << str_ <<  " </mtext>";
116         else
117                 os << str_;
118 }
119
120
121 void MathStringInset::write(WriteStream & os) const
122 {
123         if (math_font_name(code_))
124                 os << '\\' << math_font_name(code_) << '{' << str_ << '}';
125         else
126                 os << str_;
127 }