2 * \file InsetMathBrace.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathBrace.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
18 #include "MetricsInfo.h"
20 #include "frontends/FontMetrics.h"
21 #include "frontends/Painter.h"
30 InsetMathBrace::InsetMathBrace(Buffer * buf)
31 : InsetMathNest(buf, 1), current_mode_(UNDECIDED_MODE)
35 InsetMathBrace::InsetMathBrace(MathData const & ar)
36 : InsetMathNest(const_cast<Buffer *>(ar.buffer()), 1),
37 current_mode_(UNDECIDED_MODE)
43 Inset * InsetMathBrace::clone() const
45 return new InsetMathBrace(*this);
49 void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const
51 current_mode_ = isTextFont(mi.base.fontname) ? TEXT_MODE : MATH_MODE;
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;
63 void InsetMathBrace::draw(PainterInfo & pi, int x, int y) const
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);
78 void InsetMathBrace::write(TeXMathStream & os) const
80 os << '{' << cell(0) << '}';
84 void InsetMathBrace::normalize(NormalStream & os) const
86 os << "[block " << cell(0) << ']';
90 void InsetMathBrace::maple(MapleStream & os) const
96 void InsetMathBrace::octave(OctaveStream & os) const
102 void InsetMathBrace::mathmlize(MathMLStream & ms) const
104 ms << MTag("mrow") << cell(0) << ETag("mrow");
108 void InsetMathBrace::htmlize(HtmlStream & os) const
114 void InsetMathBrace::mathematica(MathematicaStream & os) const
120 void InsetMathBrace::infoize(odocstream & os) const
122 os << "Nested Block: ";