]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathFontOld.cpp
Improve support for on screen length calculation
[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/lstrings.h"
23
24 #include <ostream>
25
26 using namespace lyx::support;
27
28 namespace lyx {
29
30 InsetMathFontOld::InsetMathFontOld(Buffer * buf, latexkeys const * key)
31         : InsetMathNest(buf, 1), key_(key), current_mode_(TEXT_MODE)
32 {
33         //lock(true);
34 }
35
36
37 Inset * InsetMathFontOld::clone() const
38 {
39         return new InsetMathFontOld(*this);
40 }
41
42
43 void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const
44 {
45         current_mode_ = isTextFont(from_ascii(mi.base.fontname))
46                                 ? TEXT_MODE : MATH_MODE;
47
48         docstring const font = current_mode_ == MATH_MODE
49                                 ? "math" + key_->name : "text" + key_->name;
50
51         // When \cal is used in text mode, the font is not changed
52         bool really_change_font = font != "textcal";
53
54         FontSetChanger dummy(mi.base, font, really_change_font);
55         cell(0).metrics(mi, dim);
56         metricsMarkers(dim);
57 }
58
59
60 void InsetMathFontOld::draw(PainterInfo & pi, int x, int y) const
61 {
62         current_mode_ = isTextFont(from_ascii(pi.base.fontname))
63                                 ? TEXT_MODE : MATH_MODE;
64
65         docstring const font = current_mode_ == MATH_MODE
66                                 ? "math" + key_->name : "text" + key_->name;
67
68         // When \cal is used in text mode, the font is not changed
69         bool really_change_font = font != "textcal";
70
71         FontSetChanger dummy(pi.base, font, really_change_font);
72         cell(0).draw(pi, x + 1, y);
73         drawMarkers(pi, x, y);
74 }
75
76
77 void InsetMathFontOld::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
78 {
79         cell(0).metricsT(mi, dim);
80 }
81
82
83 void InsetMathFontOld::drawT(TextPainter & pain, int x, int y) const
84 {
85         cell(0).drawT(pain, x, y);
86 }
87
88
89 void InsetMathFontOld::write(WriteStream & os) const
90 {
91         os << "{\\" << key_->name << ' ' << cell(0) << '}';
92 }
93
94
95 void InsetMathFontOld::normalize(NormalStream & os) const
96 {
97         os << "[font " << key_->name << ' ' << cell(0) << ']';
98 }
99
100
101 void InsetMathFontOld::infoize(odocstream & os) const
102 {
103         os << bformat(_("Font: %1$s"), key_->name);
104 }
105
106
107 } // namespace lyx