]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
More fonts in mathed.
[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         "mathsf",
23         "mathtt",
24         "mathit",
25         "textrm"
26 };
27
28 }
29
30
31 MathCharInset::MathCharInset(char c)
32         : char_(c), code_(nativeCode(c))
33 {
34 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
35 }
36
37
38 MathCharInset::MathCharInset(char c, MathTextCodes t)
39         : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
40 {
41 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
42 }
43
44
45 MathTextCodes MathCharInset::nativeCode(char c) const
46 {
47         if (isalpha(c))
48                 return LM_TC_VAR;
49         //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
50         return LM_TC_CONST;
51 }
52
53
54 MathInset * MathCharInset::clone() const
55 {   
56         return new MathCharInset(*this);
57 }
58
59
60 int MathCharInset::ascent() const
61 {
62         return mathed_char_ascent(code_, size(), char_);
63 }
64
65
66 int MathCharInset::descent() const
67 {
68         return mathed_char_descent(code_, size(), char_);
69 }
70
71
72 int MathCharInset::width() const
73 {
74         return mathed_char_width(code_, size(), char_);
75 }
76
77
78 void MathCharInset::metrics(MathStyles st) const
79 {
80         size_ = st;
81 }
82
83
84 void MathCharInset::draw(Painter & pain, int x, int y) const
85
86         xo(x);
87         yo(y);
88         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
89         drawChar(pain, code_, size_, x, y, char_);
90 }
91
92
93 void MathCharInset::writeHeader(std::ostream & os) const
94 {
95         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM) 
96                 os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
97 }
98
99
100 void MathCharInset::writeTrailer(std::ostream & os) const
101 {
102         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
103                 os << '}';
104 }
105
106
107 void MathCharInset::writeRaw(std::ostream & os) const
108 {
109         os << char_;
110 }
111
112
113 void MathCharInset::write(std::ostream & os, bool) const
114 {
115         writeHeader(os);
116         writeRaw(os);
117         writeTrailer(os);
118 }
119
120
121 void MathCharInset::writeNormal(std::ostream & os) const
122 {
123         os << char_;
124 }
125
126
127 bool MathCharInset::isRelOp() const
128 {
129         return char_ == '=' || char_ == '<' || char_ == '>';
130 }
131
132
133 void MathCharInset::handleFont(MathTextCodes t)
134 {
135         code_ = (code_ == t) ? LM_TC_VAR : t;
136 }