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