From 8bfa794d285f9fcc8be7da3040c0ac1297e9f756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 7 May 2003 07:46:04 +0000 Subject: [PATCH] Ling Li's makebox support git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6943 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 10 +++++ src/mathed/Makefile.am | 2 + src/mathed/math_boxinset.C | 2 +- src/mathed/math_factory.C | 3 ++ src/mathed/math_makeboxinset.C | 75 ++++++++++++++++++++++++++++++++++ src/mathed/math_makeboxinset.h | 40 ++++++++++++++++++ src/mathed/math_nestinset.C | 4 +- src/mathed/math_parser.C | 2 +- 8 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 src/mathed/math_makeboxinset.C create mode 100644 src/mathed/math_makeboxinset.h diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 491dc3111e..2123e7680d 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,13 @@ +2003-05-06 Ling Li + + * Makefile, math_makeboxinset.[Ch]: + * math_factory.C (createMathInset): + * math_parser.C (parse1): New support for \makebox. + + * math_nestinset.C (drawMarkers, drawMarkers2): + * math_boxinset.C, math_frameboxinset.C (draw): + Fix spacing and marker length. + 2003-05-03 John Levon * formula.C: diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 423995cbb8..b5bf583d50 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -100,6 +100,8 @@ libmathed_la_SOURCES = \ math_macrotemplate.h \ math_macrotable.C \ math_macrotable.h \ + math_makeboxinset.C \ + math_makeboxinset.h \ math_mathmlstream.C \ math_mathmlstream.h \ math_matrixinset.C \ diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C index 29c5e2c727..f479ae2470 100644 --- a/src/mathed/math_boxinset.C +++ b/src/mathed/math_boxinset.C @@ -46,7 +46,7 @@ void MathBoxInset::draw(PainterInfo & pi, int x, int y) const { FontSetChanger dummy(pi.base, "textnormal"); cell(0).draw(pi, x, y); - drawMarkers2(pi, x + 1, y); + drawMarkers2(pi, x, y); } diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index b0fa5e7dff..1ccb5829dc 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -22,6 +22,7 @@ #include "math_macrotable.h" #include "math_macrotemplate.h" #include "math_macroarg.h" +#include "math_makeboxinset.h" #include "math_parboxinset.h" #include "math_rootinset.h" #include "math_sizeinset.h" @@ -259,6 +260,8 @@ MathAtom createMathInset(string const & s) return MathAtom(new MathMacroArgument(s[2] - '0')); if (s == "framebox") return MathAtom(new MathFrameboxInset); + if (s == "makebox") + return MathAtom(new MathMakeboxInset); if (s == "kern") return MathAtom(new MathKernInset); if (s == "xymatrix") diff --git a/src/mathed/math_makeboxinset.C b/src/mathed/math_makeboxinset.C new file mode 100644 index 0000000000..730604a58d --- /dev/null +++ b/src/mathed/math_makeboxinset.C @@ -0,0 +1,75 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_makeboxinset.h" +#include "math_support.h" +#include "math_mathmlstream.h" +#include "math_streamstr.h" +#include "frontends/Painter.h" + + + +MathMakeboxInset::MathMakeboxInset() + : MathNestInset(3) +{} + + +MathInset * MathMakeboxInset::clone() const +{ + return new MathMakeboxInset(*this); +} + + +void MathMakeboxInset::metrics(MetricsInfo & mi) const +{ + FontSetChanger dummy(mi.base, "textnormal"); + w_ = mathed_char_width(mi.base.font, '['); + MathNestInset::metrics(mi); + dim_ = cell(0).dim(); + dim_ += cell(1).dim(); + dim_ += cell(2).dim(); + dim_.w += 4 * w_ + 4; + metricsMarkers2(); +} + + +void MathMakeboxInset::draw(PainterInfo & pi, int x, int y) const +{ + FontSetChanger dummy(pi.base, "textnormal"); + drawMarkers2(pi, x, y); + + drawStrBlack(pi, x, y, "["); + x += w_; + cell(0).draw(pi, x, y); + x += cell(0).width(); + drawStrBlack(pi, x, y, "]"); + x += w_ + 2; + + drawStrBlack(pi, x, y, "["); + x += w_; + cell(1).draw(pi, x, y); + x += cell(1).width(); + drawStrBlack(pi, x, y, "]"); + x += w_ + 2; + + cell(2).draw(pi, x, y); +} + + +void MathMakeboxInset::write(WriteStream & os) const +{ + os << "\\makebox"; + os << '[' << cell(0) << ']'; + if (cell(1).size()) + os << '[' << cell(1) << ']'; + os << '{' << cell(2) << '}'; +} + + +void MathMakeboxInset::normalize(NormalStream & os) const +{ + os << "[makebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']'; +} diff --git a/src/mathed/math_makeboxinset.h b/src/mathed/math_makeboxinset.h new file mode 100644 index 0000000000..f93de06c11 --- /dev/null +++ b/src/mathed/math_makeboxinset.h @@ -0,0 +1,40 @@ +// -*- C++ -*- +#ifndef MATH_MAKEBOXINSET_H +#define MATH_MAKEBOXINSET_H + +#include "math_nestinset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Extra nesting: \\makebox. + * \author Ling Li + * + * Full author contact details are available in file CREDITS + */ + +// consolidate with MathFrameboxInset? + +class MathMakeboxInset : public MathNestInset { +public: + /// + MathMakeboxInset(); + /// + MathInset * clone() const; + /// + void metrics(MetricsInfo & mi) const; + /// + void draw(PainterInfo & pi, int x, int y) const; + /// + void write(WriteStream & os) const; + /// write normalized content + void normalize(NormalStream & ns) const; + /// + mode_type currentMode() const { return TEXT_MODE; } +private: + /// width of '[' in current font + mutable int w_; +}; + +#endif diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 44649e2cdc..b4163ca3e7 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -201,7 +201,7 @@ void MathNestInset::drawMarkers(PainterInfo & pi, int x, int y) const pi.pain.line(x, d - 3, x, d, LColor::mathframe); pi.pain.line(t, d - 3, t, d, LColor::mathframe); pi.pain.line(x, d, x + 3, d, LColor::mathframe); - pi.pain.line(t - 2, d, t, d, LColor::mathframe); + pi.pain.line(t - 3, d, t, d, LColor::mathframe); } @@ -215,7 +215,7 @@ void MathNestInset::drawMarkers2(PainterInfo & pi, int x, int y) const pi.pain.line(x, a + 3, x, a, LColor::mathframe); pi.pain.line(t, a + 3, t, a, LColor::mathframe); pi.pain.line(x, a, x + 3, a, LColor::mathframe); - pi.pain.line(t - 2, a, t, a, LColor::mathframe); + pi.pain.line(t - 3, a, t, a, LColor::mathframe); } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 947655d85b..2d150149b8 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -1138,7 +1138,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, parse2(cell->back(), FLAG_ITEM, mode, false); } - else if (t.cs() == "framebox") { + else if (t.cs() == "framebox" || t.cs() == "makebox") { cell->push_back(createMathInset(t.cs())); parse(cell->back().nucleus()->cell(0), FLAG_OPTION, MathInset::TEXT_MODE); parse(cell->back().nucleus()->cell(1), FLAG_OPTION, MathInset::TEXT_MODE);