]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
84a1001f9900108405fc1660beaf5160a3151455
[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         int a, d, w;
68         mathed_char_dim(LM_TC_VAR, st,'I', a, d, w);
69         int h0   = (a + d) / 2;
70         int a0   = std::max(xcell(0).ascent(), a)   - h0;
71         int d0   = std::max(xcell(0).descent(), d)  + h0;
72         ascent_  = max(a0, d0) + h0;
73         descent_ = max(a0, d0) - h0;
74         width_   = xcell(0).width() + 2 * dw() + 4;
75 }
76
77
78 void MathDelimInset::draw(Painter & pain, int x, int y) const
79
80         xo(x);
81         yo(y); 
82
83         int const w = dw();
84         int const b = y - ascent_ - 2;
85         xcell(0).draw(pain, x + w + 2, y);
86         mathed_draw_deco(pain, x + 1, b, w, height() + 4, left_);
87         mathed_draw_deco(pain, x + width() - w - 1, b, w, height() + 4, right_);
88 }