]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBrace.cpp
Amend 6c3447c8: FindAdv: sometimes a space is added on some math symbols
[lyx.git] / src / mathed / InsetMathBrace.cpp
1 /**
2  * \file InsetMathBrace.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 "InsetMathBrace.h"
14
15 #include "MathData.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
18 #include "MetricsInfo.h"
19
20 #include "frontends/FontMetrics.h"
21 #include "frontends/Painter.h"
22
23 #include <ostream>
24 #include <algorithm>
25
26 using namespace std;
27
28 namespace lyx {
29
30 InsetMathBrace::InsetMathBrace(Buffer * buf)
31         : InsetMathNest(buf, 1), current_mode_(UNDECIDED_MODE)
32 {}
33
34
35 InsetMathBrace::InsetMathBrace(Buffer * buf, MathData const & ar)
36         : InsetMathNest(buf, 1),
37           current_mode_(UNDECIDED_MODE)
38 {
39         cell(0) = ar;
40 }
41
42
43 Inset * InsetMathBrace::clone() const
44 {
45         return new InsetMathBrace(*this);
46 }
47
48
49 void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const
50 {
51         current_mode_ = isTextFont(mi.base.fontname) ? TEXT_MODE : MATH_MODE;
52         Dimension dim0;
53         cell(0).metrics(mi, dim0);
54         FontInfo font = mi.base.font;
55         augmentFont(font, current_mode_ == MATH_MODE ? "mathnormal" : "text");
56         Dimension t = theFontMetrics(font).dimension('{');
57         dim.asc = max(dim0.asc, t.asc);
58         dim.des = max(dim0.des, t.des);
59         dim.wid = dim0.width() + 2 * t.wid;
60 }
61
62
63 void InsetMathBrace::draw(PainterInfo & pi, int x, int y) const
64 {
65         current_mode_ = isTextFont(pi.base.fontname) ? TEXT_MODE : MATH_MODE;
66         FontInfo font = pi.base.font;
67         augmentFont(font, current_mode_ == MATH_MODE ? "mathnormal" : "text");
68         font.setShape(UP_SHAPE);
69         font.setColor(Color_latex);
70         Dimension t = theFontMetrics(font).dimension('{');
71         pi.pain.text(x, y, '{', font);
72         cell(0).draw(pi, x + t.wid, y);
73         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
74         pi.pain.text(x + t.wid + dim0.width(), y, '}', font);
75 }
76
77
78 void InsetMathBrace::write(TeXMathStream & os) const
79 {
80         os << '{' << cell(0) << '}';
81 }
82
83
84 void InsetMathBrace::normalize(NormalStream & os) const
85 {
86         os << "[block " << cell(0) << ']';
87 }
88
89
90 void InsetMathBrace::maple(MapleStream & os) const
91 {
92         os << cell(0);
93 }
94
95
96 void InsetMathBrace::octave(OctaveStream & os) const
97 {
98         os << cell(0);
99 }
100
101
102 void InsetMathBrace::mathmlize(MathMLStream & ms) const
103 {
104         ms << MTag("mrow") << cell(0) << ETag("mrow");
105 }
106
107
108 void InsetMathBrace::htmlize(HtmlStream & os) const
109 {
110         os << cell(0);
111 }
112
113
114 void InsetMathBrace::mathematica(MathematicaStream & os) const
115 {
116         os << cell(0);
117 }
118
119
120 void InsetMathBrace::infoize(odocstream & os) const
121 {
122         os << "Nested Block: ";
123 }
124
125
126 } // namespace lyx