]> git.lyx.org Git - features.git/blob - src/mathed/math_deliminset.C
write \mathrm{x}\mathrm{y} as \mathrm{xy} again
[features.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
15 MathDelimInset::MathDelimInset(string const & l, string const & r)
16         : MathNestInset(1), left_(l), right_(r)
17 {}
18
19
20 MathInset * MathDelimInset::clone() const
21 {   
22         return new MathDelimInset(*this);
23 }
24
25
26 string MathDelimInset::latexName(string const & name)
27 {
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         if (name == "|")
41                 return name;
42         return "\\" + name + " ";
43 }
44
45
46 void MathDelimInset::write(MathWriteInfo & os) const
47 {
48         os << "\\left" << latexName(left_) << cell(0)
49            << "\\right" << latexName(right_);
50 }
51
52
53 void MathDelimInset::writeNormal(std::ostream & os) const
54 {
55         os << "[delim " << latexName(left_) << ' ' << latexName(right_) << ' ';
56         cell(0).writeNormal(os);
57         os << "]";
58 }
59
60
61 int MathDelimInset::dw() const
62 {
63         int w = height() / 5;
64         if (w > 15)
65                 w = 15;
66         if (w < 4)
67                 w = 4;
68         return w;
69 }
70
71
72 void MathDelimInset::metrics(MathMetricsInfo const & mi) const
73 {
74         xcell(0).metrics(mi);
75         int a, d, w;
76         mathed_char_dim(LM_TC_VAR, mi, 'I', a, d, w);
77         int h0   = (a + d) / 2;
78         int a0   = std::max(xcell(0).ascent(), a)   - h0;
79         int d0   = std::max(xcell(0).descent(), d)  + h0;
80         ascent_  = max(a0, d0) + h0;
81         descent_ = max(a0, d0) - h0;
82         width_   = xcell(0).width() + 2 * dw() + 4;
83 }
84
85
86 void MathDelimInset::draw(Painter & pain, int x, int y) const
87
88         int const w = dw();
89         int const b = y - ascent_;
90         xcell(0).draw(pain, x + w + 2, y);
91         mathed_draw_deco(pain, x + 1, b, w, height(), left_);
92         mathed_draw_deco(pain, x + width() - w - 1, b, w, height(), right_);
93 }