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