]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
c84ce7f811de2a7ec8252cd88b4f49596c0ccd11
[lyx.git] / src / mathed / math_deliminset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_deliminset.h"
6 #include "math_parser.h"
7 #include "mathed/support.h"
8 #include "support/LOstream.h"
9
10
11 MathDelimInset::MathDelimInset(latexkeys const * l, latexkeys const * r)
12         : MathNestInset(1), left_(l), right_(r)
13 {}
14
15
16 MathInset * MathDelimInset::clone() const
17 {   
18         return new MathDelimInset(*this);
19 }
20
21
22 string MathDelimInset::latexName(latexkeys const * l)
23 {
24         //static const string vdelim("(){}[]./|");
25         string name = l->name;
26         if (name == "(")
27                 return name;
28         if (name == "[")
29                 return name;
30         if (name == ".")
31                 return name;
32         if (name == ")")
33                 return name;
34         if (name == "]")
35                 return name;
36         if (name == "/")
37                 return name;
38         if (name == "|")
39                 return name;
40         return "\\" + name + " ";
41 }
42
43
44 void MathDelimInset::write(std::ostream & os, bool fragile) const
45 {
46         os << "\\left" << latexName(left_);
47         cell(0).write(os, fragile);
48         os << "\\right" << latexName(right_);
49 }
50
51
52 int MathDelimInset::dw() const
53 {
54         int w = height() / 5;
55         if (w > 15)
56                 w = 15;
57         if (w < 4)
58                 w = 4;
59         return w;
60 }
61
62
63 void MathDelimInset::metrics(MathStyles st) const
64 {
65         xcell(0).metrics(st);
66         size_    = st;
67         ascent_  = std::max(xcell(0).ascent(), mathed_char_ascent(LM_TC_VAR, st,'I'));
68         descent_ = xcell(0).descent();
69         width_   = xcell(0).width() + 2 * dw() + 4;
70 }
71
72
73 void MathDelimInset::draw(Painter & pain, int x, int y) const
74
75         xo(x);
76         yo(y); 
77
78         int const w = dw();
79         int const b = y - ascent_ - 2;
80         xcell(0).draw(pain, x + w + 2, y);
81         mathed_draw_deco(pain, x, b, w, height() + 4, left_);
82         mathed_draw_deco(pain, x + width() - w, b, w, height() + 4, right_);
83 }