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 "Dimension.h"
16 #include "LaTeXFeatures.h"
18 #include "MathSupport.h"
19 #include "MathStream.h"
20 #include "MetricsInfo.h"
22 #include "frontends/FontMetrics.h"
24 #include "support/docstream.h"
25 #include "support/lstrings.h"
31 InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
32 : name_(name), delim_(delim)
36 docstring InsetMathBig::name() const
42 Inset * InsetMathBig::clone() const
44 return new InsetMathBig(*this);
48 InsetMathBig::size_type InsetMathBig::size() const
50 // order: big Big bigg Bigg biggg Biggg
52 char_type const c = name_[name_.size() - 1];
53 int const base_size = (c == 'l' || c == 'm' || c == 'r') ? 4 : 3;
54 return name_[0] == 'B' ?
55 2 * (name_.size() - base_size) + 1:
56 2 * (name_.size() - base_size);
60 double InsetMathBig::increase() const
62 // The formula used in amsmath.sty is
63 // 1.2 * (1.0 + size() * 0.5) - 1.0.
64 // We use a smaller step and a bigger offset because our base size
66 return (size() + 1) * 0.3;
70 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
72 Changer dummy = mi.base.changeEnsureMath();
73 double const h = theFontMetrics(mi.base.font).ascent('I');
74 double const f = increase();
76 dim.asc = int(h + f * h);
81 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
83 Changer dummy = pi.base.changeEnsureMath();
84 Dimension const dim = dimension(*pi.base.bv);
85 // mathed_draw_deco does not use the leading backslash, so remove it
86 // (but don't use ltrim if this is the backslash delimiter).
87 // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
88 // would treat it as |.
89 docstring const delim = (delim_ == "\\|") ? from_ascii("Vert") :
90 (delim_ == "\\\\") ? from_ascii("\\") : support::ltrim(delim_, "\\");
91 mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(),
96 void InsetMathBig::write(WriteStream & os) const
98 MathEnsurer ensurer(os);
99 os << '\\' << name_ << delim_;
100 if (delim_[0] == '\\')
101 os.pendingSpace(true);
105 void InsetMathBig::normalize(NormalStream & os) const
107 os << '[' << name_ << ' ' << delim_ << ']';
111 void InsetMathBig::mathmlize(MathStream & os) const
113 os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
114 << convertDelimToXMLEscape(delim_)
119 void InsetMathBig::htmlize(HtmlStream & os) const
123 case 0: case 1: name = "big"; break;
124 case 2: case 3: name = "bigg"; break;
125 case 4: case 5: name = "biggg"; break;
126 default: name = "big"; break;
128 os << MTag("span", "class='" + name + "symbol'")
129 << convertDelimToXMLEscape(delim_)
134 void InsetMathBig::infoize2(odocstream & os) const
140 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
142 // mathed_draw_deco must handle these
143 static char const * const delimiters[] = {
144 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
145 "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
146 "<", ">", "\\\\", "\\backslash",
147 "\\langle", "\\lceil", "\\lfloor",
148 "\\rangle", "\\rceil", "\\rfloor",
149 "\\downarrow", "\\Downarrow",
150 "\\uparrow", "\\Uparrow",
151 "\\updownarrow", "\\Updownarrow", ""
153 return support::findToken(delimiters, to_utf8(delim)) >= 0;
157 void InsetMathBig::validate(LaTeXFeatures & features) const
159 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
160 features.addCSSSnippet(
161 "span.bigsymbol{font-size: 150%;}\n"
162 "span.biggsymbol{font-size: 200%;}\n"
163 "span.bigggsymbol{font-size: 225%;}");