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"
14 #include "MathSupport.h"
15 #include "MathStream.h"
16 #include "MathStream.h"
18 #include "frontends/FontMetrics.h"
20 #include "support/lstrings.h"
28 InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
29 : name_(name), delim_(delim)
33 docstring InsetMathBig::name() const
39 auto_ptr<InsetBase> InsetMathBig::doClone() const
41 return auto_ptr<InsetBase>(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 bool 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);
79 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
81 // mathed_draw_deco does not use the leading backslash, so remove it
82 // (but don't use ltrim if this is the backslash delimiter).
83 // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
84 // would treat it as |.
85 docstring const delim = (delim_ == "\\|") ? from_ascii("Vert") :
86 (delim_ == "\\\\") ? from_ascii("\\") : support::ltrim(delim_, "\\");
87 mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(),
89 setPosCache(pi, x, y);
93 void InsetMathBig::write(WriteStream & os) const
95 os << '\\' << name_ << delim_;
96 if (delim_[0] == '\\')
97 os.pendingSpace(true);
101 void InsetMathBig::normalize(NormalStream & os) const
103 os << '[' << name_ << ' ' << delim_ << ']';
107 void InsetMathBig::infoize2(odocstream & os) const
113 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
115 // mathed_draw_deco must handle these
116 static char const * const delimiters[] = {
117 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
118 "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
119 "\\\\", "\\backslash",
120 "\\langle", "\\lceil", "\\lfloor",
121 "\\rangle", "\\rceil", "\\rfloor",
122 "\\downarrow", "\\Downarrow",
123 "\\uparrow", "\\Uparrow",
124 "\\updownarrow", "\\Updownarrow", ""
126 return support::findToken(delimiters, to_utf8(delim)) >= 0;