]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBig.cpp
Improve the list of equations
[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 "Dimension.h"
16 #include "LaTeXFeatures.h"
17
18 #include "MathSupport.h"
19 #include "MathStream.h"
20 #include "MetricsInfo.h"
21
22 #include "frontends/FontMetrics.h"
23
24 #include "support/docstream.h"
25 #include "support/lstrings.h"
26
27
28 namespace lyx {
29
30
31 InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
32         : name_(name), delim_(delim)
33 {}
34
35
36 docstring InsetMathBig::name() const
37 {
38         return name_;
39 }
40
41
42 Inset * InsetMathBig::clone() const
43 {
44         return new InsetMathBig(*this);
45 }
46
47
48 InsetMathBig::size_type InsetMathBig::size() const
49 {
50         // order: big Big bigg Bigg biggg Biggg
51         //        0   1   2    3    4     5
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);
57 }
58
59
60 double InsetMathBig::increase() const
61 {
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
65         // is different.
66         return (size() + 1) * 0.3;
67 }
68
69
70 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
71 {
72         Changer dummy = mi.base.changeEnsureMath();
73         double const h = theFontMetrics(mi.base.font).ascent('I');
74         double const f = increase();
75         dim.wid = 6;
76         dim.asc = int(h + f * h);
77         dim.des = int(f * h);
78 }
79
80
81 docstring InsetMathBig::word() const
82 {
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 |.
87         if (delim_ == "\\|")
88                 return from_ascii("Vert");
89         if (delim_ == "\\\\")
90                 return from_ascii("\\");
91         return support::ltrim(delim_, "\\");
92 }
93
94
95 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
96 {
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(),
100                          word());
101 }
102
103
104 void InsetMathBig::write(WriteStream & os) const
105 {
106         MathEnsurer ensurer(os);
107         os << '\\' << name_ << delim_;
108         if (delim_[0] == '\\')
109                 os.pendingSpace(true);
110 }
111
112
113 void InsetMathBig::normalize(NormalStream & os) const
114 {
115         os << '[' << name_ << ' ' << delim_ << ']';
116 }
117
118
119 void InsetMathBig::mathmlize(MathStream & os) const
120 {
121         os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
122            << convertDelimToXMLEscape(delim_)
123            << "</mo>";
124 }
125
126
127 void InsetMathBig::htmlize(HtmlStream & os) const
128 {
129         std::string name;
130         switch (size()) {
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;
135         }
136         os << MTag("span", "class='" + name + "symbol'")
137            << convertDelimToXMLEscape(delim_)
138            << ETag("span");
139 }
140
141
142 void InsetMathBig::infoize2(odocstream & os) const
143 {
144         os << name_;
145 }
146
147
148 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
149 {
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", ""
161         };
162         return support::findToken(delimiters, to_utf8(delim)) >= 0;
163 }
164
165
166 void InsetMathBig::validate(LaTeXFeatures & features) const
167 {
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%;}");
174 }
175
176
177 } // namespace lyx