2 * \file math_biginset.C
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 "math_biginset.h"
14 #include "math_support.h"
15 #include "math_mathmlstream.h"
16 #include "math_streamstr.h"
18 #include "support/lstrings.h"
25 MathBigInset::MathBigInset(string const & name, string const & delim)
26 : name_(name), delim_(delim)
30 string MathBigInset::name() const
36 auto_ptr<InsetBase> MathBigInset::doClone() const
38 return auto_ptr<InsetBase>(new MathBigInset(*this));
42 MathBigInset::size_type MathBigInset::size() const
44 // order: big Big bigg Bigg biggg Biggg
46 return name_[0] == 'B' ?
47 2 * (name_.size() - 4) + 1:
48 2 * (name_.size() - 4);
52 double MathBigInset::increase() const
54 // The formula used in amsmath.sty is
55 // 1.2 * (1.0 + size() * 0.5) - 1.0.
56 // We use a smaller step and a bigger offset because our base size
58 return (size() + 1) * 0.3;
62 void MathBigInset::metrics(MetricsInfo & mi, Dimension & dim) const
64 double const h = mathed_char_ascent(mi.base.font, 'I');
65 double const f = increase();
67 dim_.asc = int(h + f * h);
68 dim_.des = int(f * h);
73 void MathBigInset::draw(PainterInfo & pi, int x, int y) const
75 // mathed_draw_deco does not use the leading backslash, so remove it.
76 // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
77 // would treat it as |.
78 string const delim = (delim_ == "\\|") ?
80 lyx::support::ltrim(delim_, "\\");
81 mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(),
83 setPosCache(pi, x, y);
87 void MathBigInset::write(WriteStream & os) const
89 os << '\\' << name_ << ' ' << delim_;
90 if (delim_[0] == '\\')
91 os.pendingSpace(true);
95 void MathBigInset::normalize(NormalStream & os) const
97 os << '[' << name_ << ' ' << delim_ << ']';
101 void MathBigInset::infoize2(std::ostream & os) const
107 bool MathBigInset::isBigInsetDelim(string const & delim)
109 // mathed_draw_deco must handle these
110 static char const * const delimiters[] = {
111 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
112 "|", "/", "\\|", "\\vert", "\\Vert", "'", "\\backslash",
113 "\\langle", "\\lceil", "\\lfloor",
114 "\\rangle", "\\rceil", "\\rfloor",
115 "\\downarrow", "\\Downarrow",
116 "\\uparrow", "\\Uparrow",
117 "\\updownarrow", "\\Updownarrow", ""
119 return (lyx::support::findToken(delimiters, delim) >= 0);