]> git.lyx.org Git - lyx.git/blob - src/mathed/math_stringinset.C
start native C++ support for Octave, Maple and MathML
[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 "LColor.h"
9 #include "Painter.h"
10 #include "support/LOstream.h"
11 #include "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_ << '}';
62         else 
63                 os << str_;
64 }
65
66
67 void MathStringInset::writeNormal(std::ostream & os) const
68 {
69         os << "[string " << str_ << " " << "mathalpha" << "]";
70 }
71
72
73 string MathStringInset::octavize() const
74 {
75         return maplize();
76 }
77
78
79 string MathStringInset::maplize() const
80 {
81         if (code_ != LM_TC_VAR)
82                 return str_;
83         if (str_.size() <= 1)
84                 return str_;
85         string res;
86
87         // insert '*' between adjacent chars if type is LM_TC_VAR
88         res += str_[0];
89         for (string::size_type i = 1; i < str_.size(); ++i) {
90                 res += '*';
91                 res += str_[i];
92         }
93         return res;
94 }