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