]> git.lyx.org Git - lyx.git/blob - src/mathed/math_stringinset.C
*** empty log message ***
[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::normalize(NormalStream & os) const
63 {
64         os << "[string " << str_.c_str() << ' ' << "mathalpha" << "]";
65 }
66
67
68 void MathStringInset::maplize(MapleStream & os) const
69 {
70         if (code_ != LM_TC_VAR || str_.size() <= 1) {
71                 os << ' ' << str_.c_str() << ' ';
72                 return;
73         }       
74
75         // insert '*' between adjacent chars if type is LM_TC_VAR
76         os << str_[0];
77         for (string::size_type i = 1; i < str_.size(); ++i) 
78                 os << '*' << str_[i];
79 }
80
81
82 void MathStringInset::octavize(OctaveStream & os) const
83 {
84         if (code_ != LM_TC_VAR || str_.size() <= 1) {
85                 os << ' ' << str_.c_str() << ' ';
86                 return;
87         }       
88
89         // insert '*' between adjacent chars if type is LM_TC_VAR
90         os << str_[0];
91         for (string::size_type i = 1; i < str_.size(); ++i) 
92                 os << '*' << str_[i];
93 }
94
95
96 void MathStringInset::mathmlize(MathMLStream & os) const
97 {
98         if (code_ == LM_TC_VAR)
99                 os << "<mi> " << str_.c_str() << " </mi>";
100         else if (code_ == LM_TC_CONST)
101                 os << "<mn> " << str_.c_str() << " </mn>";
102         else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM)
103                 os << "<mtext> " << str_.c_str() <<  " </mtext>";
104         else
105                 os << str_.c_str();
106 }
107
108
109 void MathStringInset::write(WriteStream & os) const
110 {
111         if (math_font_name(code_)) 
112                 os << '\\' << math_font_name(code_) << '{' << str_.c_str() << '}';
113         else 
114                 os << str_.c_str();
115 }