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