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 docstring InsetMathBig::word() const
83 // mathed_draw_deco does not use the leading backslash, so remove it
84 // (but don't use ltrim if this is the backslash delimiter).
85 // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
86 // would treat it as |.
88 return from_ascii("Vert");
90 return from_ascii("\\");
91 return support::ltrim(delim_, "\\");
95 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
97 Changer dummy = pi.base.changeEnsureMath();
98 Dimension const dim = dimension(*pi.base.bv);
99 mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(),
104 void InsetMathBig::write(WriteStream & os) const
106 MathEnsurer ensurer(os);
107 os << '\\' << name_ << delim_;
108 if (delim_[0] == '\\')
109 os.pendingSpace(true);
113 void InsetMathBig::normalize(NormalStream & os) const
115 os << '[' << name_ << ' ' << delim_ << ']';
119 void InsetMathBig::mathmlize(MathStream & os) const
121 os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
122 << convertDelimToXMLEscape(delim_)
127 void InsetMathBig::htmlize(HtmlStream & os) const
131 case 0: case 1: name = "big"; break;
132 case 2: case 3: name = "bigg"; break;
133 case 4: case 5: name = "biggg"; break;
134 default: name = "big"; break;
136 os << MTag("span", "class='" + name + "symbol'")
137 << convertDelimToXMLEscape(delim_)
142 void InsetMathBig::infoize2(odocstream & os) const
148 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
150 // mathed_draw_deco must handle these
151 static char const * const delimiters[] = {
152 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
153 "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
154 "<", ">", "\\\\", "\\backslash",
155 "\\langle", "\\lceil", "\\lfloor",
156 "\\rangle", "\\rceil", "\\rfloor",
157 "\\llbracket", "\\rrbracket",
158 "\\downarrow", "\\Downarrow",
159 "\\uparrow", "\\Uparrow",
160 "\\updownarrow", "\\Updownarrow", ""
162 return support::findToken(delimiters, to_utf8(delim)) >= 0;
166 void InsetMathBig::validate(LaTeXFeatures & features) const
168 validate_math_word(features, word());
169 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
170 features.addCSSSnippet(
171 "span.bigsymbol{font-size: 150%;}\n"
172 "span.biggsymbol{font-size: 200%;}\n"
173 "span.bigggsymbol{font-size: 225%;}");