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