]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSize.cpp
Set correctly the spacing between atoms in MathData
[lyx.git] / src / mathed / InsetMathSize.cpp
1 /**
2  * \file InsetMathSize.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 "InsetMathSize.h"
14
15 #include "LaTeXFeatures.h"
16 #include "MathData.h"
17 #include "MathParser.h"
18 #include "MathStream.h"
19 #include "output_xhtml.h"
20
21 #include "support/convert.h"
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
24
25 #include <string>
26 #include <ostream>
27
28 using namespace lyx::support;
29 using namespace std;
30
31 namespace lyx {
32
33 InsetMathSize::InsetMathSize(Buffer * buf, latexkeys const * l)
34         : InsetMathNest(buf, 1), key_(l), style_(Styles(convert<int>(l->extra)))
35 {}
36
37
38 Inset * InsetMathSize::clone() const
39 {
40         return new InsetMathSize(*this);
41 }
42
43
44 void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
45 {
46         Changer dummy = mi.base.changeStyle(style_);
47         cell(0).metrics(mi, dim);
48         metricsMarkers(dim);
49 }
50
51
52 void InsetMathSize::draw(PainterInfo & pi, int x, int y) const
53 {
54         Changer dummy = pi.base.changeStyle(style_);
55         cell(0).draw(pi, x + 1, y);
56         drawMarkers(pi, x, y);
57 }
58
59
60 void InsetMathSize::write(WriteStream & os) const
61 {
62         MathEnsurer ensurer(os);
63         os << "{\\" << key_->name << ' ' << cell(0) << '}';
64 }
65
66
67 // From the MathML documentation:
68 //      MathML uses two attributes, displaystyle and scriptlevel, to control 
69 //      orthogonal presentation features that TeX encodes into one "style" 
70 //      attribute with values \displaystyle, \textstyle, \scriptstyle, and 
71 //      \scriptscriptstyle. The corresponding values of displaystyle and scriptlevel 
72 //      for those TeX styles would be "true" and "0", "false" and "0", "false" and "1", 
73 //      and "false" and "2", respectively. 
74 void InsetMathSize::mathmlize(MathStream & ms) const
75 {
76         string const & name = to_utf8(key_->name);
77         bool dispstyle = (name == "displaystyle");
78         int scriptlevel = 0;
79         if (name == "scriptstyle")
80                 scriptlevel = 1;
81         else if (name == "scriptscriptstyle")
82                 scriptlevel = 2;
83         stringstream attrs;
84         attrs << "displaystyle='" << (dispstyle ? "true" : "false")
85                 << "' scriptlevel='" << scriptlevel << "'";
86         ms << MTag("mstyle", attrs.str()) << cell(0) << ETag("mstyle");
87 }
88
89
90 void InsetMathSize::htmlize(HtmlStream & os) const
91 {
92         string const & name = to_utf8(key_->name);
93         os <<   MTag("span", "class='" + name + "'")
94                         << cell(0) << ETag("span");
95 }
96
97
98 void InsetMathSize::normalize(NormalStream & os) const
99 {
100         os << '[' << key_->name << ' ' << cell(0) << ']';
101 }
102
103
104 void InsetMathSize::infoize(odocstream & os) const
105 {
106         os << bformat(_("Size: %1$s"), key_->name);
107 }
108
109
110 void InsetMathSize::validate(LaTeXFeatures & features) const
111 {
112         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
113                 features.addCSSSnippet(
114                         "span.displaystyle, span.textstyle{font-size: normal;}\n"
115                         "span.scriptstyle {font-size: small;}\n"
116                         "span.scriptscriptstyle {font-size: x-small;}");
117         InsetMathNest::validate(features);
118 }
119
120 } // namespace lyx