]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
halfway through fixing size of math in non-standard sizesd paragraohs like
[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_, size_, char_);
64 }
65
66
67 int MathCharInset::descent() const
68 {
69         return mathed_char_descent(code_, size_, char_);
70 }
71
72
73 int MathCharInset::width() const
74 {
75         return mathed_char_width(code_, size_, char_);
76 }
77
78
79 void MathCharInset::metrics(MathMetricsInfo const & st) const
80 {
81         size_ = st;
82 }
83
84
85 void MathCharInset::draw(Painter & pain, int x, int y) const
86
87         xo(x);
88         yo(y);
89         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
90         drawChar(pain, code_, size_, x, y, char_);
91 }
92
93
94 void MathCharInset::writeHeader(std::ostream & os) const
95 {
96         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM) 
97                 os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
98 }
99
100
101 void MathCharInset::writeTrailer(std::ostream & os) const
102 {
103         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
104                 os << '}';
105 }
106
107
108 void MathCharInset::writeRaw(std::ostream & os) const
109 {
110         os << char_;
111 }
112
113
114 void MathCharInset::write(MathWriteInfo & os) const
115 {
116         writeHeader(os.os);
117         writeRaw(os.os);
118         writeTrailer(os.os);
119 }
120
121
122 void MathCharInset::writeNormal(std::ostream & os) const
123 {
124         os << char_;
125 }
126
127
128 bool MathCharInset::isRelOp() const
129 {
130         return char_ == '=' || char_ == '<' || char_ == '>';
131 }
132
133
134 void MathCharInset::handleFont(MathTextCodes t)
135 {
136         code_ = (code_ == t) ? LM_TC_VAR : t;
137 }