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 "MathMLStream.h"
16 #include "MathStream.h"
18 #include "frontends/FontMetrics.h"
20 #include "support/lstrings.h"
27 InsetMathBig::InsetMathBig(string const & name, string const & delim)
28 : name_(name), delim_(delim)
32 string InsetMathBig::name() const
38 auto_ptr<InsetBase> InsetMathBig::doClone() const
40 return auto_ptr<InsetBase>(new InsetMathBig(*this));
44 InsetMathBig::size_type InsetMathBig::size() const
46 // order: big Big bigg Bigg biggg Biggg
48 return name_[0] == 'B' ?
49 2 * (name_.size() - 4) + 1:
50 2 * (name_.size() - 4);
54 double InsetMathBig::increase() const
56 // The formula used in amsmath.sty is
57 // 1.2 * (1.0 + size() * 0.5) - 1.0.
58 // We use a smaller step and a bigger offset because our base size
60 return (size() + 1) * 0.3;
64 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
66 double const h = theFontMetrics(mi.base.font).ascent('I');
67 double const f = increase();
69 dim_.asc = int(h + f * h);
70 dim_.des = int(f * h);
75 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
77 // mathed_draw_deco does not use the leading backslash, so remove it.
78 // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
79 // would treat it as |.
80 string const delim = (delim_ == "\\|") ?
82 lyx::support::ltrim(delim_, "\\");
83 mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(),
85 setPosCache(pi, x, y);
89 void InsetMathBig::write(WriteStream & os) const
91 os << '\\' << name_ << ' ' << delim_;
92 if (delim_[0] == '\\')
93 os.pendingSpace(true);
97 void InsetMathBig::normalize(NormalStream & os) const
99 os << '[' << name_ << ' ' << delim_ << ']';
103 void InsetMathBig::infoize2(std::ostream & os) const
109 bool InsetMathBig::isBigInsetDelim(string const & delim)
111 // mathed_draw_deco must handle these
112 static char const * const delimiters[] = {
113 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
114 "|", "/", "\\|", "\\vert", "\\Vert", "'", "\\backslash",
115 "\\langle", "\\lceil", "\\lfloor",
116 "\\rangle", "\\rceil", "\\rfloor",
117 "\\downarrow", "\\Downarrow",
118 "\\uparrow", "\\Uparrow",
119 "\\updownarrow", "\\Updownarrow", ""
121 return (lyx::support::findToken(delimiters, delim) >= 0);