]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBig.cpp
Get rid of Inset::setPosCache
[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 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
82 {
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(),
92                          delim);
93 }
94
95
96 void InsetMathBig::write(WriteStream & os) const
97 {
98         MathEnsurer ensurer(os);
99         os << '\\' << name_ << delim_;
100         if (delim_[0] == '\\')
101                 os.pendingSpace(true);
102 }
103
104
105 void InsetMathBig::normalize(NormalStream & os) const
106 {
107         os << '[' << name_ << ' ' << delim_ << ']';
108 }
109
110
111 void InsetMathBig::mathmlize(MathStream & os) const
112 {
113         os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
114            << convertDelimToXMLEscape(delim_)
115            << "</mo>";
116 }
117
118
119 void InsetMathBig::htmlize(HtmlStream & os) const
120 {
121         std::string name;
122         switch (size()) {
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;
127         }
128         os << MTag("span", "class='" + name + "symbol'")
129            << convertDelimToXMLEscape(delim_)
130            << ETag("span");
131 }
132
133
134 void InsetMathBig::infoize2(odocstream & os) const
135 {
136         os << name_;
137 }
138
139
140 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
141 {
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", ""
152         };
153         return support::findToken(delimiters, to_utf8(delim)) >= 0;
154 }
155
156
157 void InsetMathBig::validate(LaTeXFeatures & features) const
158 {
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%;}");
164 }
165
166
167 } // namespace lyx