]> git.lyx.org Git - features.git/blob - src/mathed/InsetMathBig.cpp
MathML for InsetMathBig.
[features.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 "MathSupport.h"
16 #include "MathStream.h"
17 #include "MetricsInfo.h"
18
19 #include "frontends/FontMetrics.h"
20
21 #include "support/docstream.h"
22 #include "support/lstrings.h"
23
24
25 namespace lyx {
26
27
28 InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
29         : name_(name), delim_(delim)
30 {}
31
32
33 docstring InsetMathBig::name() const
34 {
35         return name_;
36 }
37
38
39 Inset * InsetMathBig::clone() const
40 {
41         return new InsetMathBig(*this);
42 }
43
44
45 InsetMathBig::size_type InsetMathBig::size() const
46 {
47         // order: big Big bigg Bigg biggg Biggg
48         //        0   1   2    3    4     5
49         return name_[0] == 'B' ?
50                 2 * (name_.size() - 4) + 1:
51                 2 * (name_.size() - 4);
52 }
53
54
55 double InsetMathBig::increase() const
56 {
57         // The formula used in amsmath.sty is
58         // 1.2 * (1.0 + size() * 0.5) - 1.0.
59         // We use a smaller step and a bigger offset because our base size
60         // is different.
61         return (size() + 1) * 0.3;
62 }
63
64
65 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
66 {
67         double const h = theFontMetrics(mi.base.font).ascent('I');
68         double const f = increase();
69         dim.wid = 6;
70         dim.asc = int(h + f * h);
71         dim.des = int(f * h);
72 }
73
74
75 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
76 {
77         Dimension const dim = dimension(*pi.base.bv);
78         // mathed_draw_deco does not use the leading backslash, so remove it
79         // (but don't use ltrim if this is the backslash delimiter).
80         // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
81         // would treat it as |.
82         docstring const delim = (delim_ == "\\|") ?  from_ascii("Vert") :
83                 (delim_ == "\\\\") ? from_ascii("\\") : support::ltrim(delim_, "\\");
84         mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(),
85                          delim);
86         setPosCache(pi, x, y);
87 }
88
89
90 void InsetMathBig::write(WriteStream & os) const
91 {
92         MathEnsurer ensurer(os);
93         os << '\\' << name_ << delim_;
94         if (delim_[0] == '\\')
95                 os.pendingSpace(true);
96 }
97
98
99 void InsetMathBig::normalize(NormalStream & os) const
100 {
101         os << '[' << name_ << ' ' << delim_ << ']';
102 }
103
104
105 docstring InsetMathBig::mathmlize(MathStream & os) const
106 {
107         os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>";
108         if (delim_ == "(" || delim_ == ")"
109                         || delim_ == "[" || delim_ == "]"
110                         || delim_ == "|" || delim_ == "/")
111                 os << delim_;
112         else if (delim_ == "\\{" || delim_ == "\\lbrace")
113                 os << "{";
114         else if (delim_ == "\\}" || delim_ == "\\rbrace")
115                 os << "}";
116         else if (delim_ == "\\slash")
117                 os << "/";
118         else if (delim_ == "\\|" || delim_ == "\\vert")
119                 os << "|";
120         else if (delim_ == "\\Vert")
121                 os << "&par;";
122         else if (delim_ == "\\\\" || delim_ == "\\backslash")
123                 os <<" \\";
124         else if (delim_ == "\\langle")
125                 os << "&lt;";
126         else if (delim_ == "\\rangle")
127                 os << "&gt;";
128         else if (delim_ == "\\lceil")
129                 os << "&lceil;";
130         else if (delim_ == "\\rceil")
131                 os << "&rceil;";
132         else if (delim_ == "\\lfloor")
133                 os << "&lfloor;";
134         else if (delim_ == "\\rfloor")
135                 os << "&rfloor;";
136         else if (delim_ == "\\downarrow")
137                 os << "&darr;";
138         else if (delim_ == "\\uparrow")
139                 os << "&uarr;";
140         else if (delim_ == "\\Downarrow")
141                 os << "&dArr;";
142         else if (delim_ == "\\Uparrow")
143                 os << "&uArr;";
144         else if (delim_ == "\\updownarrow")
145                 os << "&varr;";
146         else if (delim_ == "\\Updownarrow")
147                 os << "&vArr;";
148         os << "</mo>";
149         return docstring();;
150 }
151
152
153 void InsetMathBig::infoize2(odocstream & os) const
154 {
155         os << name_;
156 }
157
158
159 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
160 {
161         // mathed_draw_deco must handle these
162         static char const * const delimiters[] = {
163                 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
164                 "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
165                 "\\\\", "\\backslash",
166                 "\\langle", "\\lceil", "\\lfloor",
167                 "\\rangle", "\\rceil", "\\rfloor",
168                 "\\downarrow", "\\Downarrow",
169                 "\\uparrow", "\\Uparrow",
170                 "\\updownarrow", "\\Updownarrow", ""
171         };
172         return support::findToken(delimiters, to_utf8(delim)) >= 0;
173 }
174
175
176 } // namespace lyx