]> git.lyx.org Git - features.git/blob - src/mathed/math_deliminset.C
mathed compilation fixes
[features.git] / src / mathed / math_deliminset.C
1 #include <config.h>
2
3 #include "math_deliminset.h"
4 #include "math_iter.h"
5 #include "math_parser.h"
6 #include "LColor.h"
7 #include "Painter.h"
8 #include "mathed/support.h"
9 #include "support/LOstream.h"
10
11 using std::ostream;
12
13
14 MathDelimInset::MathDelimInset(int l, int r, short st)
15         : MathParInset(st, "", LM_OT_DELIM), left(l), right(r) {}
16
17
18 MathedInset * MathDelimInset::Clone()
19 {   
20         MathDelimInset * p = new MathDelimInset(left, right, GetStyle());
21         MathedIter it(array);
22         p->SetData(it.Copy());
23         return p;
24 }
25
26
27
28 void MathDelimInset::Write(ostream & os, bool fragile)
29 {
30         latexkeys * l = (left != '|') ? lm_get_key_by_id(left, LM_TK_SYM): 0;
31         latexkeys * r = (right != '|') ? lm_get_key_by_id(right, LM_TK_SYM): 0;
32         os << "\\left";
33         if (l) {
34                 os << '\\' << l->name << ' ';
35         } else {
36                 if (left == '{' || left == '}') {
37                         os << '\\' << char(left) << ' ';
38                 } else {
39                         os << char(left) << ' ';
40                 }
41         }
42         MathParInset::Write(os, fragile);
43         os << "\\right";
44         if (r) {
45                 os << '\\' << r->name << ' ';
46         } else {
47                 if (right == '{' || right == '}') {
48                         os << '\\' << char(right) << ' ';
49                 } else {
50                         os << char(right) << ' ';
51                 }
52         }
53 }
54
55
56
57 void
58 MathDelimInset::draw(Painter & pain, int x, int y)
59
60         xo = x;  yo = y; 
61         MathParInset::draw(pain, x + dw + 2, y - dh); 
62         
63         if (left == '.') {
64                 pain.line(x + 4, yo - ascent,
65                           x + 4, yo + descent,
66                           LColor::mathcursor, Painter::line_onoffdash);
67         } else
68                 mathed_draw_deco(pain, x, y - ascent, dw, Height(), left);
69         x += Width() - dw - 2;
70         if (right == '.') {
71                 pain.line(x + 4, yo - ascent,
72                           x + 4, yo + descent,
73                           LColor::mathcursor, Painter::line_onoffdash);
74         } else
75                 mathed_draw_deco(pain, x, y-ascent, dw, Height(), right);
76 }
77
78
79 void
80 MathDelimInset::Metrics()
81 {
82    MathParInset::Metrics();
83    int d;
84    
85    mathed_char_height(LM_TC_CONST, size, 'I', d, dh);
86    dh /= 2;
87    ascent += 2 + dh;
88    descent += 2 - dh;
89    dw = Height()/5;
90    if (dw > 15) dw = 15;
91    if (dw<6) dw = 6;
92    width += 2*dw+4;
93 }