]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBig.C
Fix bug 2789 (as discussed)
[lyx.git] / src / mathed / InsetMathBig.C
1 /**
2  * \file InsetMathBig.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathBig.h"
14 #include "MathSupport.h"
15 #include "MathMLStream.h"
16 #include "MathStream.h"
17
18 #include "support/lstrings.h"
19
20
21 using std::string;
22 using std::auto_ptr;
23
24
25 InsetMathBig::InsetMathBig(string const & name, string const & delim)
26         : name_(name), delim_(delim)
27 {}
28
29
30 string InsetMathBig::name() const
31 {
32         return name_;
33 }
34
35
36 auto_ptr<InsetBase> InsetMathBig::doClone() const
37 {
38         return auto_ptr<InsetBase>(new InsetMathBig(*this));
39 }
40
41
42 InsetMathBig::size_type InsetMathBig::size() const
43 {
44         // order: big Big bigg Bigg biggg Biggg
45         //        0   1   2    3    4     5
46         return name_[0] == 'B' ?
47                 2 * (name_.size() - 4) + 1:
48                 2 * (name_.size() - 4);
49 }
50
51
52 double InsetMathBig::increase() const
53 {
54         // The formula used in amsmath.sty is
55         // 1.2 * (1.0 + size() * 0.5) - 1.0.
56         // We use a smaller step and a bigger offset because our base size
57         // is different.
58         return (size() + 1) * 0.3;
59 }
60
61
62 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
63 {
64         double const h = mathed_char_ascent(mi.base.font, 'I');
65         double const f = increase();
66         dim_.wid = 6;
67         dim_.asc = int(h + f * h);
68         dim_.des = int(f * h);
69         dim = dim_;
70 }
71
72
73 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
74 {
75         // mathed_draw_deco does not use the leading backslash, so remove it.
76         // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
77         // would treat it as |.
78         string const delim = (delim_ == "\\|") ?
79                 "Vert" :
80                 lyx::support::ltrim(delim_, "\\");
81         mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(),
82                          delim);
83         setPosCache(pi, x, y);
84 }
85
86
87 void InsetMathBig::write(WriteStream & os) const
88 {
89         os << '\\' << name_ << ' ' << delim_;
90         if (delim_[0] == '\\')
91                 os.pendingSpace(true);
92 }
93
94
95 void InsetMathBig::normalize(NormalStream & os) const
96 {
97         os << '[' << name_ << ' ' <<  delim_ << ']';
98 }
99
100
101 void InsetMathBig::infoize2(std::ostream & os) const
102 {
103         os << name_;
104 }
105
106
107 bool InsetMathBig::isBigInsetDelim(string const & delim)
108 {
109         // mathed_draw_deco must handle these
110         static char const * const delimiters[] = {
111                 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
112                 "|", "/", "\\|", "\\vert", "\\Vert", "'", "\\backslash",
113                 "\\langle", "\\lceil", "\\lfloor",
114                 "\\rangle", "\\rceil", "\\rfloor",
115                 "\\downarrow", "\\Downarrow",
116                 "\\uparrow", "\\Uparrow",
117                 "\\updownarrow", "\\Updownarrow", ""
118         };
119         return (lyx::support::findToken(delimiters, delim) >= 0);
120 }