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