]> git.lyx.org Git - lyx.git/blob - src/mathed/math_accentinset.C
small cleanup, doxygen, formatting changes
[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, MathedTextCodes f, int cd, short st)
11         : MathedInset("", LM_OT_ACCENT, st), c(cx), fn(f), code(cd)
12 {
13         inset = 0;
14 }
15
16
17 MathAccentInset::MathAccentInset(MathedInset *ins, int cd, short st)
18         : MathedInset("", LM_OT_ACCENT, st),
19           c(0), fn(LM_TC_MIN), code(cd), inset(ins) {}
20
21
22 MathAccentInset::~MathAccentInset()
23 {
24         delete inset;
25 }
26
27
28 MathedInset * MathAccentInset::Clone()
29 {   
30         MathAccentInset * p;
31         
32         if (inset) 
33                 p = new MathAccentInset(inset->Clone(), code, GetStyle());
34         else
35                 p = new MathAccentInset(c, fn, code, GetStyle());
36         
37         return p;
38 }
39
40
41 void
42 MathAccentInset::draw(Painter & pain, int x, int y)
43 {
44         int dw = width - 2;
45         
46         if (inset) 
47                 inset->draw(pain, x, y);
48         else {
49                 string s;
50                 s += c;
51                 drawStr(pain, fn, size(), x, y, s);
52         }
53         x += (code == LM_not) ? (width-dw) / 2 : 2;
54         mathed_draw_deco(pain, x, y - dy, dw, dh, code);
55 }
56
57
58 void
59 MathAccentInset::Metrics()
60 {
61         if (inset) {
62                 inset->Metrics();
63                 ascent = inset->Ascent();
64                 descent = inset->Descent();
65                 width = inset->Width();
66                 dh = ascent;
67         } else {
68                 mathed_char_height(fn, size(), c, ascent, descent);
69                 width = mathed_char_width(fn, size(), c);
70                 dh = (width - 2) / 2; 
71         }
72         if (code == LM_not) {
73                 ascent += dh;
74                 descent += dh;
75                 dh = Height();
76         } else 
77                 ascent += dh+2;
78         
79         dy = ascent;
80 //    if (MathIsBinary(fn))
81 //      width += 2*mathed_char_width(fn, size, ' ');    
82 }
83
84
85 void MathAccentInset::Write(ostream & os, bool fragile)
86 {
87         latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
88         os << '\\' << l->name;
89         if (code!= LM_not)
90                 os << '{';
91         else
92                 os << ' ';
93         
94         if (inset) {
95                 inset->Write(os, fragile);
96         } else {
97                 if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM) {
98                         os << '\\'
99                            << math_font_name[fn - LM_TC_RM]
100                            << '{';
101                 }
102                 if (MathIsSymbol(fn)) {
103                         latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
104                         if (l) {
105                                 os << '\\' << l->name << ' ';
106                         }
107                 } else
108                         os << char(c);
109                 
110                 if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM)
111                         os << '}';
112         }
113         
114         if (code!= LM_not)
115                 os << '}';
116 }