]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.cpp
Merge branch 'betterspacing'
[lyx.git] / src / mathed / InsetMath.cpp
1 /**
2  * \file InsetMath.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetMath.h"
15 #include "MathData.h"
16 #include "MathRow.h"
17 #include "MathStream.h"
18
19 #include "MetricsInfo.h"
20
21 #include "support/debug.h"
22 #include "support/docstream.h"
23 #include "support/gettext.h"
24 #include "support/lassert.h"
25 #include "support/lstrings.h"
26 #include "support/textutils.h"
27
28
29 using namespace std;
30
31 namespace lyx {
32
33 docstring InsetMath::name() const
34 {
35         return from_utf8("Unknown");
36 }
37
38
39 MathData & InsetMath::cell(idx_type)
40 {
41         static MathData dummyCell(&buffer());
42         LYXERR0("I don't have any cell");
43         return dummyCell;
44 }
45
46
47 MathData const & InsetMath::cell(idx_type) const
48 {
49         static MathData dummyCell;
50         LYXERR0("I don't have any cell");
51         return dummyCell;
52 }
53
54
55 MathClass InsetMath::mathClass() const
56 {
57         return MC_ORD;
58 }
59
60
61 bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
62 {
63         MathRow::Element e(MathRow::INSET, mi);
64         e.inset = this;
65         e.mclass = mathClass();
66         mrow.push_back(e);
67         return true;
68 }
69
70 void InsetMath::metricsMarkers(MetricsInfo & mi, Dimension & dim,
71                            int framesize) const
72 {
73         if (!mi.base.macro_nesting)
74                 Inset::metricsMarkers(dim, framesize);
75 }
76
77
78 void InsetMath::metricsMarkers2(MetricsInfo & mi, Dimension & dim,
79                             int framesize) const
80 {
81         if (!mi.base.macro_nesting)
82                 Inset::metricsMarkers2(dim, framesize);
83 }
84
85
86 void InsetMath::drawMarkers(PainterInfo & pi, int x, int y) const
87 {
88         if (!pi.base.macro_nesting)
89                 Inset::drawMarkers(pi, x, y);
90 }
91
92
93 void InsetMath::drawMarkers2(PainterInfo & pi, int x, int y) const
94 {
95         if (!pi.base.macro_nesting)
96                 Inset::drawMarkers2(pi, x, y);
97 }
98
99
100
101 void InsetMath::dump() const
102 {
103         lyxerr << "---------------------------------------------" << endl;
104         odocstringstream os;
105         otexrowstream ots(os);
106         WriteStream wi(ots, false, true, WriteStream::wsDefault);
107         write(wi);
108         lyxerr << to_utf8(os.str());
109         lyxerr << "\n---------------------------------------------" << endl;
110 }
111
112
113 void InsetMath::metricsT(TextMetricsInfo const &, Dimension &) const
114 {
115         LYXERR0("InsetMath::metricsT(Text) called directly!");
116 }
117
118
119 void InsetMath::drawT(TextPainter &, int, int) const
120 {
121         LYXERR0("InsetMath::drawT(Text) called directly!");
122 }
123
124
125 void InsetMath::write(WriteStream & os) const
126 {
127         MathEnsurer ensurer(os);
128         docstring const s = name();
129         os << "\\" << s;
130         // We need an extra ' ' unless this is a single-char-non-ASCII name
131         // or anything non-ASCII follows
132         if (s.size() != 1 || isAlphaASCII(s[0]))
133                 os.pendingSpace(true);
134 }
135
136
137 int InsetMath::plaintext(odocstringstream &, 
138         OutputParams const &, size_t) const
139 {
140         // all math plain text output shall take place in InsetMathHull
141         LATTEST(false);
142         return 0;
143 }
144
145
146 void InsetMath::normalize(NormalStream & os) const
147 {
148         os << '[' << name() << "] ";
149 }
150
151
152 void InsetMath::octave(OctaveStream & os) const
153 {
154         NormalStream ns(os.os());
155         normalize(ns);
156 }
157
158
159 void InsetMath::maple(MapleStream & os) const
160 {
161         NormalStream ns(os.os());
162         normalize(ns);
163 }
164
165
166 void InsetMath::maxima(MaximaStream & os) const
167 {
168         MapleStream ns(os.os());
169         maple(ns);
170 }
171
172
173 void InsetMath::mathematica(MathematicaStream & os) const
174 {
175         NormalStream ns(os.os());
176         normalize(ns);
177 }
178
179
180 void InsetMath::mathmlize(MathStream & os) const
181 {
182         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
183         os << MTag("mi");
184         NormalStream ns(os.os());
185         normalize(ns);
186         os << ETag("mi");
187 }
188
189
190 void InsetMath::htmlize(HtmlStream & os) const
191 {
192         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
193         os << MTag("span", "style='color: red;'");
194         NormalStream ns(os.os());
195         normalize(ns);
196         os << ETag("span");
197 }
198
199
200 HullType InsetMath::getType() const
201 {
202         return hullNone;
203 }
204
205
206 ostream & operator<<(ostream & os, MathAtom const & at)
207 {
208         odocstringstream oss;
209         otexrowstream ots(oss);
210         WriteStream wi(ots, false, false, WriteStream::wsDefault);
211         at->write(wi);
212         return os << to_utf8(oss.str());
213 }
214
215
216 odocstream & operator<<(odocstream & os, MathAtom const & at)
217 {
218         otexrowstream ots(os);
219         WriteStream wi(ots, false, false, WriteStream::wsDefault);
220         at->write(wi);
221         return os;
222 }
223
224
225 } // namespace lyx