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