]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathFontOld.cpp
Get rid of Inset::setPosCache
[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         metricsMarkers(mi, dim);
66 }
67
68
69 void InsetMathFontOld::draw(PainterInfo & pi, int x, int y) const
70 {
71         current_mode_ = isTextFont(pi.base.fontname)
72                                 ? TEXT_MODE : MATH_MODE;
73
74         std::string const fontname = current_mode_ == MATH_MODE
75                 ? "math" + font() : "text" + font();// I doubt that this still works
76
77         // When \cal is used in text mode, the font is not changed
78         bool really_change_font = fontname != "textcal";
79
80         Changer dummy = really_change_font ? pi.base.changeFontSet(fontname)
81                 : Changer();
82         cell(0).draw(pi, x + 1, y);
83         drawMarkers(pi, x, y);
84 }
85
86
87 void InsetMathFontOld::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
88 {
89         cell(0).metricsT(mi, dim);
90 }
91
92
93 void InsetMathFontOld::drawT(TextPainter & pain, int x, int y) const
94 {
95         cell(0).drawT(pain, x, y);
96 }
97
98
99 void InsetMathFontOld::write(WriteStream & os) const
100 {
101         os << "{\\" << key_->name << ' ' << cell(0) << '}';
102 }
103
104
105 void InsetMathFontOld::normalize(NormalStream & os) const
106 {
107         os << "[font " << key_->name << ' ' << cell(0) << ']';
108 }
109
110
111 void InsetMathFontOld::infoize(odocstream & os) const
112 {
113         os << bformat(_("Font: %1$s"), key_->name);
114 }
115
116
117 } // namespace lyx