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