]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBig.cpp
Use convertDelimToXMLEscape with matrix delimiters, too.
[lyx.git] / src / mathed / InsetMathBig.cpp
1 /**
2  * \file InsetMathBig.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathBig.h"
14
15 #include "LaTeXFeatures.h"
16 #include "MathSupport.h"
17 #include "MathStream.h"
18 #include "MetricsInfo.h"
19
20 #include "frontends/FontMetrics.h"
21
22 #include "support/docstream.h"
23 #include "support/lstrings.h"
24
25
26 namespace lyx {
27
28
29 InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
30         : name_(name), delim_(delim)
31 {}
32
33
34 docstring InsetMathBig::name() const
35 {
36         return name_;
37 }
38
39
40 Inset * InsetMathBig::clone() const
41 {
42         return new InsetMathBig(*this);
43 }
44
45
46 InsetMathBig::size_type InsetMathBig::size() const
47 {
48         // order: big Big bigg Bigg biggg Biggg
49         //        0   1   2    3    4     5
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);
55 }
56
57
58 double InsetMathBig::increase() const
59 {
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
63         // is different.
64         return (size() + 1) * 0.3;
65 }
66
67
68 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
69 {
70         double const h = theFontMetrics(mi.base.font).ascent('I');
71         double const f = increase();
72         dim.wid = 6;
73         dim.asc = int(h + f * h);
74         dim.des = int(f * h);
75 }
76
77
78 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
79 {
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(),
88                          delim);
89         setPosCache(pi, x, y);
90 }
91
92
93 void InsetMathBig::write(WriteStream & os) const
94 {
95         MathEnsurer ensurer(os);
96         os << '\\' << name_ << delim_;
97         if (delim_[0] == '\\')
98                 os.pendingSpace(true);
99 }
100
101
102 void InsetMathBig::normalize(NormalStream & os) const
103 {
104         os << '[' << name_ << ' ' << delim_ << ']';
105 }
106
107
108 void InsetMathBig::mathmlize(MathStream & os) const
109 {
110         os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
111            << convertDelimToXMLEscape(delim_)
112            << "</mo>";
113 }
114
115
116 void InsetMathBig::htmlize(HtmlStream & os) const
117 {
118         std::string name;
119         switch (size()) {
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;
124         }
125         os << MTag("span", "class='" + name + "symbol'")
126            << convertDelimToXMLEscape(delim_)
127            << ETag("span");
128 }
129
130
131 void InsetMathBig::infoize2(odocstream & os) const
132 {
133         os << name_;
134 }
135
136
137 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
138 {
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", ""
149         };
150         return support::findToken(delimiters, to_utf8(delim)) >= 0;
151 }
152
153
154 void InsetMathBig::validate(LaTeXFeatures & features) const
155 {
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%;}");
161 }
162
163
164 } // namespace lyx