]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
add missing writeNormal() methods to some insets
[lyx.git] / src / mathed / math_charinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include <cctype>
6
7 #include "math_charinset.h"
8 #include "LColor.h"
9 #include "Painter.h"
10 #include "support/LOstream.h"
11 #include "mathed/support.h"
12 #include "math_parser.h"
13 #include "debug.h"
14
15
16 namespace {
17
18 char const * math_font_name[] = {
19         "mathrm",
20         "mathcal",
21         "mathbf",
22         "mathbb",
23         "mathsf",
24         "mathtt",
25         "mathit",
26         "textrm"
27 };
28
29 }
30
31
32 MathCharInset::MathCharInset(char c)
33         : char_(c), code_(nativeCode(c))
34 {
35 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
36 }
37
38
39 MathCharInset::MathCharInset(char c, MathTextCodes t)
40         : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
41 {
42 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
43 }
44
45
46 MathTextCodes MathCharInset::nativeCode(char c) const
47 {
48         if (isalpha(c))
49                 return LM_TC_VAR;
50         //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
51         return LM_TC_CONST;
52 }
53
54
55 MathInset * MathCharInset::clone() const
56 {   
57         return new MathCharInset(*this);
58 }
59
60
61 int MathCharInset::ascent() const
62 {
63         return mathed_char_ascent(code_, mi_, char_);
64 }
65
66
67 int MathCharInset::descent() const
68 {
69         return mathed_char_descent(code_, mi_, char_);
70 }
71
72
73 int MathCharInset::width() const
74 {
75         return mathed_char_width(code_, mi_, char_);
76 }
77
78
79 void MathCharInset::metrics(MathMetricsInfo const & mi) const
80 {
81         mi_ = mi;
82 }
83
84
85 void MathCharInset::draw(Painter & pain, int x, int y) const
86
87         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
88         drawChar(pain, code_, mi_, x, y, char_);
89 }
90
91
92 void MathCharInset::writeHeader(std::ostream & os) const
93 {
94         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM) 
95                 os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
96 }
97
98
99 void MathCharInset::writeTrailer(std::ostream & os) const
100 {
101         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
102                 os << '}';
103 }
104
105
106 void MathCharInset::writeRaw(std::ostream & os) const
107 {
108         os << char_;
109 }
110
111
112 void MathCharInset::write(MathWriteInfo & os) const
113 {
114         writeHeader(os.os);
115         writeRaw(os.os);
116         writeTrailer(os.os);
117 }
118
119
120 void MathCharInset::writeNormal(std::ostream & os) const
121 {
122         os << "[char " << char_ << " " << "mathalpha" << "]";
123 }
124
125
126 bool MathCharInset::isRelOp() const
127 {
128         return char_ == '=' || char_ == '<' || char_ == '>';
129 }
130
131
132 void MathCharInset::handleFont(MathTextCodes t)
133 {
134         code_ = (code_ == t) ? LM_TC_VAR : t;
135 }