]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBig.cpp
use FileName::isDirectory()
[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         // Cache the inset dimension. 
71         setDimCache(mi, dim);
72 }
73
74
75 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
76 {
77         Dimension const dim = dimension(*pi.base.bv);
78         // mathed_draw_deco does not use the leading backslash, so remove it
79         // (but don't use ltrim if this is the backslash delimiter).
80         // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
81         // would treat it as |.
82         docstring const delim = (delim_ == "\\|") ?  from_ascii("Vert") :
83                 (delim_ == "\\\\") ? from_ascii("\\") : support::ltrim(delim_, "\\");
84         mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(),
85                          delim);
86         setPosCache(pi, x, y);
87 }
88
89
90 void InsetMathBig::write(WriteStream & os) const
91 {
92         os << '\\' << name_ << delim_;
93         if (delim_[0] == '\\')
94                 os.pendingSpace(true);
95 }
96
97
98 void InsetMathBig::normalize(NormalStream & os) const
99 {
100         os << '[' << name_ << ' ' << delim_ << ']';
101 }
102
103
104 void InsetMathBig::infoize2(odocstream & os) const
105 {
106         os << name_;
107 }
108
109
110 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
111 {
112         // mathed_draw_deco must handle these
113         static char const * const delimiters[] = {
114                 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
115                 "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
116                 "\\\\", "\\backslash",
117                 "\\langle", "\\lceil", "\\lfloor",
118                 "\\rangle", "\\rceil", "\\rfloor",
119                 "\\downarrow", "\\Downarrow",
120                 "\\uparrow", "\\Uparrow",
121                 "\\updownarrow", "\\Updownarrow", ""
122         };
123         return support::findToken(delimiters, to_utf8(delim)) >= 0;
124 }
125
126
127 } // namespace lyx