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