From 25b1956b2a8f8bf5b4d8393a8aac9c421fc52c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 13 Aug 2004 15:06:46 +0000 Subject: [PATCH] fix some fbox drawing git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8903 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/Makefile.am | 2 + src/mathed/math_boxedinset.C | 77 +++++++++++++++++++++++++++++++++++ src/mathed/math_boxedinset.h | 39 ++++++++++++++++++ src/mathed/math_factory.C | 3 ++ src/mathed/math_fboxinset.C | 4 +- src/mathed/math_fboxinset.h | 4 +- src/mathed/math_parser.C | 11 +---- src/mathed/math_scriptinset.C | 20 ++++----- 8 files changed, 135 insertions(+), 25 deletions(-) create mode 100644 src/mathed/math_boxedinset.C create mode 100644 src/mathed/math_boxedinset.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 19dab36584..18484f5b58 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -25,6 +25,8 @@ libmathed_la_SOURCES = \ math_boldsymbolinset.h \ math_boxinset.C \ math_boxinset.h \ + math_boxedinset.C \ + math_boxedinset.h \ math_braceinset.C \ math_braceinset.h \ math_casesinset.C \ diff --git a/src/mathed/math_boxedinset.C b/src/mathed/math_boxedinset.C new file mode 100644 index 0000000000..df4f2a112d --- /dev/null +++ b/src/mathed/math_boxedinset.C @@ -0,0 +1,77 @@ +/** + * \file math_boxedinset.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "math_boxedinset.h" +#include "math_data.h" +#include "math_mathmlstream.h" +#include "math_parser.h" +#include "math_streamstr.h" +#include "LaTeXFeatures.h" +#include "LColor.h" + +#include "support/std_ostream.h" +#include "frontends/Painter.h" + +using std::auto_ptr; + + +MathBoxedInset::MathBoxedInset() + : MathNestInset(1) +{} + + +auto_ptr MathBoxedInset::clone() const +{ + return auto_ptr(new MathBoxedInset(*this)); +} + + +void MathBoxedInset::metrics(MetricsInfo & mi, Dimension & dim) const +{ + cell(0).metrics(mi, dim); + metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space + dim_ = dim; +} + + +void MathBoxedInset::draw(PainterInfo & pi, int x, int y) const +{ + pi.pain.rectangle(x + 1, y - dim_.ascent() + 1, + dim_.width() - 2, dim_.height() - 2, LColor::foreground); + cell(0).draw(pi, x + 3, y); + setPosCache(pi, x, y); +} + + +void MathBoxedInset::write(WriteStream & os) const +{ + os << "\\boxed{" << cell(0) << '}'; +} + + +void MathBoxedInset::normalize(NormalStream & os) const +{ + os << "[boxed " << cell(0) << ']'; +} + + +void MathBoxedInset::infoize(std::ostream & os) const +{ + os << "Boxed: "; +} + + +void MathBoxedInset::validate(LaTeXFeatures & features) const +{ + features.require("amsmath"); +} + diff --git a/src/mathed/math_boxedinset.h b/src/mathed/math_boxedinset.h new file mode 100644 index 0000000000..f41510f976 --- /dev/null +++ b/src/mathed/math_boxedinset.h @@ -0,0 +1,39 @@ +// -*- C++ -*- +/** + * \file math_boxedinset.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef MATH_BOXEDINSET_H +#define MATH_BOXEDINSET_H + +#include "math_nestinset.h" + + +/// Non-AMS-style frame +class MathBoxedInset : public MathNestInset { +public: + /// + MathBoxedInset(); + /// + std::auto_ptr clone() const; + /// + void validate(LaTeXFeatures & features) const; + /// + void metrics(MetricsInfo & mi, Dimension & dim) const; + /// + void draw(PainterInfo & pi, int x, int y) const; + /// + void write(WriteStream & os) const; + /// write normalized content + void normalize(NormalStream & ns) const; + /// + void infoize(std::ostream & os) const; +}; + +#endif diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index a6d8503f1e..4cb8ebfbc6 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -16,6 +16,7 @@ #include "math_amsarrayinset.h" #include "math_binominset.h" #include "math_boxinset.h" +#include "math_boxedinset.h" #include "math_boldsymbolinset.h" #include "math_casesinset.h" #include "math_colorinset.h" @@ -275,6 +276,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 == "boxed") + return MathAtom(new MathBoxedInset()); if (s == "mbox") return MathAtom(new MathBoxInset("mbox")); if (s == "fbox") diff --git a/src/mathed/math_fboxinset.C b/src/mathed/math_fboxinset.C index a54e64370e..33ab17d14f 100644 --- a/src/mathed/math_fboxinset.C +++ b/src/mathed/math_fboxinset.C @@ -44,7 +44,7 @@ void MathFboxInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, "textnormal"); cell(0).metrics(mi, dim); - metricsMarkers(dim, 5); // 5 pixels margin + metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space dim_ = dim; } @@ -54,7 +54,7 @@ void MathFboxInset::draw(PainterInfo & pi, int x, int y) const pi.pain.rectangle(x + 1, y - dim_.ascent() + 1, dim_.width() - 2, dim_.height() - 2, LColor::foreground); FontSetChanger dummy(pi.base, "textnormal"); - cell(0).draw(pi, x + 5, y); + cell(0).draw(pi, x + 3, y); setPosCache(pi, x, y); } diff --git a/src/mathed/math_fboxinset.h b/src/mathed/math_fboxinset.h index 5527b1cfa6..215eaf4cda 100644 --- a/src/mathed/math_fboxinset.h +++ b/src/mathed/math_fboxinset.h @@ -15,9 +15,7 @@ #include "math_nestinset.h" -class latexkeys; - -/// Extra nesting +/// Non-AMS-style frame class MathFboxInset : public MathNestInset { public: /// diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 3c58bfeb05..087cd2c117 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -144,8 +144,7 @@ enum { FLAG_EQUATION = 1 << 9, // next \] leaves the loop FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop FLAG_OPTION = 1 << 11, // read [...] style option - FLAG_BRACED = 1 << 12, // read {...} style argument - FLAG_SKIPSPACE = 1 << 13 // skip spaces + FLAG_BRACED = 1 << 12 // read {...} style argument }; @@ -585,14 +584,6 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, lyxerr << endl; #endif - if (flags & FLAG_SKIPSPACE) { - if (t.cat() == catSpace || t.cat() == catNewline) - continue; - pop_back(); - return; - } - - if (flags & FLAG_ITEM) { if (t.cat() == catBegin) { diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index 11f858c31a..dffd25c0c9 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -305,12 +305,12 @@ bool MathScriptInset::hasLimits() const void MathScriptInset::removeScript(bool up) { - lyxerr << "MathNestInset::removeScript: 1 up: " << up << endl; + lyxerr << "MathScriptInset::removeScript: 1 up: " << up << endl; if (nargs() == 2) { - lyxerr << "MathNestInset::removeScript: a up: " << up << endl; + lyxerr << "MathScriptInset::removeScript: a up: " << up << endl; if (up == cell_1_is_up_) cells_.pop_back(); - lyxerr << "MathNestInset::removeScript: b up: " << up << endl; + lyxerr << "MathScriptInset::removeScript: b up: " << up << endl; } else if (nargs() == 3) { if (up == true) { swap(cells_[1], cells_[2]); @@ -320,7 +320,7 @@ void MathScriptInset::removeScript(bool up) } cells_.pop_back(); } - lyxerr << "MathNestInset::removeScript: 2 up: " << up << endl; + lyxerr << "MathScriptInset::removeScript: 2 up: " << up << endl; } @@ -557,22 +557,22 @@ void MathScriptInset::notifyCursorLeaves(LCursor & cur) { MathNestInset::notifyCursorLeaves(cur); + lyxerr << "MathScriptInset::notifyCursorLeaves: 1 " << cur << endl; + // remove empty scripts if possible +if (0) { if (nargs() > 2 && cur.idx() == 2 && cell(2).empty()) { // must be a subscript... removeScript(false); - // sanitize cursor, even if this slice will be removed immediately - cur.idx() = 0; - cur.pos() = 0; } else if (nargs() > 1 && cur.idx() == 1 && cell(1).empty()) { // could be either subscript or super script removeScript(cell_1_is_up_); - // sanitize cursor, even if this slice will be removed immediately - cur.idx() = 0; - cur.pos() = 0; } } + lyxerr << "MathScriptInset::notifyCursorLeaves: 2 " << cur << endl; +} + void MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) {