]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathString.cpp
ef403f452a8f0610b2ea7490930e3d19d6a42c73
[lyx.git] / src / mathed / InsetMathString.cpp
1 /**
2  * \file InsetMathString.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 "InsetMathString.h"
14
15 #include "MathFactory.h"
16 #include "MathExtern.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19
20 #include "Encoding.h"
21 #include "MetricsInfo.h"
22
23 #include "support/debug.h"
24 #include "support/gettext.h"
25 #include "support/lassert.h"
26 #include "support/lstrings.h"
27 #include "support/textutils.h"
28
29 using lyx::support::escape;
30
31
32 namespace lyx {
33
34 InsetMathString::InsetMathString(docstring const & s)
35         : str_(s)
36 {}
37
38
39 Inset * InsetMathString::clone() const
40 {
41         return new InsetMathString(*this);
42 }
43
44
45 void InsetMathString::metrics(MetricsInfo & mi, Dimension & dim) const
46 {
47         mathed_string_dim(mi.base.font, str_, dim);
48 }
49
50
51 void InsetMathString::draw(PainterInfo & pi, int x, int y) const
52 {
53         pi.draw(x, y, str_);
54 }
55
56
57 void InsetMathString::normalize(NormalStream & os) const
58 {
59         os << "[string " << str_ << ' ' << "mathalpha" << ']';
60 }
61
62
63 void InsetMathString::maple(MapleStream & os) const
64 {
65         if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
66                 os << ' ' << str_ << ' ';
67                 return;
68         }
69
70         // insert '*' between adjacent chars if type is LM_TC_VAR
71         os << str_[0];
72         for (size_t i = 1; i < str_.size(); ++i)
73                 os << str_[i];
74 }
75
76
77 void InsetMathString::mathematica(MathematicaStream & os) const
78 {
79         os << ' ' << str_ << ' ';
80 }
81
82
83 void InsetMathString::octave(OctaveStream & os) const
84 {
85         if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
86                 os << ' ' << str_ << ' ';
87                 return;
88         }
89
90         // insert '*' between adjacent chars if type is LM_TC_VAR
91         os << str_[0];
92         for (size_t i = 1; i < str_.size(); ++i)
93                 os << str_[i];
94 }
95
96
97 void InsetMathString::mathmlize(MathMLStream &) const
98 {
99         // useless, no doubt, but we should not be here
100         LATTEST(false);
101 }
102
103
104 void InsetMathString::write(WriteStream & os) const
105 {
106         writeString(str_, os);
107 }
108
109
110 } // namespace lyx