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 "LaTeXFeatures.h"
16 #include "MathSupport.h"
17 #include "MathStream.h"
18 #include "MetricsInfo.h"
20 #include "frontends/FontMetrics.h"
22 #include "support/docstream.h"
23 #include "support/lstrings.h"
29 InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
30 : name_(name), delim_(delim)
34 docstring InsetMathBig::name() const
40 Inset * InsetMathBig::clone() const
42 return new InsetMathBig(*this);
46 InsetMathBig::size_type InsetMathBig::size() const
48 // order: big Big bigg Bigg biggg Biggg
50 char_type const c = name_[name_.size() - 1];
51 int const base_size = (c == 'l' || c == 'm' || c == 'r') ? 4 : 3;
52 return name_[0] == 'B' ?
53 2 * (name_.size() - base_size) + 1:
54 2 * (name_.size() - base_size);
58 double InsetMathBig::increase() const
60 // The formula used in amsmath.sty is
61 // 1.2 * (1.0 + size() * 0.5) - 1.0.
62 // We use a smaller step and a bigger offset because our base size
64 return (size() + 1) * 0.3;
68 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
70 double const h = theFontMetrics(mi.base.font).ascent('I');
71 double const f = increase();
73 dim.asc = int(h + f * h);
78 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
80 Dimension const dim = dimension(*pi.base.bv);
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 MathEnsurer ensurer(os);
96 os << '\\' << name_ << delim_;
97 if (delim_[0] == '\\')
98 os.pendingSpace(true);
102 void InsetMathBig::normalize(NormalStream & os) const
104 os << '[' << name_ << ' ' << delim_ << ']';
108 void InsetMathBig::mathmlize(MathStream & os) const
110 os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
111 << convertDelimToXMLEscape(delim_)
116 void InsetMathBig::htmlize(HtmlStream & os) const
120 case 0: case 1: name = "big"; break;
121 case 2: case 3: name = "bigg"; break;
122 case 4: case 5: name = "biggg"; break;
123 default: name = "big"; break;
125 os << MTag("span", "class='" + name + "symbol'")
126 << convertDelimToXMLEscape(delim_)
131 void InsetMathBig::infoize2(odocstream & os) const
137 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
139 // mathed_draw_deco must handle these
140 static char const * const delimiters[] = {
141 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
142 "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
143 "<", ">", "\\\\", "\\backslash",
144 "\\langle", "\\lceil", "\\lfloor",
145 "\\rangle", "\\rceil", "\\rfloor",
146 "\\downarrow", "\\Downarrow",
147 "\\uparrow", "\\Uparrow",
148 "\\updownarrow", "\\Updownarrow", ""
150 return support::findToken(delimiters, to_utf8(delim)) >= 0;
154 void InsetMathBig::validate(LaTeXFeatures & features) const
156 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
157 features.addCSSSnippet(
158 "span.bigsymbol{font-size: 150%;}\n"
159 "span.biggsymbol{font-size: 200%;}\n"
160 "span.bigggsymbol{font-size: 225%;}");