From: André Pönitz Date: Wed, 17 Jul 2002 10:25:33 +0000 (+0000) Subject: fixes for \xxalignat and old style font changes X-Git-Tag: 1.6.10~18846 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=baf8d2da9f597105e9f698fe54fcf61574b8665e;p=features.git fixes for \xxalignat and old style font changes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4673 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index cad384f547..b8ecffc96f 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -63,6 +63,8 @@ libmathed_la_SOURCES = \ math_fboxinset.h \ math_fontinset.C \ math_fontinset.h \ + math_fontoldinset.C \ + math_fontoldinset.h \ math_fracinset.C \ math_fracinset.h \ math_fracbase.C \ diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 345669b828..f1f6c90ff7 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -40,7 +40,9 @@ #include "Lsstream.h" #include "math_arrayinset.h" #include "math_charinset.h" +#include "math_deliminset.h" #include "math_cursor.h" +#include "math_factory.h" #include "math_fontinset.h" #include "math_hullinset.h" #include "math_iterator.h" @@ -127,7 +129,7 @@ void InsetFormulaBase::handleFont bool sel = mathcursor->selection(); if (sel) updateLocal(bv, true); - mathcursor->handleNest(new MathFontInset(font)); + mathcursor->handleNest(createMathInset(font)); mathcursor->insert(arg); if (!sel) updateLocal(bv, false); @@ -665,7 +667,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, rs = ')'; bv->lockedInsetStoreUndo(Undo::EDIT); - mathcursor->handleDelim(ls, rs); + mathcursor->handleNest(MathAtom(new MathDelimInset(ls, rs))); updateLocal(bv, true); break; } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index e8c887262d..ee80f37862 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -35,7 +35,6 @@ #include "math_boxinset.h" #include "math_casesinset.h" #include "math_charinset.h" -#include "math_deliminset.h" #include "math_extern.h" #include "math_factory.h" #include "math_fboxinset.h" @@ -703,16 +702,10 @@ void MathCursor::drawSelection(MathPainterInfo & pain) const } -void MathCursor::handleDelim(string const & l, string const & r) +void MathCursor::handleNest(MathAtom const & at) { - handleNest(new MathDelimInset(l, r)); -} - - -void MathCursor::handleNest(MathInset * p) -{ - p->cell(0) = grabAndEraseSelection().glue(); - insert(MathAtom(p)); // this invalidates p! + at->cell(0) = grabAndEraseSelection().glue(); + insert(at); pushRight(prevAtom()); } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 96d0348085..d00b294273 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -165,9 +165,7 @@ public: /// void drawSelection(MathPainterInfo & pain) const; /// - void handleDelim(string const & l, string const & r); - /// - void handleNest(MathInset * p); + void handleNest(MathAtom const & at); /// splits cells and shifts right part to the next cell void splitCell(); /// splits line and insert new row of cell diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index e6982a3fd8..ab9240d0e3 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -12,8 +12,8 @@ #include "support/LOstream.h" -MathDecorationInset::MathDecorationInset(string const & name) - : MathNestInset(1), name_(name) +MathDecorationInset::MathDecorationInset(latexkeys const * key) + : MathNestInset(1), key_(key) {} @@ -25,53 +25,53 @@ MathInset * MathDecorationInset::clone() const bool MathDecorationInset::upper() const { - return name_.substr(0, 5) != "under"; + return key_->name.substr(0, 5) != "under"; } bool MathDecorationInset::isScriptable() const { return - name_ == "overbrace" || - name_ == "underbrace" || - name_ == "overleftarrow" || - name_ == "overrightarrow" || - name_ == "overleftrightarrow" || - name_ == "underleftarrow" || - name_ == "underrightarrow" || - name_ == "underleftrightarrow"; + key_->name == "overbrace" || + key_->name == "underbrace" || + key_->name == "overleftarrow" || + key_->name == "overrightarrow" || + key_->name == "overleftrightarrow" || + key_->name == "underleftarrow" || + key_->name == "underrightarrow" || + key_->name == "underleftrightarrow"; } bool MathDecorationInset::protect() const { return - name_ == "overbrace" || - name_ == "underbrace" || - name_ == "overleftarrow" || - name_ == "overrightarrow" || - name_ == "overleftrightarrow" || - name_ == "underleftarrow" || - name_ == "underrightarrow" || - name_ == "underleftrightarrow"; + key_->name == "overbrace" || + key_->name == "underbrace" || + key_->name == "overleftarrow" || + key_->name == "overrightarrow" || + key_->name == "overleftrightarrow" || + key_->name == "underleftarrow" || + key_->name == "underrightarrow" || + key_->name == "underleftrightarrow"; } bool MathDecorationInset::wide() const { return - name_ == "overline" || - name_ == "underline" || - name_ == "overbrace" || - name_ == "underbrace" || - name_ == "overleftarrow" || - name_ == "overrightarrow" || - name_ == "overleftrightarrow" || - name_ == "widehat" || - name_ == "widetilde" || - name_ == "underleftarrow" || - name_ == "underrightarrow" || - name_ == "underleftrightarrow"; + key_->name == "overline" || + key_->name == "underline" || + key_->name == "overbrace" || + key_->name == "underbrace" || + key_->name == "overleftarrow" || + key_->name == "overrightarrow" || + key_->name == "overleftrightarrow" || + key_->name == "widehat" || + key_->name == "widetilde" || + key_->name == "underleftarrow" || + key_->name == "underrightarrow" || + key_->name == "underleftrightarrow"; } @@ -98,9 +98,9 @@ void MathDecorationInset::draw(MathPainterInfo & pi, int x, int y) const { xcell(0).draw(pi, x + 1, y); if (wide()) - mathed_draw_deco(pi, x + 1, y + dy_, width(), dh_, name_); + mathed_draw_deco(pi, x + 1, y + dy_, width(), dh_, key_->name); else - mathed_draw_deco(pi, x + 1 + (width() - dw_) / 2, y + dy_, dw_, dh_, name_); + mathed_draw_deco(pi, x + 1 + (width() - dw_) / 2, y + dy_, dw_, dh_, key_->name); drawMarkers(pi, x, y); } @@ -109,17 +109,17 @@ void MathDecorationInset::write(WriteStream & os) const { if (os.fragile() && protect()) os << "\\protect"; - os << '\\' << name_ << '{' << cell(0) << '}'; + os << '\\' << key_->name << '{' << cell(0) << '}'; } void MathDecorationInset::normalize(NormalStream & os) const { - os << "[deco " << name_ << ' ' << cell(0) << ']'; + os << "[deco " << key_->name << ' ' << cell(0) << ']'; } void MathDecorationInset::infoize(std::ostream & os) const { - os << "Deco: " << name_; + os << "Deco: " << key_->name; } diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index e0e03650cf..da265685f3 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -13,10 +13,12 @@ \author Alejandro Aguilar Sierra */ +class latexkeys; + class MathDecorationInset : public MathNestInset { public: /// - explicit MathDecorationInset(string const & name); + explicit MathDecorationInset(latexkeys const * key); /// MathInset * clone() const; /// @@ -41,7 +43,7 @@ private: bool wide() const; /// - string const name_; + latexkeys const * key_; /// height cache of deco mutable int dh_; /// vertical offset cache of deco diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index da83db3178..83363d8bb0 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -8,10 +8,11 @@ #include "math_mathmlstream.h" #include "math_streamstr.h" #include "math_support.h" +#include "math_parser.h" -MathDotsInset::MathDotsInset(string const & name) - : name_(name) +MathDotsInset::MathDotsInset(latexkeys const * key) + : key_(key) {} @@ -24,38 +25,38 @@ MathInset * MathDotsInset::clone() const void MathDotsInset::metrics(MathMetricsInfo & mi) const { mathed_char_dim(mi.base.font, 'M', dim_); - if (name_ == "ldots" || name_ == "dotsm") + if (key_->name == "ldots" || key_->name == "dotsm") dh_ = 0; - else if (name_ == "cdots" || name_ == "dotsb" - || name_ == "dotsm" || name_ == "dotsi") + else if (key_->name == "cdots" || key_->name == "dotsb" + || key_->name == "dotsm" || key_->name == "dotsi") dh_ = ascent() / 2; - else if (name_ == "dotsc") + else if (key_->name == "dotsc") dh_ = ascent() / 4; - else if (name_ == "vdots") + else if (key_->name == "vdots") dim_.w /= 2; - else if (name_ == "ddots") + else if (key_->name == "ddots") dh_ = ascent(); } void MathDotsInset::draw(MathPainterInfo & pain, int x, int y) const { - mathed_draw_deco(pain, x + 2, y - dh_, width() - 2, ascent(), name_); - if (name_ == "vdots" || name_ == "ddots") + mathed_draw_deco(pain, x + 2, y - dh_, width() - 2, ascent(), key_->name); + if (key_->name == "vdots" || key_->name == "ddots") ++x; - if (name_ != "vdots") + if (key_->name != "vdots") --y; - mathed_draw_deco(pain, x + 2, y - dh_, width() - 2, ascent(), name_); + mathed_draw_deco(pain, x + 2, y - dh_, width() - 2, ascent(), key_->name); } void MathDotsInset::write(WriteStream & os) const { - os << '\\' << name_ << ' '; + os << '\\' << key_->name << ' '; } void MathDotsInset::normalize(NormalStream & os) const { - os << "[" << name_ << "] "; + os << "[" << key_->name << "] "; } diff --git a/src/mathed/math_dotsinset.h b/src/mathed/math_dotsinset.h index be37fb641b..d0187a0804 100644 --- a/src/mathed/math_dotsinset.h +++ b/src/mathed/math_dotsinset.h @@ -3,17 +3,18 @@ #define MATH_DOTSINSET_H #include "math_diminset.h" -#include "LString.h" #ifdef __GNUG__ #pragma interface #endif +class latexkeys; + /// The different kinds of ellipsis class MathDotsInset : public MathDimInset { public: /// - explicit MathDotsInset(string const &); + explicit MathDotsInset(latexkeys const * l); /// MathInset * clone() const; /// @@ -28,6 +29,6 @@ protected: /// cache for the thing's heigth mutable int dh_; /// - string const name_; + latexkeys const * key_; }; #endif diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index 18c2bd90bb..f328ed3a57 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -10,6 +10,7 @@ #include "math_dotsinset.h" #include "math_fboxinset.h" #include "math_fontinset.h" +#include "math_fontoldinset.h" #include "math_fracinset.h" #include "math_kerninset.h" #include "math_lefteqninset.h" @@ -222,11 +223,11 @@ MathAtom createMathInset(string const & s) if (inset == "underset") return MathAtom(new MathUndersetInset); if (inset == "decoration") - return MathAtom(new MathDecorationInset(l->name)); + return MathAtom(new MathDecorationInset(l)); if (inset == "space") return MathAtom(new MathSpaceInset(l->name)); if (inset == "dots") - return MathAtom(new MathDotsInset(l->name)); + return MathAtom(new MathDotsInset(l)); if (inset == "mbox") return MathAtom(new MathBoxInset(l->name)); if (inset == "parbox") @@ -236,9 +237,9 @@ MathAtom createMathInset(string const & s) if (inset == "style") return MathAtom(new MathSizeInset(l)); if (inset == "font") - return MathAtom(new MathFontInset(l->name)); + return MathAtom(new MathFontInset(l)); if (inset == "oldfont") - return MathAtom(new MathFontInset(l->name)); + return MathAtom(new MathFontOldInset(l)); if (inset == "matrix") return MathAtom(new MathAMSArrayInset(s)); return MathAtom(new MathSymbolInset(l)); diff --git a/src/mathed/math_fontinset.C b/src/mathed/math_fontinset.C index ceb1143760..9b1536ac91 100644 --- a/src/mathed/math_fontinset.C +++ b/src/mathed/math_fontinset.C @@ -9,14 +9,15 @@ #include "math_mathmlstream.h" #include "math_streamstr.h" #include "math_support.h" +#include "math_parser.h" #include "LaTeXFeatures.h" #include "textpainter.h" #include "frontends/Painter.h" -MathFontInset::MathFontInset(string const & name) - : MathNestInset(1), name_(name) +MathFontInset::MathFontInset(latexkeys const * key) + : MathNestInset(1), key_(key) { //lock(true); } @@ -30,7 +31,7 @@ MathInset * MathFontInset::clone() const void MathFontInset::metrics(MathMetricsInfo & mi) const { - MathFontSetChanger dummy(mi.base, name_.c_str()); + MathFontSetChanger dummy(mi.base, key_->name.c_str()); dim_ = xcell(0).metrics(mi); metricsMarkers(); } @@ -40,7 +41,7 @@ void MathFontInset::draw(MathPainterInfo & pi, int x, int y) const { //lyxerr << "MathFontInset::draw\n"; //MathNestInset::draw(pi, x, y); - MathFontSetChanger dummy(pi.base, name_.c_str()); + MathFontSetChanger dummy(pi.base, key_->name.c_str()); xcell(0).draw(pi, x + 1, y); drawMarkers(pi, x, y); } @@ -61,13 +62,13 @@ void MathFontInset::drawT(TextPainter & pain, int x, int y) const void MathFontInset::write(WriteStream & os) const { - os << '\\' << name_ << '{' << cell(0) << '}'; + os << '\\' << key_->name << '{' << cell(0) << '}'; } void MathFontInset::normalize(NormalStream & os) const { - os << "[font_ " << name_ << " " << cell(0) << "]"; + os << "[font " << key_->name << " " << cell(0) << "]"; } @@ -75,12 +76,12 @@ void MathFontInset::validate(LaTeXFeatures & features) const { // Make sure amssymb is put in preamble if Blackboard Bold or // Fraktur used: - if (name_ == "mathfrak" || name_ == "mathbb") + if (key_->name == "mathfrak" || key_->name == "mathbb") features.require("amssymb"); } void MathFontInset::infoize(std::ostream & os) const { - os << "Font: " << name_; + os << "Font: " << key_->name; } diff --git a/src/mathed/math_fontinset.h b/src/mathed/math_fontinset.h index a07f2ad02e..5b0dfdd427 100644 --- a/src/mathed/math_fontinset.h +++ b/src/mathed/math_fontinset.h @@ -3,21 +3,21 @@ #define MATH_FONTINSET_H #include "math_nestinset.h" -#include "LString.h" -#include "lyxfont.h" #ifdef __GNUG__ #pragma interface #endif -/** The base character inset. +/** Inset for font changes \author André Pönitz */ +class latexkeys; + class MathFontInset : public MathNestInset { public: /// - explicit MathFontInset(string const & name); + explicit MathFontInset(latexkeys const * key); /// MathInset * clone() const; /// @@ -32,8 +32,6 @@ public: void write(WriteStream & os) const; /// void normalize(NormalStream &) const; - /// identifies Fontinsets - MathFontInset const * asFontInset() const { return this; } /// void validate(LaTeXFeatures & features) const; /// @@ -41,6 +39,6 @@ public: private: /// the font to be used on screen - string name_; + latexkeys const * key_; }; #endif diff --git a/src/mathed/math_fontoldinset.C b/src/mathed/math_fontoldinset.C new file mode 100644 index 0000000000..aa37571a98 --- /dev/null +++ b/src/mathed/math_fontoldinset.C @@ -0,0 +1,73 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_fontoldinset.h" +#include "math_mathmlstream.h" +#include "math_streamstr.h" +#include "math_support.h" +#include "math_parser.h" +#include "textpainter.h" +#include "frontends/Painter.h" + + + +MathFontOldInset::MathFontOldInset(latexkeys const * key) + : MathNestInset(1), key_(key) +{ + //lock(true); +} + + +MathInset * MathFontOldInset::clone() const +{ + return new MathFontOldInset(*this); +} + + +void MathFontOldInset::metrics(MathMetricsInfo & mi) const +{ + MathFontSetChanger dummy(mi.base, key_->name.c_str()); + dim_ = xcell(0).metrics(mi); + metricsMarkers(); +} + + +void MathFontOldInset::draw(MathPainterInfo & pi, int x, int y) const +{ + MathFontSetChanger dummy(pi.base, key_->name.c_str()); + xcell(0).draw(pi, x + 1, y); + drawMarkers(pi, x, y); +} + + +void MathFontOldInset::metricsT(TextMetricsInfo const & mi) const +{ + dim_ = xcell(0).metricsT(mi); +} + + +void MathFontOldInset::drawT(TextPainter & pain, int x, int y) const +{ + xcell(0).drawT(pain, x, y); +} + + +void MathFontOldInset::write(WriteStream & os) const +{ + os << "{\\" << key_->name << ' ' << cell(0) << '}'; +} + + +void MathFontOldInset::normalize(NormalStream & os) const +{ + os << "[font " << key_->name << " " << cell(0) << "]"; +} + + +void MathFontOldInset::infoize(std::ostream & os) const +{ + os << "Font: " << key_->name; +} diff --git a/src/mathed/math_fontoldinset.h b/src/mathed/math_fontoldinset.h new file mode 100644 index 0000000000..14a42cc58f --- /dev/null +++ b/src/mathed/math_fontoldinset.h @@ -0,0 +1,44 @@ +// -*- C++ -*- +#ifndef MATH_FONTOLDINSET_H +#define MATH_FONTOLDINSET_H + +#include "math_nestinset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Old-style font changes + \author André Pönitz + */ + +class latexkeys; + +class MathFontOldInset : public MathNestInset { +public: + /// + explicit MathFontOldInset(latexkeys const * key); + /// + MathInset * clone() const; + /// we write extra braces in any case... + bool extraBraces() const { return true; } + /// + void metrics(MathMetricsInfo & mi) const; + /// + void draw(MathPainterInfo & pi, int x, int y) const; + /// + void metricsT(TextMetricsInfo const & mi) const; + /// + void drawT(TextPainter & pi, int x, int y) const; + /// + void write(WriteStream & os) const; + /// + void normalize(NormalStream &) const; + /// + void infoize(std::ostream & os) const; + +private: + /// the font to be used on screen + latexkeys const * key_; +}; +#endif diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 63fb2495c2..b51cc4760d 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -352,11 +352,11 @@ void MathHullInset::header_write(WriteStream & os) const else if (type_ == "eqnarray" || type_ == "align") os << "\\begin{" << type_ << star(n) << "}\n"; - else if (type_ == "alignat" || type_ == "xalignat" || type_ == "xxalignat") + else if (type_ == "alignat" || type_ == "xalignat") os << "\\begin{" << type_ << star(n) << "}" << "{" << static_cast(ncols()/2) << "}\n"; - else if (type_ == "multline" || type_ == "gather") + else if (type_ == "xxalignat" || type_ == "multline" || type_ == "gather") os << "\\begin{" << type_ << "}\n"; else diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 5becf7ed11..3805e7c189 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -53,7 +53,6 @@ class MathBoxInset; class MathCharInset; class MathDelimInset; class MathFboxInset; -class MathFontInset; class MathGridInset; class MathFracInset; class MathHullInset; @@ -203,7 +202,6 @@ public: virtual MathDelimInset * asDelimInset() { return 0; } virtual MathDelimInset const * asDelimInset() const { return 0; } virtual MathFboxInset * asFboxInset() { return 0; } - virtual MathFontInset const * asFontInset() const { return 0; } virtual MathFracInset * asFracInset() { return 0; } virtual MathGridInset * asGridInset() { return 0; } virtual MathHullInset * asHullInset() { return 0; } diff --git a/src/mathed/math_parboxinset.C b/src/mathed/math_parboxinset.C index 60b748c19d..9e90e7e189 100644 --- a/src/mathed/math_parboxinset.C +++ b/src/mathed/math_parboxinset.C @@ -34,16 +34,22 @@ void MathParboxInset::setWidth(string const & w) } +int MathParboxInset::pos2row(pos_type pos) const +{ + for (int r = 0, n = rows_.size(); r < n; ++r) + if (pos >= rows_[r].begin && pos < rows_[r].end) + return r; + lyxerr << "illegal row for pos " << pos << "\n"; + return 0; +} + + void MathParboxInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const { - for (int r = 0, n = rows_.size(); r < n; ++r) { - if (pos >= rows_[r].begin && pos < rows_[r].end) { - //lyxerr << "found cursor at pos " << pos << " in row " << r << "\n"; - x = cells_[0].xo() + cells_[0].pos2x(rows_[r].begin, pos, rows_[r].glue); - y = cells_[0].yo() + rows_[r].yo; - break; - } - } + int const r = pos2row(pos); + //lyxerr << "found cursor at pos " << pos << " in row " << r << "\n"; + x = cells_[0].xo() + cells_[0].pos2x(rows_[r].begin, pos, rows_[r].glue); + y = cells_[0].yo() + rows_[r].yo; // move cursor visually into empty cells ("blue rectangles"); if (cell(0).empty()) x += 2; diff --git a/src/mathed/math_parboxinset.h b/src/mathed/math_parboxinset.h index f7305478cd..389fe158b0 100644 --- a/src/mathed/math_parboxinset.h +++ b/src/mathed/math_parboxinset.h @@ -26,6 +26,8 @@ public: /// void setPosition(string const & pos); private: + /// row corresponding to given position + int pos2row(pos_type pos) const; /// width on screen int lyx_width_; /// width for TeX diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index dc44e7a90e..0e1e94e335 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -1026,12 +1026,8 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, latexkeys const * l = in_word_set(t.cs()); if (l) { if (l->inset == "font") { - lyxerr << "starting font " << t.cs() << "\n"; - MathAtom p = createMathInset(t.cs()); - bool textmode = (t.cs()[0] == 't'); - parse(p->cell(0), FLAG_ITEM, !textmode); - cell->push_back(p); - //lyxerr << "ending font\n"; + cell->push_back(createMathInset(t.cs())); + parse(cell->back()->cell(0), FLAG_ITEM, l->extra == "mathmode"); } else if (l->inset == "oldfont") {