]> git.lyx.org Git - lyx.git/blob - src/mathed/math_charinset.C
Oooooops
[lyx.git] / src / mathed / math_charinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_charinset.h"
6 #include "LColor.h"
7 #include "Painter.h"
8 #include "support/LOstream.h"
9 #include "mathed/support.h"
10 #include "math_parser.h"
11 #include "debug.h"
12
13
14 MathCharInset::MathCharInset(char c, MathTextCodes t)
15         : char_(c)
16 {
17         code(t);
18 }
19
20
21 MathInset * MathCharInset::clone() const
22 {   
23         return new MathCharInset(*this);
24 }
25
26
27 int MathCharInset::ascent() const
28 {
29         return mathed_char_ascent(code_, size(), char_);
30 }
31
32
33 int MathCharInset::descent() const
34 {
35         return mathed_char_descent(code_, size(), char_);
36 }
37
38
39 int MathCharInset::width() const
40 {
41         return mathed_char_width(code_, size(), char_);
42 }
43
44
45 void MathCharInset::draw(Painter & pain, int x, int y)
46
47         xo(x);
48         yo(y);
49         drawChar(pain, code_, size_, x, y, char_);
50 }
51
52
53 void MathCharInset::write(std::ostream & os, bool) const
54 {
55         int brace = 0;
56
57         if (MathIsSymbol(code_)) {
58                 latexkeys const * l = lm_get_key_by_id(char_, LM_TK_SYM);
59
60                 if (l == 0) 
61                         l = lm_get_key_by_id(char_, LM_TK_BIGSYM);
62
63                 if (l) {
64                         os << '\\' << l->name << ' ';
65                 } else {
66                         lyxerr << "Could not find the LaTeX name for  " 
67                                 << char_ << " and code_ " << code_ << "!" << std::endl;
68                 }
69         } else {
70                 if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM) 
71                         os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
72
73                 // Is there a standard logical XOR?
74                 if ((code_ == LM_TC_TEX && char_ != '{' && char_ != '}') ||
75                                 (code_ == LM_TC_SPECIAL))
76                         os << '\\';
77                 else {
78                         if (char_ == '{')
79                                 ++brace;
80                         if (char_ == '}')
81                                 --brace;
82                 }
83                 if (char_ == '}' && code_ == LM_TC_TEX && brace < 0) 
84                         lyxerr <<"Math warning: Unexpected closing brace.\n";
85                 else           
86                         os << char_;
87         }
88
89         if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
90                 os << '}';
91 }
92
93
94 void MathCharInset::writeNormal(std::ostream & os) const
95 {
96         os << "[sqrt ";
97         cell(0).writeNormal(os); 
98         os << "] ";
99 }