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