From 0355e7d391e05fb67649cd193d31fa20fd994492 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 29 Aug 2002 09:57:57 +0000 Subject: [PATCH] partial framebox support git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5169 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 7 ++++ src/mathed/Makefile.am | 2 ++ src/mathed/math_factory.C | 3 ++ src/mathed/math_fboxinset.h | 2 +- src/mathed/math_frameboxinset.C | 64 +++++++++++++++++++++++++++++++++ src/mathed/math_frameboxinset.h | 34 ++++++++++++++++++ src/mathed/math_parser.C | 9 ++++- 7 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 src/mathed/math_frameboxinset.C create mode 100644 src/mathed/math_frameboxinset.h diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index d55f3f2fdb..63c5e5b92f 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,10 @@ + +2002-08-29 André Pönitz + + * math_framboxinset.[Ch]: new (partial) support for \framebox + + * math_parser.C: generalization for reading optional arguments + 2002-08-26 Lars Gullik Bjønnes * math_parinset.C: add support/LOstream.h and config.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index e8f1d9a53f..bd6215598c 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -65,6 +65,8 @@ libmathed_la_SOURCES = \ math_factory.h \ math_fboxinset.C \ math_fboxinset.h \ + math_frameboxinset.C \ + math_frameboxinset.h \ math_fontinset.C \ math_fontinset.h \ math_fontoldinset.C \ diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index c1604d03d0..0887d0ab94 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -10,6 +10,7 @@ #include "math_dotsinset.h" #include "math_ertinset.h" #include "math_fboxinset.h" +#include "math_frameboxinset.h" #include "math_fontinset.h" #include "math_fontoldinset.h" #include "math_fracinset.h" @@ -218,6 +219,8 @@ MathAtom createMathInset(string const & s) if (s.size() == 3 && s[0] == '\\' && s[1] == '#' && s[2] >= '1' && s[2] <= '9') return MathAtom(new MathMacroArgument(s[2] - '0')); + if (s == "framebox") + return MathAtom(new MathFrameboxInset); if (s == "kern") return MathAtom(new MathKernInset); if (s == "xymatrix") diff --git a/src/mathed/math_fboxinset.h b/src/mathed/math_fboxinset.h index ac84e9a869..3a5029cede 100644 --- a/src/mathed/math_fboxinset.h +++ b/src/mathed/math_fboxinset.h @@ -26,7 +26,7 @@ public: /// void metrics(MathMetricsInfo & mi) const; /// - void draw(MathPainterInfo &, int x, int y) const; + void draw(MathPainterInfo & pi, int x, int y) const; /// void write(WriteStream & os) const; /// write normalized content diff --git a/src/mathed/math_frameboxinset.C b/src/mathed/math_frameboxinset.C new file mode 100644 index 0000000000..d7ab17872f --- /dev/null +++ b/src/mathed/math_frameboxinset.C @@ -0,0 +1,64 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_frameboxinset.h" +#include "math_support.h" +#include "math_mathmlstream.h" +#include "math_streamstr.h" +#include "frontends/Painter.h" + + + +MathFrameboxInset::MathFrameboxInset() + : MathNestInset(2) +{} + + +MathInset * MathFrameboxInset::clone() const +{ + return new MathFrameboxInset(*this); +} + + +void MathFrameboxInset::metrics(MathMetricsInfo & mi) const +{ + w_ = mathed_char_width(mi.base.font, '['); + MathNestInset::metrics(mi); + dim_ = cell(0).dim(); + dim_ += cell(1).dim(); + dim_.w += 2 * w_ + 4; + metricsMarkers2(5); // 5 pixels margin +} + + +void MathFrameboxInset::draw(MathPainterInfo & pi, int x, int y) const +{ + pi.pain.rectangle(x + 1, y - ascent() + 1, width() - 2, height() - 2, + LColor::black); + x += 5; + drawStrBlack(pi, x, y, "["); + x += w_; + cell(0).draw(pi, x, y); + x += cell(0).width(); + drawStrBlack(pi, x, y, "]"); + x += w_ + 4; + cell(1).draw(pi, x, y); +} + + +void MathFrameboxInset::write(WriteStream & os) const +{ + os << "\\framebox"; + if (cell(0).size()) + os << '[' << cell(0) << ']'; + os << '{' << cell(1) << '}'; +} + + +void MathFrameboxInset::normalize(NormalStream & os) const +{ + os << "[framebox " << cell(0) << ' ' << cell(1) << ']'; +} diff --git a/src/mathed/math_frameboxinset.h b/src/mathed/math_frameboxinset.h new file mode 100644 index 0000000000..581ec282f6 --- /dev/null +++ b/src/mathed/math_frameboxinset.h @@ -0,0 +1,34 @@ +// -*- C++ -*- +#ifndef MATH_FRAMEBOXINSET_H +#define MATH_FRAMEBOXINSET_H + +#include "math_nestinset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Extra nesting + \author André Pönitz +*/ + +class MathFrameboxInset : public MathNestInset { +public: + /// + MathFrameboxInset(); + /// + MathInset * clone() const; + /// + void metrics(MathMetricsInfo & mi) const; + /// + void draw(MathPainterInfo & pi, int x, int y) const; + /// + void write(WriteStream & os) const; + /// write normalized content + void normalize(NormalStream & ns) const; +private: + /// width of '[' in current font + mutable int w_; +}; + +#endif diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 35e205b1bd..7e4215d340 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -1149,7 +1149,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, MathInset::mode_type m = mode; if (m == MathInset::UNDECIDED_MODE) m = at->currentMode(); - for (MathInset::idx_type i = 0; i < at->nargs(); ++i) + MathArray opt; + parse(opt, FLAG_OPTION, MathInset::VERBATIM_MODE); + MathInset::idx_type start = 0; + if (opt.size()) { + start = 1; + at.nucleus()->cell(0) = opt; + } + for (MathInset::idx_type i = start; i < at->nargs(); ++i) parse(at.nucleus()->cell(i), FLAG_ITEM, m); cell->push_back(at); } -- 2.39.2