]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
suppress debug messages
[lyx.git] / src / mathed / math_charinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include <cctype>
8
9 #include "math_charinset.h"
10 #include "LColor.h"
11 #include "Painter.h"
12 #include "support/LOstream.h"
13 #include "math_support.h"
14 #include "math_parser.h"
15 #include "debug.h"
16 #include "math_mathmlstream.h"
17 #include "LaTeXFeatures.h"
18 #include "textpainter.h"
19
20
21 using std::ostream;
22
23
24 MathCharInset::MathCharInset(char c)
25         : char_(c), code_(nativeCode(c))
26 {
27 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
28 }
29
30
31 MathCharInset::MathCharInset(char c, MathTextCodes t)
32         : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
33 {
34 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
35 }
36
37
38 MathTextCodes MathCharInset::nativeCode(char c)
39 {
40         if (isalpha(c))
41                 return LM_TC_VAR;
42         //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
43         return LM_TC_CONST;
44 }
45
46
47 MathInset * MathCharInset::clone() const
48 {   
49         return new MathCharInset(*this);
50 }
51
52
53 void MathCharInset::metrics(MathMetricsInfo const & mi) const
54 {
55         whichFont(font_, code_, mi);
56         mathed_char_dim(font_, char_, ascent_, descent_, width_);
57 }
58
59
60 void MathCharInset::draw(Painter & pain, int x, int y) const
61
62         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
63         drawChar(pain, font_, x, y, char_);
64 }
65
66
67 void MathCharInset::metrics(TextMetricsInfo const &) const
68 {
69         width_   = 1;
70         ascent_  = 1;
71         descent_ = 0;
72 }
73
74
75 void MathCharInset::draw(TextPainter & pain, int x, int y) const
76
77         lyxerr << "drawing text '" << char_ << "' code: " << code_ << endl;
78         pain.draw(x, y, char_);
79 }
80
81
82 void MathCharInset::writeHeader(ostream & os) const
83 {
84         if (math_font_name(code_))
85                 os << '\\' << math_font_name(code_) << '{';
86 }
87
88
89 void MathCharInset::writeTrailer(ostream & os) const
90 {
91         if (math_font_name(code_))
92                 os << '}';
93 }
94
95
96 void MathCharInset::writeRaw(ostream & os) const
97 {
98         os << char_;
99 }
100
101
102 void MathCharInset::write(WriteStream & os) const
103 {
104         writeHeader(os.os());
105         writeRaw(os.os());
106         writeTrailer(os.os());
107 }
108
109
110 void MathCharInset::normalize(NormalStream & os) const
111 {
112         os << "[char " << char_ << " " << "mathalpha" << "]";
113 }
114
115
116 bool MathCharInset::isRelOp() const
117 {
118         return char_ == '=' || char_ == '<' || char_ == '>';
119 }
120
121
122 void MathCharInset::handleFont(MathTextCodes t)
123 {
124         code_ = (code_ == t) ? LM_TC_VAR : t;
125 }
126
127
128 void MathCharInset::validate(LaTeXFeatures & features) const
129 {
130         // Make sure amssymb is put in preamble if Blackboard Bold or
131         // Fraktur used:
132         if ((code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK))
133                 features.require("amssymb");
134 }
135
136
137 bool MathCharInset::match(MathInset * p) const
138 {
139         MathCharInset const * q = p->asCharInset();
140         return q && char_ == q->char_ && code_ == q->code_;
141 }