]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
whichFont down to 5.3%
[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
19
20 MathCharInset::MathCharInset(char c)
21         : char_(c), code_(nativeCode(c))
22 {
23 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
24 }
25
26
27 MathCharInset::MathCharInset(char c, MathTextCodes t)
28         : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
29 {
30 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
31 }
32
33
34 MathTextCodes MathCharInset::nativeCode(char c)
35 {
36         if (isalpha(c))
37                 return LM_TC_VAR;
38         //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
39         return LM_TC_CONST;
40 }
41
42
43 MathInset * MathCharInset::clone() const
44 {   
45         return new MathCharInset(*this);
46 }
47
48
49 void MathCharInset::metrics(MathMetricsInfo const & mi) const
50 {
51         mi_ = mi;
52         mathed_char_dim(code_, mi_, char_, ascent_, descent_, width_);
53 }
54
55
56 void MathCharInset::draw(Painter & pain, int x, int y) const
57
58         //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
59         drawChar(pain, code_, mi_, x, y, char_);
60 }
61
62
63 void MathCharInset::writeHeader(std::ostream & os) const
64 {
65         if (math_font_name(code_))
66                 os << '\\' << math_font_name(code_) << '{';
67 }
68
69
70 void MathCharInset::writeTrailer(std::ostream & os) const
71 {
72         if (math_font_name(code_))
73                 os << '}';
74 }
75
76
77 void MathCharInset::writeRaw(std::ostream & os) const
78 {
79         os << char_;
80 }
81
82
83 void MathCharInset::write(WriteStream & os) const
84 {
85         writeHeader(os.os());
86         writeRaw(os.os());
87         writeTrailer(os.os());
88 }
89
90
91 void MathCharInset::normalize(NormalStream & os) const
92 {
93         os << "[char " << char_ << " " << "mathalpha" << "]";
94 }
95
96
97 bool MathCharInset::isRelOp() const
98 {
99         return char_ == '=' || char_ == '<' || char_ == '>';
100 }
101
102
103 void MathCharInset::handleFont(MathTextCodes t)
104 {
105         code_ = (code_ == t) ? LM_TC_VAR : t;
106 }
107
108
109 void MathCharInset::validate(LaTeXFeatures & features) const
110 {
111         // Make sure amssymb is put in preamble if Blackboard Bold or
112         // Fraktur used:
113         if ( (code_ == LM_TC_BB) || (code_ == LM_TC_EUFRAK) )
114                 features.require("amssymb");
115 }
116
117
118 bool MathCharInset::match(MathInset * p) const
119 {
120         MathCharInset const * q = p->asCharInset();
121         return q && char_ == q->char_ && code_ == q->code_;
122 }