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/Application.h"
19 #include "frontends/FontLoader.h"
20 #include "frontends/FontMetrics.h"
22 #include "support/lstrings.h"
29 InsetMathBig::InsetMathBig(string const & name, string const & delim)
30 : name_(name), delim_(delim)
34 string InsetMathBig::name() const
40 auto_ptr<InsetBase> InsetMathBig::doClone() const
42 return auto_ptr<InsetBase>(new InsetMathBig(*this));
46 InsetMathBig::size_type InsetMathBig::size() const
48 // order: big Big bigg Bigg biggg Biggg
50 return name_[0] == 'B' ?
51 2 * (name_.size() - 4) + 1:
52 2 * (name_.size() - 4);
56 double InsetMathBig::increase() const
58 // The formula used in amsmath.sty is
59 // 1.2 * (1.0 + size() * 0.5) - 1.0.
60 // We use a smaller step and a bigger offset because our base size
62 return (size() + 1) * 0.3;
66 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
69 = theApp->fontLoader().metrics(mi.base.font).ascent('I');
70 double const f = increase();
72 dim_.asc = int(h + f * h);
73 dim_.des = int(f * h);
78 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
80 // mathed_draw_deco does not use the leading backslash, so remove it.
81 // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
82 // would treat it as |.
83 string const delim = (delim_ == "\\|") ?
85 lyx::support::ltrim(delim_, "\\");
86 mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(),
88 setPosCache(pi, x, y);
92 void InsetMathBig::write(WriteStream & os) const
94 os << '\\' << name_ << ' ' << delim_;
95 if (delim_[0] == '\\')
96 os.pendingSpace(true);
100 void InsetMathBig::normalize(NormalStream & os) const
102 os << '[' << name_ << ' ' << delim_ << ']';
106 void InsetMathBig::infoize2(std::ostream & os) const
112 bool InsetMathBig::isBigInsetDelim(string const & delim)
114 // mathed_draw_deco must handle these
115 static char const * const delimiters[] = {
116 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
117 "|", "/", "\\|", "\\vert", "\\Vert", "'", "\\backslash",
118 "\\langle", "\\lceil", "\\lfloor",
119 "\\rangle", "\\rceil", "\\rfloor",
120 "\\downarrow", "\\Downarrow",
121 "\\uparrow", "\\Uparrow",
122 "\\updownarrow", "\\Updownarrow", ""
124 return (lyx::support::findToken(delimiters, delim) >= 0);