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