]> git.lyx.org Git - lyx.git/blob - src/mathed/math_accentinset.C
remove more forms.h cruft
[lyx.git] / src / mathed / math_accentinset.C
1 #include <config.h>
2
3 #include "math_accentinset.h"
4 #include "mathed/support.h"
5 #include "math_parser.h"
6 #include "support/LOstream.h"
7
8 using std::ostream;
9
10 MathAccentInset::MathAccentInset(byte cx, MathTextCodes f, int cd)
11         : MathInset("", LM_OT_ACCENT),
12           c(cx), fn(f), code(cd), inset(0)
13 {}
14
15
16 MathAccentInset::MathAccentInset(MathInset * ins, int cd)
17         : MathInset("", LM_OT_ACCENT),
18           c(0), fn(LM_TC_MIN), code(cd), inset(ins)
19 {}
20
21
22 MathAccentInset::~MathAccentInset()
23 {
24         delete inset;
25 }
26
27
28 MathInset * MathAccentInset::clone() const
29 {   
30         MathAccentInset * p;
31         
32         if (inset) 
33                 p = new MathAccentInset(inset->clone(), code);
34         else
35                 p = new MathAccentInset(c, fn, code);
36         
37         return p;
38 }
39
40
41 void MathAccentInset::draw(Painter & pain, int x, int y)
42 {
43         int const dw = width() - 2;
44         
45         if (inset) 
46                 inset->draw(pain, x, y);
47         else 
48                 drawChar(pain, fn, size(), x, y, c);
49         x += (code == LM_not) ? (width() - dw) / 2 : 2;
50         mathed_draw_deco(pain, x, y - dy, dw, dh, code);
51 }
52
53
54 void MathAccentInset::Metrics(MathStyles st)
55 {
56         if (inset) {
57                 inset->Metrics(st);
58                 ascent_  = inset->ascent();
59                 descent_ = inset->descent();
60                 width_   = inset->width();
61                 dh = ascent_;
62         } else {
63                 mathed_char_dim(fn, size(), c, ascent_, descent_, width_);
64                 dh = width() / 2 - 1;
65         }
66         if (code == LM_not) {
67                 ascent_  += dh;
68                 descent_ += dh;
69                 dh = height();
70         } else 
71                 ascent_ += dh + 2;
72         
73         dy = ascent_;
74 //    if (MathIsBinary(fn))
75 //      width += 2*mathed_char_width(fn, size, ' ');    
76 }
77
78
79 void MathAccentInset::Write(ostream & os, bool fragile) const
80 {
81         latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
82         os << '\\' << l->name;
83         if (code!= LM_not)
84                 os << '{';
85         else
86                 os << ' ';
87         
88         if (inset)
89                 inset->Write(os, fragile);
90         else {
91                 if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM)
92                         os << '\\' << math_font_name[fn - LM_TC_RM] << '{';
93                 if (MathIsSymbol(fn)) {
94                         latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
95                         if (l)
96                                 os << '\\' << l->name << ' ';
97                 } else
98                         os << char(c);
99                 
100                 if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM)
101                         os << '}';
102         }
103         
104         if (code!= LM_not)
105                 os << '}';
106 }
107
108
109 void MathAccentInset::WriteNormal(ostream & os) const
110 {
111         latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
112         os << "[accent " << l->name << " ";
113
114         if (inset)
115                 inset->WriteNormal(os);
116         else {
117                 if (fn >= LM_TC_RM && fn <= LM_TC_TEXTRM)
118                         os << "[font " << math_font_name[fn - LM_TC_RM] << "]";
119                 if (MathIsSymbol(fn)) {
120                         latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
121                         if (l) 
122                                 os << "[symbol " << l->name << "] ";
123                 } else
124                         os << "[char " << char(c) << "] ";
125         }
126
127         os << "] ";
128 }
129
130 int MathAccentInset::getAccentCode() const
131 {
132         return code;
133 }