2 * \file InsetMathBig.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathBig.h"
15 #include "MathSupport.h"
16 #include "MathStream.h"
17 #include "MetricsInfo.h"
19 #include "frontends/FontMetrics.h"
21 #include "support/docstream.h"
22 #include "support/lstrings.h"
28 InsetMathBig::InsetMathBig(docstring
const & name
, docstring
const & delim
)
29 : name_(name
), delim_(delim
)
33 docstring
InsetMathBig::name() const
39 Inset
* InsetMathBig::clone() const
41 return new InsetMathBig(*this);
45 InsetMathBig::size_type
InsetMathBig::size() const
47 // order: big Big bigg Bigg biggg Biggg
49 return name_
[0] == 'B' ?
50 2 * (name_
.size() - 4) + 1:
51 2 * (name_
.size() - 4);
55 double InsetMathBig::increase() const
57 // The formula used in amsmath.sty is
58 // 1.2 * (1.0 + size() * 0.5) - 1.0.
59 // We use a smaller step and a bigger offset because our base size
61 return (size() + 1) * 0.3;
65 void InsetMathBig::metrics(MetricsInfo
& mi
, Dimension
& dim
) const
67 double const h
= theFontMetrics(mi
.base
.font
).ascent('I');
68 double const f
= increase();
70 dim
.asc
= int(h
+ f
* h
);
75 void InsetMathBig::draw(PainterInfo
& pi
, int x
, int y
) const
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(),
86 setPosCache(pi
, x
, y
);
90 void InsetMathBig::write(WriteStream
& os
) const
92 MathEnsurer
ensurer(os
);
93 os
<< '\\' << name_
<< delim_
;
94 if (delim_
[0] == '\\')
95 os
.pendingSpace(true);
99 void InsetMathBig::normalize(NormalStream
& os
) const
101 os
<< '[' << name_
<< ' ' << delim_
<< ']';
105 void InsetMathBig::infoize2(odocstream
& os
) const
111 bool InsetMathBig::isBigInsetDelim(docstring
const & delim
)
113 // mathed_draw_deco must handle these
114 static char const * const delimiters
[] = {
115 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
116 "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
117 "\\\\", "\\backslash",
118 "\\langle", "\\lceil", "\\lfloor",
119 "\\rangle", "\\rceil", "\\rfloor",
120 "\\downarrow", "\\Downarrow",
121 "\\uparrow", "\\Uparrow",
122 "\\updownarrow", "\\Updownarrow", ""
124 return support::findToken(delimiters
, to_utf8(delim
)) >= 0;