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