]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathFontOld.cpp
Account for old versions of Pygments
[lyx.git] / src / mathed / InsetMathFontOld.cpp
1 /**
2  * \file InsetMathFontOld.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 "InsetMathFontOld.h"
14
15 #include "MathData.h"
16 #include "MathParser.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19 #include "MetricsInfo.h"
20
21 #include "support/gettext.h"
22 #include "support/lassert.h"
23 #include "support/lstrings.h"
24
25 #include <ostream>
26
27 using namespace lyx::support;
28
29 namespace lyx {
30
31 InsetMathFontOld::InsetMathFontOld(Buffer * buf, latexkeys const * key)
32         : InsetMathNest(buf, 1), key_(key), current_mode_(TEXT_MODE)
33 {
34         //lock(true);
35 }
36
37
38 std::string InsetMathFontOld::font() const
39 {
40         LASSERT(isAscii(key_->name), return "mathnormal");
41         return to_ascii(key_->name);
42 }
43
44
45 Inset * InsetMathFontOld::clone() const
46 {
47         return new InsetMathFontOld(*this);
48 }
49
50
51 void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const
52 {
53         current_mode_ = isTextFont(mi.base.fontname)
54                                 ? TEXT_MODE : MATH_MODE;
55
56         std::string const fontname = current_mode_ == MATH_MODE
57                 ? "math" + font() : "text" + font();// I doubt that this still works
58
59         // When \cal is used in text mode, the font is not changed
60         bool really_change_font = fontname != "textcal";
61
62         Changer dummy = really_change_font ? mi.base.changeFontSet(fontname)
63                 : Changer();
64         cell(0).metrics(mi, dim);
65 }
66
67
68 void InsetMathFontOld::draw(PainterInfo & pi, int x, int y) const
69 {
70         current_mode_ = isTextFont(pi.base.fontname)
71                                 ? TEXT_MODE : MATH_MODE;
72
73         std::string const fontname = current_mode_ == MATH_MODE
74                 ? "math" + font() : "text" + font();// I doubt that this still works
75
76         // When \cal is used in text mode, the font is not changed
77         bool really_change_font = fontname != "textcal";
78
79         Changer dummy = really_change_font ? pi.base.changeFontSet(fontname)
80                 : Changer();
81         cell(0).draw(pi, x, y);
82 }
83
84
85 void InsetMathFontOld::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
86 {
87         cell(0).metricsT(mi, dim);
88 }
89
90
91 void InsetMathFontOld::drawT(TextPainter & pain, int x, int y) const
92 {
93         cell(0).drawT(pain, x, y);
94 }
95
96
97 void InsetMathFontOld::write(WriteStream & os) const
98 {
99         os << "{\\" << key_->name << ' ' << cell(0) << '}';
100 }
101
102
103 void InsetMathFontOld::normalize(NormalStream & os) const
104 {
105         os << "[font " << key_->name << ' ' << cell(0) << ']';
106 }
107
108
109 void InsetMathFontOld::infoize(odocstream & os) const
110 {
111         os << bformat(_("Font: %1$s"), key_->name);
112 }
113
114
115 } // namespace lyx