From 5507c1ad69ef62f0790b66c797c6d89166795590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 19 Oct 2001 11:25:48 +0000 Subject: [PATCH] use stream-like syntax for LaTeX output (instead of inset.write(stream) functions) prepare fix for proper font sizes in chapter heading etc... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2899 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 7 ++- src/mathed/Makefile.am | 2 + src/mathed/array.C | 6 +-- src/mathed/array.h | 4 +- src/mathed/formula.C | 29 +++++------ src/mathed/formula.h | 2 - src/mathed/formulabase.C | 19 +++++-- src/mathed/formulabase.h | 6 ++- src/mathed/formulamacro.C | 32 ++++++------ src/mathed/formulamacro.h | 2 - src/mathed/math_arrayinset.C | 15 +++--- src/mathed/math_arrayinset.h | 4 +- src/mathed/math_binominset.C | 17 +++---- src/mathed/math_binominset.h | 4 +- src/mathed/math_boxinset.C | 81 ++++++++++++++++++++++++++++++ src/mathed/math_boxinset.h | 51 +++++++++++++++++++ src/mathed/math_charinset.C | 12 ++--- src/mathed/math_charinset.h | 4 +- src/mathed/math_cursor.C | 8 ++- src/mathed/math_decorationinset.C | 10 ++-- src/mathed/math_decorationinset.h | 4 +- src/mathed/math_deliminset.C | 11 ++-- src/mathed/math_deliminset.h | 4 +- src/mathed/math_dotsinset.C | 6 +-- src/mathed/math_dotsinset.h | 4 +- src/mathed/math_factory.C | 3 ++ src/mathed/math_fracinset.C | 24 +++------ src/mathed/math_fracinset.h | 4 +- src/mathed/math_funcinset.C | 8 +-- src/mathed/math_funcinset.h | 4 +- src/mathed/math_funcliminset.C | 13 ++--- src/mathed/math_funcliminset.h | 4 +- src/mathed/math_gridinset.C | 10 ++-- src/mathed/math_gridinset.h | 4 +- src/mathed/math_hash.C | 2 + src/mathed/math_inset.C | 23 ++++----- src/mathed/math_inset.h | 73 ++++++++++++++++++++++++--- src/mathed/math_kerninset.C | 6 ++- src/mathed/math_kerninset.h | 4 +- src/mathed/math_lefteqninset.C | 11 ++-- src/mathed/math_lefteqninset.h | 6 +-- src/mathed/math_macro.C | 34 ++++++------- src/mathed/math_macro.h | 4 +- src/mathed/math_macroarg.C | 8 +-- src/mathed/math_macroarg.h | 4 +- src/mathed/math_macrotemplate.C | 14 ++---- src/mathed/math_macrotemplate.h | 4 +- src/mathed/math_matrixinset.C | 17 +++---- src/mathed/math_matrixinset.h | 4 +- src/mathed/math_nestinset.C | 13 ++--- src/mathed/math_nestinset.h | 2 +- src/mathed/math_notinset.C | 18 +++---- src/mathed/math_notinset.h | 4 +- src/mathed/math_parser.C | 11 ++++ src/mathed/math_parser.h | 2 + src/mathed/math_rootinset.C | 10 ++-- src/mathed/math_rootinset.h | 4 +- src/mathed/math_scriptinset.C | 28 ++++------- src/mathed/math_scriptinset.h | 8 +-- src/mathed/math_sizeinset.C | 12 ++--- src/mathed/math_sizeinset.h | 4 +- src/mathed/math_spaceinset.C | 4 +- src/mathed/math_spaceinset.h | 4 +- src/mathed/math_specialcharinset.C | 6 +-- src/mathed/math_specialcharinset.h | 4 +- src/mathed/math_splitinset.C | 8 +-- src/mathed/math_splitinset.h | 2 +- src/mathed/math_sqrtinset.C | 8 ++- src/mathed/math_sqrtinset.h | 4 +- src/mathed/math_stackrelinset.C | 13 ++--- src/mathed/math_stackrelinset.h | 4 +- src/mathed/math_symbolinset.C | 29 ++++++----- src/mathed/math_symbolinset.h | 4 +- src/mathed/xarray.C | 8 +-- src/mathed/xarray.h | 2 +- 75 files changed, 522 insertions(+), 326 deletions(-) create mode 100644 src/mathed/math_boxinset.C create mode 100644 src/mathed/math_boxinset.h diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 9aef0b2763..550d77e4eb 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,11 +1,16 @@ +2001-10-17 André Pönitz + + * math_inset.h: + * *.[Ch]: make output more stream-like + 2001-10-17 André Pönitz * formula.C: * array.C: add missing/broken writeNormal() * math_lefteqn.[Ch]: some visual support for \lefteqn - + 2001-10-10 André Pönitz diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 15fadc46a0..8b9a43e04a 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -24,6 +24,8 @@ libmathed_la_SOURCES = \ math_atom.h \ math_binominset.C \ math_binominset.h \ + math_boxinset.C \ + math_boxinset.h \ math_charinset.C \ math_charinset.h \ math_cursor.C \ diff --git a/src/mathed/array.C b/src/mathed/array.C index c91d52ed84..2c87130997 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -171,7 +171,7 @@ string charSequence(MathArray::const_iterator it, MathArray::const_iterator end) } -void MathArray::write(ostream & os, bool fragile) const +void MathArray::write(MathWriteInfo & wi) const { for (const_iterator it = begin(); it != end(); ++it) { MathInset * p = it->nucleus(); @@ -190,10 +190,10 @@ void MathArray::write(ostream & os, bool fragile) const } else */ if (MathScriptInset const * q = asScript(it)) { - q->write(p, os, fragile); + q->write(p, wi); ++it; } else { - p->write(os, fragile); + p->write(wi); } } } diff --git a/src/mathed/array.h b/src/mathed/array.h index 2f7cbe6558..db0f1d4ea5 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -22,6 +22,8 @@ class MathScriptInset; class MathMacro; +class MathWriteInfo; +class MathMetricsInfo; class LaTeXFeatures; #ifdef __GNUG__ @@ -96,7 +98,7 @@ public: /// MathAtom const & at(size_type pos) const; /// - void write(std::ostream &, bool) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 6a427b9c41..400bbaf813 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -90,16 +90,19 @@ void InsetFormula::write(Buffer const * buf, ostream & os) const } -int InsetFormula::latex(Buffer const *, ostream & os, bool fragile, bool) const +int InsetFormula::latex(Buffer const * buf, ostream & os, bool fragil, bool) + const { - par_->write(os, fragile); + MathWriteInfo wi(buf, os, fragil); + par_->write(wi); return 1; } -int InsetFormula::ascii(Buffer const *, ostream & os, int) const +int InsetFormula::ascii(Buffer const * buf, ostream & os, int) const { - par_->write(os, false); + MathWriteInfo wi(buf, os, false); + par_->write(wi); return 1; } @@ -123,7 +126,7 @@ void InsetFormula::read(Buffer const *, LyXLex & lex) } -void InsetFormula::draw(BufferView * bv, LyXFont const &, +void InsetFormula::draw(BufferView * bv, LyXFont const & font, int y, float & xx, bool) const { int x = int(xx) - 1; @@ -132,7 +135,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const &, MathInset::workwidth = bv->workWidth(); Painter & pain = bv->painter(); - metrics(); + metrics(bv, &font); int w = par_->width(); int h = par_->height(); int a = par_->ascent(); @@ -150,12 +153,6 @@ void InsetFormula::draw(BufferView * bv, LyXFont const &, } -void InsetFormula::metrics() const -{ - par_->metrics(display() ? LM_ST_DISPLAY : LM_ST_TEXT); -} - - vector const InsetFormula::getLabelList() const { return mat()->getLabelList(); @@ -302,7 +299,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, } -void InsetFormula::handleExtern(const string & arg, BufferView *) +void InsetFormula::handleExtern(const string & arg, BufferView * bv) { // where are we? MathArray & ar = mathcursor->cursor().cell(); @@ -337,7 +334,7 @@ void InsetFormula::handleExtern(const string & arg, BufferView *) mathcursor->end(); // re-compute inset dimension - metrics(); + metrics(bv); } @@ -391,9 +388,9 @@ int InsetFormula::descent(BufferView *, LyXFont const &) const } -int InsetFormula::width(BufferView *, LyXFont const &) const +int InsetFormula::width(BufferView * bv, LyXFont const & font) const { - metrics(); + metrics(bv, &font); return par_->width(); } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 501f1db2b1..659c80a1ca 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -44,8 +44,6 @@ public: int width(BufferView *, LyXFont const &) const; /// void draw(BufferView *, LyXFont const &, int, float &, bool) const; - /// - void metrics() const; /// void write(Buffer const *, std::ostream &) const; diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index f233c7851d..f7b9e49b33 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -104,6 +104,7 @@ MathArrayInset * matrixpar(MathInset::idx_type & idx) InsetFormulaBase::InsetFormulaBase() + : view_(0), font_(0) { // This is needed as long the math parser is not re-entrant MathMacroTable::builtinMacros(); @@ -116,6 +117,17 @@ void InsetFormulaBase::validate(LaTeXFeatures &) const {} +void InsetFormulaBase::metrics(BufferView * bv, LyXFont const * f) const +{ + if (bv) + view_ = bv; + if (f) + font_ = f; + MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT); + par()->metrics(mi); +} + + string const InsetFormulaBase::editMessage() const { return _("Math editor mode"); @@ -128,7 +140,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int) lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl; mathcursor = new MathCursor(this, x == 0); - metrics(); + metrics(bv); // if that is removed, we won't get the magenta box when entering an // inset for the first time bv->updateInset(this, false); @@ -233,7 +245,7 @@ vector const InsetFormulaBase::getLabelList() const void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty) { - metrics(); + metrics(bv); bv->updateInset(this, dirty); } @@ -677,8 +689,7 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display) // sel = ""; //else - string sel = bv->getLyXText()->selectionAsString(bv->buffer(), - false); + string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false); InsetFormulaBase * f; if (sel.empty()) { diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index f35889641e..3d45a7814f 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -89,12 +89,16 @@ public: /// virtual MathAtom & par() = 0; /// - virtual void metrics() const = 0; + virtual void metrics(BufferView * bv = 0, LyXFont const * font = 0) const; /// virtual void updateLocal(BufferView * bv, bool mark_dirty); private: /// unimplemented void operator=(const InsetFormulaBase &); + /// + mutable BufferView * view_; + /// + mutable LyXFont const * font_; }; // We don't really mess want around with mathed stuff outside mathed. diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index d8b620d87d..b0188770d3 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -61,7 +61,10 @@ InsetFormulaMacro::InsetFormulaMacro(string const & s) { string name = mathed_parse_macro(s); setInsetName(name); - metrics(); +#ifdef WITH_WARNINGS +#warning "metrics disabled" +#endif + //metrics(); } @@ -71,23 +74,27 @@ Inset * InsetFormulaMacro::clone(Buffer const &, bool) const } -void InsetFormulaMacro::write(Buffer const *, ostream & os) const +void InsetFormulaMacro::write(Buffer const * buf, ostream & os) const { os << "FormulaMacro "; - par()->write(os, false); + MathWriteInfo wi(buf, os, false); + par()->write(wi); } -int InsetFormulaMacro::latex(Buffer const *, ostream & os, bool fragile, +int InsetFormulaMacro::latex(Buffer const * buf, ostream & os, bool fragile, bool /*free_spacing*/) const { - par()->write(os, fragile); + MathWriteInfo wi(buf, os, fragile); + par()->write(wi); return 2; } -int InsetFormulaMacro::ascii(Buffer const *, ostream & os, int) const + +int InsetFormulaMacro::ascii(Buffer const * buf, ostream & os, int) const { - par()->write(os, false); + MathWriteInfo wi(buf, os, false); + par()->write(wi); return 0; } @@ -108,6 +115,7 @@ void InsetFormulaMacro::read(Buffer const *, LyXLex & lex) { string name = mathed_parse_macro(lex); setInsetName(name); + lyxerr << "metrics disabled"; metrics(); } @@ -130,9 +138,9 @@ int InsetFormulaMacro::descent(BufferView *, LyXFont const &) const } -int InsetFormulaMacro::width(BufferView *, LyXFont const & f) const +int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const { - metrics(); + metrics(bv, &f); return 10 + lyxfont::width(prefix(), f) + par()->width(); } @@ -193,12 +201,6 @@ MathInsetTypes InsetFormulaMacro::getType() const } -void InsetFormulaMacro::metrics() const -{ - par()->metrics(LM_ST_TEXT); -} - - void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f, int baseline, float & x, bool /*cleared*/) const { diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index fdf37e37fa..19734215f2 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -68,8 +68,6 @@ public: /// MathInsetTypes getType() const; /// - void metrics() const; - /// MathAtom const & par() const; /// MathAtom & par(); diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index ae9cfabbf4..25c63eb7ce 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -22,9 +22,9 @@ MathInset * MathArrayInset::clone() const } -void MathArrayInset::write(std::ostream & os, bool fragile) const +void MathArrayInset::write(MathWriteInfo & os) const { - if (fragile) + if (os.fragile) os << "\\protect"; os << "\\begin{array}"; @@ -36,16 +36,19 @@ void MathArrayInset::write(std::ostream & os, bool fragile) const os << colinfo_[col].align_; os << "}\n"; - MathGridInset::write(os, fragile); + MathGridInset::write(os); - if (fragile) + if (os.fragile) os << "\\protect"; os << "\\end{array}\n"; } -void MathArrayInset::metrics(MathStyles st) const +void MathArrayInset::metrics(MathMetricsInfo const & st) const { - MathGridInset::metrics(st == LM_ST_DISPLAY ? LM_ST_TEXT : st); + MathMetricsInfo m = st; + if (m.size == LM_ST_DISPLAY) + m.size = LM_ST_TEXT; + MathGridInset::metrics(m); } diff --git a/src/mathed/math_arrayinset.h b/src/mathed/math_arrayinset.h index ee7341d843..79fa2130da 100644 --- a/src/mathed/math_arrayinset.h +++ b/src/mathed/math_arrayinset.h @@ -18,9 +18,9 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// MathArrayInset * asArrayInset() { return this; } }; diff --git a/src/mathed/math_binominset.C b/src/mathed/math_binominset.C index 5785777615..1f04084c26 100644 --- a/src/mathed/math_binominset.C +++ b/src/mathed/math_binominset.C @@ -28,11 +28,12 @@ int MathBinomInset::dw() const } -void MathBinomInset::metrics(MathStyles st) const +void MathBinomInset::metrics(MathMetricsInfo const & st) const { - size_ = smallerStyleFrac(st); - xcell(0).metrics(size_); - xcell(1).metrics(size_); + MathMetricsInfo m = st; + m.size = smallerStyleFrac(m.size); + xcell(0).metrics(m); + xcell(1).metrics(m); ascent_ = xcell(0).height() + 4 + 5; descent_ = xcell(1).height() + 4 - 5; width_ = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4; @@ -51,13 +52,9 @@ void MathBinomInset::draw(Painter & pain, int x, int y) const } -void MathBinomInset::write(std::ostream & os, bool fragile) const +void MathBinomInset::write(MathWriteInfo & os) const { - os << '{'; - cell(0).write(os, fragile); - os << " \\choose "; - cell(1).write(os, fragile); - os << '}'; + os << '{' << cell(0) << " \\choose " << cell(1) << '}'; } diff --git a/src/mathed/math_binominset.h b/src/mathed/math_binominset.h index 2bb97451dd..b991a2700a 100644 --- a/src/mathed/math_binominset.h +++ b/src/mathed/math_binominset.h @@ -18,11 +18,11 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; private: diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C new file mode 100644 index 0000000000..fa2a61909c --- /dev/null +++ b/src/mathed/math_boxinset.C @@ -0,0 +1,81 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_boxinset.h" +#include "support/LOstream.h" +#include "LColor.h" +#include "debug.h" +#include "Painter.h" +#include "math_cursor.h" +#include "insets/insettext.h" + + +MathBoxInset::MathBoxInset(string const & name) + : MathDimInset(), name_(name), text_(new InsetText), buffer_(0) +{ + lyxerr << "creating new " << name << endl; +} + + +MathBoxInset::MathBoxInset(MathBoxInset const & m) + : MathDimInset(*this), name_(m.name_), text_(0), buffer_(m.buffer_) +{ + if (!m.buffer_) + cerr << "no buffer\n"; + else + text_ = static_cast(m.text_->clone(*m.buffer_, false)); +} + + +MathBoxInset::~MathBoxInset() +{ + delete text_; +} + + +MathInset * MathBoxInset::clone() const +{ + return new MathBoxInset(*this); +} + + +void MathBoxInset::write(MathWriteInfo & os) const +{ + os << "\\" << name_ << "{" << cell(0) << "}"; +} + + +void MathBoxInset::writeNormal(std::ostream & os) const +{ + os << "[mbox "; + //text_->write(buffer(), os); + os << "] "; +} + + +void MathBoxInset::metrics(MathMetricsInfo const & st) const +{ + size_ = st; + if (text_ && st.view && st.font) { + ascent_ = text_->ascent(st.view, *st.font) + 2; + descent_ = text_->descent(st.view, *st.font) + 2; + width_ = text_->width(st.view, *st.font) + 4; + } else { + ascent_ = 10; + descent_ = 0; + width_ = 10; + } +} + + +void MathBoxInset::draw(Painter & pain, int x, int y) const +{ + float fx = x + 2; + + if (text_ && size_.view && size_.font) + text_->draw(size_.view, *(size_.font), y, fx, false); + if (mathcursor && mathcursor->isInside(this)) + pain.rectangle(x, y - ascent(), xcell(0).width(), height(), + LColor::mathframe); +} diff --git a/src/mathed/math_boxinset.h b/src/mathed/math_boxinset.h new file mode 100644 index 0000000000..9b0bd58123 --- /dev/null +++ b/src/mathed/math_boxinset.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +#ifndef MATH_BOXINSET_H +#define MATH_BOXINSET_H + +#include "math_diminset.h" +#include "LString.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +class InsetText; +class BufferView; +class Buffer; +class LyXFont; + +/// Support for \\mbox + +class MathBoxInset : public MathDimInset { +public: + /// + explicit MathBoxInset(string const &); + /// + MathBoxInset(MathBoxInset const &); + /// + ~MathBoxInset(); + /// + MathInset * clone() const; + /// + void draw(Painter &, int x, int y) const; + /// + void write(MathWriteInfo & os) const; + /// + void writeNormal(std::ostream &) const; + /// + void metrics(MathMetricsInfo const & st) const; + /// identifies BoxInsets + MathBoxInset * asBoxInset() { return this; } + +private: + /// unimplemented + void operator=(MathBoxInset const &); + + /// + string name_; + /// + InsetText * text_; + /// + mutable Buffer * buffer_; +}; +#endif diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 8c1ca673b4..44d6884541 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -76,7 +76,7 @@ int MathCharInset::width() const } -void MathCharInset::metrics(MathStyles st) const +void MathCharInset::metrics(MathMetricsInfo const & st) const { size_ = st; } @@ -87,7 +87,7 @@ void MathCharInset::draw(Painter & pain, int x, int y) const xo(x); yo(y); //lyxerr << "drawing '" << char_ << "' code: " << code_ << endl; - drawChar(pain, code_, size_, x, y, char_); + drawChar(pain, code_, size_.size, x, y, char_); } @@ -111,11 +111,11 @@ void MathCharInset::writeRaw(std::ostream & os) const } -void MathCharInset::write(std::ostream & os, bool) const +void MathCharInset::write(MathWriteInfo & os) const { - writeHeader(os); - writeRaw(os); - writeTrailer(os); + writeHeader(os.os); + writeRaw(os.os); + writeTrailer(os.os); } diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index 37f6029e07..fc024338fe 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -23,11 +23,11 @@ public: /// MathTextCodes nativeCode(char c) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeHeader(std::ostream &) const; /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 5c4840ba13..9623694133 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -460,7 +460,10 @@ void MathCursor::niceInsert(MathAtom const & t) right(); // do not push for e.g. MathSymbolInset selPaste(); } - p->metrics(p->size()); +#ifdef WITH_WARNINGS +#warning "redraw disabled" +#endif + //p->metrics(p->size()); } @@ -936,7 +939,8 @@ void MathCursor::normalize() const lyxerr << "this should not really happen - 2: " << pos() << " " << size() << " in idx: " << it->idx() << " in atom: '"; - it->par()->write(lyxerr, false); + MathWriteInfo wi(0, lyxerr, false); + it->par()->write(wi); lyxerr << "\n"; dump("error 4"); } diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index 4b35c789f3..becc4183f4 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -62,7 +62,7 @@ bool MathDecorationInset::wide() const } -void MathDecorationInset::metrics(MathStyles st) const +void MathDecorationInset::metrics(MathMetricsInfo const & st) const { xcell(0).metrics(st); size_ = st; @@ -96,13 +96,11 @@ void MathDecorationInset::draw(Painter & pain, int x, int y) const } -void MathDecorationInset::write(ostream & os, bool fragile) const +void MathDecorationInset::write(MathWriteInfo & os) const { - if (fragile && protect()) + if (os.fragile && protect()) os << "\\protect"; - os << '\\' << name_ << '{'; - cell(0).write(os, fragile); - os << '}'; + os << '\\' << name_ << '{' << cell(0) << '}'; } diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index 200b8ea998..a7a8effa82 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -22,9 +22,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void writeNormal(std::ostream & os) const; /// diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index a4f7efafd1..dfa8884469 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -42,11 +42,10 @@ string MathDelimInset::latexName(string const & name) } -void MathDelimInset::write(std::ostream & os, bool fragile) const +void MathDelimInset::write(MathWriteInfo & os) const { - os << "\\left" << latexName(left_); - cell(0).write(os, fragile); - os << "\\right" << latexName(right_); + os << "\\left" << latexName(left_) << cell(0) + << "\\right" << latexName(right_); } @@ -61,12 +60,12 @@ int MathDelimInset::dw() const } -void MathDelimInset::metrics(MathStyles st) const +void MathDelimInset::metrics(MathMetricsInfo const & st) const { xcell(0).metrics(st); size_ = st; int a, d, w; - mathed_char_dim(LM_TC_VAR, st,'I', a, d, w); + mathed_char_dim(LM_TC_VAR, size_.size,'I', a, d, w); int h0 = (a + d) / 2; int a0 = std::max(xcell(0).ascent(), a) - h0; int d0 = std::max(xcell(0).descent(), d) + h0; diff --git a/src/mathed/math_deliminset.h b/src/mathed/math_deliminset.h index 23cf45e376..89240db8cb 100644 --- a/src/mathed/math_deliminset.h +++ b/src/mathed/math_deliminset.h @@ -22,9 +22,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; private: /// int dw() const; diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index f7b6238dc0..4c142c34c8 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -32,9 +32,9 @@ void MathDotsInset::draw(Painter & pain, int x, int y) const } -void MathDotsInset::metrics(MathStyles st) const +void MathDotsInset::metrics(MathMetricsInfo const & st) const { - size(st); + size_ = st; mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_); switch (name_[0]) { case 'l': dh_ = 0; break; @@ -45,7 +45,7 @@ void MathDotsInset::metrics(MathStyles st) const } -void MathDotsInset::write(ostream & os, bool /* fragile */) const +void MathDotsInset::write(MathWriteInfo & os) const { os << '\\' << name_ << ' '; } diff --git a/src/mathed/math_dotsinset.h b/src/mathed/math_dotsinset.h index cda4a77f7a..2fcc333c25 100644 --- a/src/mathed/math_dotsinset.h +++ b/src/mathed/math_dotsinset.h @@ -19,11 +19,11 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; protected: /// cache for the thing's heigth mutable int dh_; diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index 280b48f5d7..88b8472848 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -2,6 +2,7 @@ #include "math_parser.h" #include "math_binominset.h" +//#include "math_boxinset.h" #include "math_decorationinset.h" #include "math_dotsinset.h" #include "math_funcinset.h" @@ -62,6 +63,8 @@ MathAtom createMathInset(latexkeys const * l) return MathAtom(new MathSpaceInset(l->id)); case LM_TK_DOTS: return MathAtom(new MathDotsInset(l->name)); + //case LM_TK_BOX: + // return MathAtom(new MathBoxInset(l->name)); } return MathAtom(new MathFuncInset(l->name)); } diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index e4e08935ed..057366ba7b 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -19,9 +19,10 @@ MathInset * MathFracInset::clone() const } -void MathFracInset::metrics(MathStyles st) const +void MathFracInset::metrics(MathMetricsInfo const & st) const { - size_ = smallerStyleFrac(st); + size_ = st; + size_.size = smallerStyleFrac(size_.size); xcell(0).metrics(size_); xcell(1).metrics(size_); width_ = std::max(xcell(0).width(), xcell(1).width()) + 4; @@ -42,21 +43,12 @@ void MathFracInset::draw(Painter & pain, int x, int y) const } -void MathFracInset::write(std::ostream & os, bool fragile) const +void MathFracInset::write(MathWriteInfo & os) const { - if (atop_) { - os << "{"; - cell(0).write(os, fragile); - os << "\\atop "; - cell(1).write(os, fragile); - os << '}'; - } else { - os << "\\frac{"; - cell(0).write(os, fragile); - os << "}{"; - cell(1).write(os, fragile); - os << '}'; - } + if (atop_) + os << '{' << cell(0) << "\\atop " << cell(1) << '}'; + else + os << "\\frac{" << cell(0) << "}{" << cell(1) << '}'; } diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index d60ca9bd08..0c227c6f8c 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -18,11 +18,11 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; public: diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C index 9932510580..b5651b9df7 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -37,7 +37,7 @@ void MathFuncInset::setName(string const & n) } -void MathFuncInset::write(std::ostream & os, bool /* fragile */) const +void MathFuncInset::write(MathWriteInfo & os) const { os << "\\" << name_ << ' '; } @@ -49,10 +49,10 @@ void MathFuncInset::writeNormal(std::ostream & os) const } -void MathFuncInset::metrics(MathStyles st) const +void MathFuncInset::metrics(MathMetricsInfo const & st) const { size_ = st; - mathed_string_dim(LM_TC_TEX, size_, name_, ascent_, descent_, width_); + mathed_string_dim(LM_TC_TEX, size_.size, name_, ascent_, descent_, width_); } @@ -60,5 +60,5 @@ void MathFuncInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); - drawStr(pain, LM_TC_TEX, size_, x, y, name_); + drawStr(pain, LM_TC_TEX, size_.size, x, y, name_); } diff --git a/src/mathed/math_funcinset.h b/src/mathed/math_funcinset.h index 3a773df15f..b81cc60907 100644 --- a/src/mathed/math_funcinset.h +++ b/src/mathed/math_funcinset.h @@ -20,11 +20,11 @@ public: /// MathInset * clone() const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// diff --git a/src/mathed/math_funcliminset.C b/src/mathed/math_funcliminset.C index d281b9e23b..f8f03cda1c 100644 --- a/src/mathed/math_funcliminset.C +++ b/src/mathed/math_funcliminset.C @@ -19,11 +19,11 @@ MathInset * MathFuncLimInset::clone() const bool MathFuncLimInset::isScriptable() const { - return size_ == LM_ST_DISPLAY; + return size_.size == LM_ST_DISPLAY; } -void MathFuncLimInset::write(ostream & os, bool /* fragile */) const +void MathFuncLimInset::write(MathWriteInfo & os) const { os << '\\' << sym_->name << ' '; } @@ -35,10 +35,11 @@ void MathFuncLimInset::writeNormal(ostream & os) const } -void MathFuncLimInset::metrics(MathStyles st) const +void MathFuncLimInset::metrics(MathMetricsInfo const & st) const { - size(st); - mathed_string_dim(LM_TC_TEXTRM, size(), sym_->name, ascent_, descent_, width_); + size_ = st; + mathed_string_dim(LM_TC_TEXTRM, size_.size, sym_->name, + ascent_, descent_, width_); } @@ -46,5 +47,5 @@ void MathFuncLimInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); - drawStr(pain, LM_TC_TEXTRM, size_, x, y, sym_->name); + drawStr(pain, LM_TC_TEXTRM, size_.size, x, y, sym_->name); } diff --git a/src/mathed/math_funcliminset.h b/src/mathed/math_funcliminset.h index dce77a090a..70f0e992b8 100644 --- a/src/mathed/math_funcliminset.h +++ b/src/mathed/math_funcliminset.h @@ -16,11 +16,11 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index c7edf132a5..4b3c16d606 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -132,7 +132,7 @@ LyXLength MathGridInset::vskip(row_type row) const } -void MathGridInset::metrics(MathStyles st) const +void MathGridInset::metrics(MathMetricsInfo const & st) const { // let the cells adjust themselves MathNestInset::metrics(st); @@ -264,13 +264,11 @@ void MathGridInset::draw(Painter & pain, int x, int y) const } -void MathGridInset::write(std::ostream & os, bool fragile) const +void MathGridInset::write(MathWriteInfo & os) const { for (row_type row = 0; row < nrows(); ++row) { - for (col_type col = 0; col < ncols(); ++col) { - cell(index(row, col)).write(os, fragile); - os << eocString(col); - } + for (col_type col = 0; col < ncols(); ++col) + os << cell(index(row, col)) << eocString(col); os << eolString(row); } } diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 8253ec3066..c0b64f03e7 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -64,11 +64,11 @@ public: /// MathGridInset(int m, int n, char valign, string const & halign); /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index 80f5dbfe63..888ff8748a 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -94,6 +94,7 @@ latexkeys_a wordlist_array[] = {"mathsf", LM_TK_FONT, LM_TC_SF}, {"mathtt", LM_TK_FONT, LM_TC_TT}, {"max", LM_TK_FUNCLIM, 0}, + //{"mbox", LM_TK_BOX, 0}, {"min", LM_TK_FUNCLIM, 0}, {"newcommand", LM_TK_NEWCOMMAND, 0 }, {"nolimits", LM_TK_LIMIT, static_cast(-1)}, @@ -154,6 +155,7 @@ MathTokenEnum tokenEnum(const string & font) return LM_TK_SYM; } + MathSymbolTypes symbolType(const string & type) { if (type == "mathrel") diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index b4e340b508..0620aefdbd 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -28,7 +28,7 @@ int MathInset::workwidth; MathInset::MathInset() - : size_(LM_ST_DISPLAY), xo_(0), yo_(0) + : xo_(0), yo_(0) {} @@ -44,19 +44,14 @@ int MathInset::height() const MathStyles MathInset::size() const { - return size_; -} - - -void MathInset::size(MathStyles s) const -{ - size_ = s; + return size_.size; } std::ostream & operator<<(std::ostream & os, MathInset const & inset) { - inset.write(os, false); + MathWriteInfo wi(0, os, false); + inset.write(wi); return os; } @@ -216,7 +211,8 @@ void MathInset::userSetSize(MathStyles sz) void MathInset::writeNormal(std::ostream & os) const { os << "[unknown "; - write(os, false); + MathWriteInfo wi(0, os, false); + write(wi); os << "] "; } @@ -224,7 +220,8 @@ void MathInset::writeNormal(std::ostream & os) const void MathInset::dump() const { lyxerr << "---------------------------------------------\n"; - write(lyxerr, false); + MathWriteInfo wi(0, lyxerr, false); + write(wi); lyxerr << "\n---------------------------------------------\n"; } @@ -267,7 +264,7 @@ std::vector } -void MathInset::metrics(MathStyles st) const +void MathInset::metrics(MathMetricsInfo const & st) const { lyxerr << "MathInset::metrics() called directly!\n"; size_ = st; @@ -280,7 +277,7 @@ void MathInset::draw(Painter &, int, int) const } -void MathInset::write(std::ostream &, bool) const +void MathInset::write(MathWriteInfo &) const { lyxerr << "MathInset::write() called directly!\n"; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 9894c9ee73..323deadb75 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -37,16 +37,75 @@ */ -class LaTeXFeatures; class MathArrayInset; +class MathBoxInset; class MathCharInset; class MathGridInset; class MathNestInset; -class MathScriptInset; class MathMatrixInset; +class MathScriptInset; class MathSpaceInset; class MathMacroTemplate; +class LaTeXFeatures; +class Buffer; +class BufferView; +class LyXFont; + + +struct MathMetricsInfo { + /// + MathMetricsInfo() + : view(0), font(0), size(LM_ST_TEXT) + {} + /// + MathMetricsInfo(BufferView * v, LyXFont const * f, MathStyles s) + : view(v), font(f), size(s) + {} + + /// + BufferView * view; + /// + LyXFont const * font; + /// + MathStyles size; +}; + + +struct MathWriteInfo { + /// + MathWriteInfo(Buffer const * buffer_, std::ostream & os_, bool fragile_) + : buffer(buffer_), os(os_), fragile(fragile_) + {} + /// + explicit MathWriteInfo(std::ostream & os_) + : buffer(0), os(os_), fragile(false) + {} + + /// + template + MathWriteInfo & operator<<(T const & T) + { + os << T; + return *this; + } + /// + MathWriteInfo & operator<<(MathArray const & ar) + { + ar.write(*this); + return *this; + } + + + /// + Buffer const * buffer; + /// + std::ostream & os; + /// + bool fragile; +}; + + class MathInset { public: /// short of anything else reasonable @@ -68,7 +127,7 @@ public: /// draw the object, sets xo_ and yo_ cached values virtual void draw(Painter &, int x, int y) const; /// write LaTeX and Lyx code - virtual void write(std::ostream &, bool fragile) const; + virtual void write(MathWriteInfo & os) const; /// write normalized content virtual void writeNormal(std::ostream &) const; /// reproduce itself @@ -76,7 +135,7 @@ public: ///substitutes macro arguments if necessary virtual void substitute(MathMacro const & macro); /// compute the size of the object, sets ascend_, descend_ and width_ - virtual void metrics(MathStyles st) const; + virtual void metrics(MathMetricsInfo const & st) const; /// virtual int ascent() const { return 1; } /// @@ -191,6 +250,8 @@ public: virtual MathGridInset * asGridInset() { return 0; } /// identifies ArrayInsets virtual MathArrayInset * asArrayInset() { return 0; } + /// identifies BoxInsets + virtual MathBoxInset * asBoxInset() { return 0; } /// identifies macro templates virtual MathMacroTemplate * asMacroTemplate() { return 0; } @@ -226,10 +287,8 @@ public: static int workwidth; protected: - /// _sets_ style - void size(MathStyles s) const; /// the used font size - mutable MathStyles size_; + mutable MathMetricsInfo size_; private: /// the following are used for positioning the cursor with the mouse diff --git a/src/mathed/math_kerninset.C b/src/mathed/math_kerninset.C index 37e24e93a5..6a28235177 100644 --- a/src/mathed/math_kerninset.C +++ b/src/mathed/math_kerninset.C @@ -31,7 +31,7 @@ void MathKernInset::draw(Painter &, int, int) const {} -void MathKernInset::write(std::ostream & os, bool) const +void MathKernInset::write(MathWriteInfo & os) const { os << "\\kern" << wid_.asLatexString() << " "; } @@ -43,12 +43,14 @@ void MathKernInset::writeNormal(std::ostream & os) const } -void MathKernInset::metrics(MathStyles) const +void MathKernInset::metrics(MathMetricsInfo const &) const { ascent_ = 0; descent_ = 0; #ifdef WITH_WARNINGS #warning fix this once the interface to LyXLength has improved #endif + // this uses the numerical valu in pixels, even if the unit is cm or ex! width_ = static_cast(wid_.value()); + //cerr << "handling kern of width " << wid_.value() << "\n"; } diff --git a/src/mathed/math_kerninset.h b/src/mathed/math_kerninset.h index 978dd10409..0a707cae7f 100644 --- a/src/mathed/math_kerninset.h +++ b/src/mathed/math_kerninset.h @@ -25,11 +25,11 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; private: /// width in em LyXLength wid_; diff --git a/src/mathed/math_lefteqninset.C b/src/mathed/math_lefteqninset.C index 162c2ab88d..9c22c442a4 100644 --- a/src/mathed/math_lefteqninset.C +++ b/src/mathed/math_lefteqninset.C @@ -30,23 +30,22 @@ void MathLefteqnInset::draw(Painter & pain, int x, int y) const } -void MathLefteqnInset::write(std::ostream & os, bool fragile) const +void MathLefteqnInset::write(MathWriteInfo & os) const { - os << "\\lefteqn{"; - cell(0).write(os, fragile); - os << "}"; + os << "\\lefteqn{" << cell(0) << "}"; } void MathLefteqnInset::writeNormal(std::ostream & os) const { os << "[lefteqn "; - cell(0).write(os, false); + MathWriteInfo wi(os); + cell(0).write(wi); os << "] "; } -void MathLefteqnInset::metrics(MathStyles st) const +void MathLefteqnInset::metrics(MathMetricsInfo const & st) const { MathNestInset::metrics(st); size_ = st; diff --git a/src/mathed/math_lefteqninset.h b/src/mathed/math_lefteqninset.h index de99a1273a..15c37262a9 100644 --- a/src/mathed/math_lefteqninset.h +++ b/src/mathed/math_lefteqninset.h @@ -8,7 +8,7 @@ #pragma interface #endif -/// The \kern primitive +/// Support for LaTeX's \\lefteqn command class MathLefteqnInset : public MathNestInset { public: @@ -19,10 +19,10 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; }; #endif diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index afd872b9a7..7e17da748c 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -69,11 +69,11 @@ bool MathMacro::editing() const } -void MathMacro::metrics(MathStyles st) const +void MathMacro::metrics(MathMetricsInfo const & st) const { if (defining()) { size_ = st; - mathed_string_dim(LM_TC_TEX, size_, name(), ascent_, descent_, width_); + mathed_string_dim(LM_TC_TEX, size_.size, name(), ascent_, descent_, width_); return; } @@ -85,12 +85,12 @@ void MathMacro::metrics(MathStyles st) const ascent_ = expanded_.ascent() + 2; descent_ = expanded_.descent() + 2; - width_ += mathed_string_width(LM_TC_TEXTRM, size_, name()) + 10; + width_ += mathed_string_width(LM_TC_TEXTRM, size_.size, name()) + 10; int lasc; int ldes; int lwid; - mathed_string_dim(LM_TC_TEXTRM, size_, "#1: ", lasc, ldes, lwid); + mathed_string_dim(LM_TC_TEXTRM, size_.size, "#1: ", lasc, ldes, lwid); for (idx_type i = 0; i < nargs(); ++i) { MathXArray const & c = xcell(i); @@ -117,25 +117,25 @@ void MathMacro::draw(Painter & pain, int x, int y) const xo(x); yo(y); - metrics(size()); + metrics(size_); if (defining()) { - drawStr(pain, LM_TC_TEX, size_, x, y, name()); + drawStr(pain, LM_TC_TEX, size_.size, x, y, name()); return; } if (editing()) { int h = y - ascent() + 2 + expanded_.ascent(); - drawStr(pain, LM_TC_TEXTRM, size(), x + 3, h, name()); + drawStr(pain, LM_TC_TEXTRM, size_.size, x + 3, h, name()); - int const w = mathed_string_width(LM_TC_TEXTRM, size(), name()); + int const w = mathed_string_width(LM_TC_TEXTRM, size_.size, name()); expanded_.draw(pain, x + w + 12, h); h += expanded_.descent(); int lasc; int ldes; int lwid; - mathed_string_dim(LM_TC_TEXTRM, size_, "#1: ", lasc, ldes, lwid); + mathed_string_dim(LM_TC_TEXTRM, size_.size, "#1: ", lasc, ldes, lwid); for (idx_type i = 0; i < nargs(); ++i) { MathXArray const & c = xcell(i); @@ -143,7 +143,7 @@ void MathMacro::draw(Painter & pain, int x, int y) const c.draw(pain, x + lwid, h); char str[] = "#1:"; str[1] += static_cast(i); - drawStr(pain, LM_TC_TEX, size(), x + 3, h, str); + drawStr(pain, LM_TC_TEX, size_.size, x + 3, h, str); h += std::max(c.descent(), ldes) + 5; } return; @@ -158,18 +158,18 @@ void MathMacro::dump() const MathMacroTable::dump(); lyxerr << "\n macro: '" << this << "'\n"; lyxerr << " name: '" << name() << "'\n"; - lyxerr << " template: '"; tmplate_->write(lyxerr, false); lyxerr << "'\n"; + lyxerr << " template: '"; + MathWriteInfo wi(lyxerr); + tmplate_->write(wi); + lyxerr << "'\n"; } -void MathMacro::write(std::ostream & os, bool fragile) const +void MathMacro::write(MathWriteInfo & os) const { os << '\\' << name(); - for (idx_type i = 0; i < nargs(); ++i) { - os << '{'; - cell(i).write(os, fragile); - os << '}'; - } + for (idx_type i = 0; i < nargs(); ++i) + os << '{' << cell(i) << '}'; if (nargs() == 0) os << ' '; } diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 05362ee2a0..4460f0bfd5 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -44,11 +44,11 @@ public: /// void draw(Painter &, int x, int y) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index d7a777954d..ab1b217957 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -29,13 +29,13 @@ MathInset * MathMacroArgument::clone() const } -void MathMacroArgument::write(std::ostream & os, bool /*fragile*/) const +void MathMacroArgument::write(MathWriteInfo & os) const { os << '#' << number_; } -void MathMacroArgument::metrics(MathStyles st) const +void MathMacroArgument::metrics(MathMetricsInfo const & st) const { if (expanded_) { xcell(0).metrics(st); @@ -43,7 +43,7 @@ void MathMacroArgument::metrics(MathStyles st) const ascent_ = xcell(0).ascent(); descent_ = xcell(0).descent(); } else - mathed_string_dim(LM_TC_TEX, size(), str_, ascent_, descent_, width_); + mathed_string_dim(LM_TC_TEX, size_.size, str_, ascent_, descent_, width_); } @@ -52,7 +52,7 @@ void MathMacroArgument::draw(Painter & pain, int x, int y) const if (expanded_) xcell(0).draw(pain, x, y); else - drawStr(pain, LM_TC_TEX, size(), x, y, str_); + drawStr(pain, LM_TC_TEX, size_.size, x, y, str_); } diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index 0982ada0d1..c8855d9a87 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -18,11 +18,11 @@ public: /// MathInset * clone() const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 822d0e9211..c217cd1b57 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -47,20 +47,16 @@ string const & MathMacroTemplate::name() const } -void MathMacroTemplate::write(std::ostream & os, bool fragile) const +void MathMacroTemplate::write(MathWriteInfo & os) const { - os << "\n\\newcommand{\\" << name_ << "}"; - + os << "\n\\newcommand{\\" << name_ << '}'; if (numargs_ > 0) - os << "[" << numargs_ << "]"; - - os << "{"; - cell(0).write(os, fragile); - os << "}\n"; + os << '[' << numargs_ << ']'; + os << '{' << cell(0) << "}\n"; } -void MathMacroTemplate::metrics(MathStyles st) const +void MathMacroTemplate::metrics(MathMetricsInfo const & st) const { xcell(0).metrics(st); size_ = st; diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index aeefe5a2ce..4cbe5106ee 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -25,7 +25,7 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// Number of arguments int numargs() const; /// @@ -35,7 +35,7 @@ public: /// void draw(Painter &, int x, int y) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// identifies macro templates MathMacroTemplate * asMacroTemplate() { return this; } private: diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 5e61d8671e..690dc0acad 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -140,9 +140,10 @@ int MathMatrixInset::defaultColSpace(col_type col) } -void MathMatrixInset::metrics(MathStyles) const +void MathMatrixInset::metrics(MathMetricsInfo const & st) const { - size_ = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; + size_ = st; + size_.size = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; // let the cells adjust themselves MathGridInset::metrics(size_); @@ -187,17 +188,15 @@ void MathMatrixInset::draw(Painter & pain, int x, int y) const } -void MathMatrixInset::write(std::ostream & os, bool fragile) const +void MathMatrixInset::write(MathWriteInfo & os) const { - header_write(os); + header_write(os.os); bool n = numberedType(); for (row_type row = 0; row < nrows(); ++row) { - for (col_type col = 0; col < ncols(); ++col) { - cell(index(row, col)).write(os, fragile); - os << eocString(col); - } + for (col_type col = 0; col < ncols(); ++col) + os << cell(index(row, col)) << eocString(col); if (n) { if (!label_[row].empty()) os << "\\label{" << label_[row] << "}"; @@ -207,7 +206,7 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const os << eolString(row); } - footer_write(os); + footer_write(os.os); } diff --git a/src/mathed/math_matrixinset.h b/src/mathed/math_matrixinset.h index 32c5fa43e8..c28020b549 100644 --- a/src/mathed/math_matrixinset.h +++ b/src/mathed/math_matrixinset.h @@ -27,11 +27,11 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 5dccb4b559..9b8a411002 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -48,7 +48,7 @@ void MathNestInset::substitute(MathMacro const & m) } -void MathNestInset::metrics(MathStyles st) const +void MathNestInset::metrics(MathMetricsInfo const & st) const { size_ = st; for (idx_type i = 0; i < nargs(); ++i) @@ -139,12 +139,13 @@ bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const void MathNestInset::dump() const { - lyxerr << "---------------------------------------------\n"; - write(lyxerr, false); - lyxerr << "\n"; + MathWriteInfo os(lyxerr); + os << "---------------------------------------------\n"; + write(os); + os << "\n"; for (idx_type i = 0; i < nargs(); ++i) - lyxerr << cell(i) << "\n"; - lyxerr << "---------------------------------------------\n"; + os << cell(i) << "\n"; + os << "---------------------------------------------\n"; } diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 5cf17786de..8bf33e0038 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -19,7 +19,7 @@ public: explicit MathNestInset(idx_type ncells); /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// draw the object, sets xo_ and yo_ cached values void draw(Painter &, int x, int y) const; /// appends itself with macro arguments substituted diff --git a/src/mathed/math_notinset.C b/src/mathed/math_notinset.C index a187a3173f..9ebbb3f1bf 100644 --- a/src/mathed/math_notinset.C +++ b/src/mathed/math_notinset.C @@ -16,7 +16,7 @@ MathInset * MathNotInset::clone() const } -void MathNotInset::write(ostream & os, bool /* fragile */) const +void MathNotInset::write(MathWriteInfo & os) const { os << "\\not "; } @@ -28,15 +28,13 @@ void MathNotInset::writeNormal(ostream & os) const } -void MathNotInset::metrics(MathStyles st) const +void MathNotInset::metrics(MathMetricsInfo const & st) const { - size(st); + size_ = st; if (math_font_available(LM_TC_CMSY)) - mathed_char_dim(LM_TC_CMSY, size_, 54, - ascent_, descent_, width_); - else - mathed_char_dim(LM_TC_VAR, size_, '/', - ascent_, descent_, width_); + mathed_char_dim(LM_TC_CMSY, size(), 54, ascent_, descent_, width_); + else + mathed_char_dim(LM_TC_VAR, size(), '/', ascent_, descent_, width_); width_ = 0; } @@ -47,7 +45,7 @@ void MathNotInset::draw(Painter & pain, int x, int y) const yo(y); if (math_font_available(LM_TC_CMSY)) - drawChar(pain, LM_TC_CMSY, size_, x, y, 54); + drawChar(pain, LM_TC_CMSY, size(), x, y, 54); else - drawChar(pain, LM_TC_VAR, size_, x, y, '/'); + drawChar(pain, LM_TC_VAR, size(), x, y, '/'); } diff --git a/src/mathed/math_notinset.h b/src/mathed/math_notinset.h index b97d565ffc..cc0dca081b 100644 --- a/src/mathed/math_notinset.h +++ b/src/mathed/math_notinset.h @@ -13,11 +13,11 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; }; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 66d455e4b9..ba70645930 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -889,6 +889,17 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) } array.push_back(MathAtom(p)); } + +/* + // Disabled + else if (t.cs() == "mbox") { + array.push_back(createMathInset(t.cs())); + // slurp in the argument of mbox + + MathBoxInset * p = array.back()->asBoxInset(); + //lyx::assert(p); + } +*/ else if (t.cs().size()) { latexkeys const * l = in_word_set(t.cs()); diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index 7acfa475d9..e49a4f7ce6 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -38,6 +38,8 @@ enum MathTokenEnum /// LM_TK_SYM = 256, /// + LM_TK_BOX, + /// LM_TK_CHOOSE, /// LM_TK_BINOM, diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index 4760854461..c9bd8e6188 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -30,7 +30,7 @@ MathInset * MathRootInset::clone() const } -void MathRootInset::metrics(MathStyles st) const +void MathRootInset::metrics(MathMetricsInfo const & st) const { MathNestInset::metrics(st); size_ = st; @@ -60,13 +60,9 @@ void MathRootInset::draw(Painter & pain, int x, int y) const } -void MathRootInset::write(std::ostream & os, bool fragile) const +void MathRootInset::write(MathWriteInfo & os) const { - os << "\\sqrt["; - cell(0).write(os, fragile); - os << "]{"; - cell(1).write(os, fragile); - os << '}'; + os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}'; } diff --git a/src/mathed/math_rootinset.h b/src/mathed/math_rootinset.h index 5649d0a8f7..95174881c7 100644 --- a/src/mathed/math_rootinset.h +++ b/src/mathed/math_rootinset.h @@ -34,11 +34,11 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// bool idxUp(int & idx, int & pos) const; /// diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index a0ce5ebbc5..cc9c481bdb 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -180,13 +180,14 @@ int MathScriptInset::ndes(MathInset const * nuc) const } -void MathScriptInset::metrics(MathStyles st) const +void MathScriptInset::metrics(MathMetricsInfo const & st) const { metrics(0, st); } -void MathScriptInset::metrics(MathInset const * nuc, MathStyles st) const +void MathScriptInset::metrics(MathInset const * nuc, + MathMetricsInfo const & st) const { MathNestInset::metrics(st); if (nuc) @@ -221,18 +222,17 @@ void MathScriptInset::draw(MathInset const * nuc, Painter & pain, } -void MathScriptInset::write(std::ostream & os, bool fragile) const +void MathScriptInset::write(MathWriteInfo & os) const { //lyxerr << "unexpected call to MathScriptInset::write()\n"; - write(0, os, fragile); + write(0, os); } -void MathScriptInset::write(MathInset const * nuc, std::ostream & os, - bool fragile) const +void MathScriptInset::write(MathInset const * nuc, MathWriteInfo & os) const { if (nuc) { - nuc->write(os, fragile); + nuc->write(os); if (nuc->takesLimits()) { if (limits_ == -1) os << "\\nolimits "; @@ -243,17 +243,11 @@ void MathScriptInset::write(MathInset const * nuc, std::ostream & os, else os << "{}"; - if (hasDown() && down().data_.size()) { - os << "_{"; - down().data_.write(os, fragile); - os << "}"; - } + if (hasDown() && down().data_.size()) + os << "_{" << down().data_ << '}'; - if (hasUp() && up().data_.size()) { - os << "^{"; - up().data_.write(os, fragile); - os << "}"; - } + if (hasUp() && up().data_.size()) + os << "^{" << up().data_ << '}'; } diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 59e0535a68..49337fa80a 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -21,16 +21,16 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// - void write(MathInset const * nucleus, std::ostream &, bool fragile) const; + void write(MathInset const *, MathWriteInfo & os) const; /// - void metrics(MathInset const * nucleus, MathStyles st) const; + void metrics(MathInset const * nucleus, MathMetricsInfo const & st) const; /// void draw(MathInset const * nucleus, Painter &, int x, int y) const; /// diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index 8587e57047..389b233597 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -26,20 +26,20 @@ void MathSizeInset::draw(Painter & pain, int x, int y) const } -void MathSizeInset::metrics(MathStyles /* st */) const +void MathSizeInset::metrics(MathMetricsInfo const & st) const { - xcell(0).metrics(MathStyles(key_->id)); + size_ = st; + size_.size = MathStyles(key_->id); + xcell(0).metrics(size_); ascent_ = xcell(0).ascent_; descent_ = xcell(0).descent_; width_ = xcell(0).width_; } -void MathSizeInset::write(std::ostream & os, bool fragile) const +void MathSizeInset::write(MathWriteInfo & os) const { - os << "{\\" << key_->name << " "; - cell(0).write(os, fragile); - os << "}"; + os << "{\\" << key_->name << ' ' << cell(0) << '}'; } diff --git a/src/mathed/math_sizeinset.h b/src/mathed/math_sizeinset.h index c72ce5e64e..b4e25958c7 100644 --- a/src/mathed/math_sizeinset.h +++ b/src/mathed/math_sizeinset.h @@ -22,11 +22,11 @@ public: /// MathInset * clone() const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index 46408f177e..87b752e884 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -40,7 +40,7 @@ void MathSpaceInset::draw(Painter & pain, int x, int y) const } -void MathSpaceInset::write(std::ostream & os, bool /* fragile */) const +void MathSpaceInset::write(MathWriteInfo & os) const { if (space_ >= 0 && space_ < 6) os << '\\' << latex_mathspace[space_] << ' '; @@ -53,7 +53,7 @@ void MathSpaceInset::writeNormal(std::ostream & os) const } -void MathSpaceInset::metrics(MathStyles st) const +void MathSpaceInset::metrics(MathMetricsInfo const & st) const { size_ = st; width_ = space_ ? space_ * 2 : 2; diff --git a/src/mathed/math_spaceinset.h b/src/mathed/math_spaceinset.h index 96b43441f9..fddaed6130 100644 --- a/src/mathed/math_spaceinset.h +++ b/src/mathed/math_spaceinset.h @@ -19,11 +19,11 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// MathSpaceInset const * asSpaceInset() const { return this; } /// diff --git a/src/mathed/math_specialcharinset.C b/src/mathed/math_specialcharinset.C index 4fe90e80fc..05c34659b7 100644 --- a/src/mathed/math_specialcharinset.C +++ b/src/mathed/math_specialcharinset.C @@ -36,7 +36,7 @@ int MathSpecialCharInset::width() const } -void MathSpecialCharInset::metrics(MathStyles st) const +void MathSpecialCharInset::metrics(MathMetricsInfo const & st) const { size_ = st; } @@ -46,11 +46,11 @@ void MathSpecialCharInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); - drawChar(pain, LM_TC_CONST, size_, x, y, char_); + drawChar(pain, LM_TC_CONST, size(), x, y, char_); } -void MathSpecialCharInset::write(std::ostream & os, bool) const +void MathSpecialCharInset::write(MathWriteInfo & os) const { os << "\\" << char_; } diff --git a/src/mathed/math_specialcharinset.h b/src/mathed/math_specialcharinset.h index 6582868f6d..8fcfbb32c9 100644 --- a/src/mathed/math_specialcharinset.h +++ b/src/mathed/math_specialcharinset.h @@ -20,11 +20,11 @@ public: /// MathInset * clone() const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// diff --git a/src/mathed/math_splitinset.C b/src/mathed/math_splitinset.C index e7b5c18f18..46eab1d065 100644 --- a/src/mathed/math_splitinset.C +++ b/src/mathed/math_splitinset.C @@ -19,13 +19,13 @@ MathInset * MathSplitInset::clone() const } -void MathSplitInset::write(std::ostream & os, bool fragile) const +void MathSplitInset::write(MathWriteInfo & os) const { - if (fragile) + if (os.fragile) os << "\\protect"; os << "\\begin{split}"; - MathGridInset::write(os, fragile); - if (fragile) + MathGridInset::write(os); + if (os.fragile) os << "\\protect"; os << "\\end{split}\n"; } diff --git a/src/mathed/math_splitinset.h b/src/mathed/math_splitinset.h index 2ef9348db9..7c188eca93 100644 --- a/src/mathed/math_splitinset.h +++ b/src/mathed/math_splitinset.h @@ -16,7 +16,7 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// int defaultColSpace(int) { return 0; } /// diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index 956fbb28b9..27cdc56c2c 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -19,7 +19,7 @@ MathInset * MathSqrtInset::clone() const } -void MathSqrtInset::metrics(MathStyles st) const +void MathSqrtInset::metrics(MathMetricsInfo const & st) const { xcell(0).metrics(st); size_ = st; @@ -46,11 +46,9 @@ void MathSqrtInset::draw(Painter & pain, int x, int y) const } -void MathSqrtInset::write(std::ostream & os, bool fragile) const +void MathSqrtInset::write(MathWriteInfo & os) const { - os << "\\sqrt{"; - cell(0).write(os, fragile); - os << '}'; + os << "\\sqrt{" << cell(0) << '}'; } diff --git a/src/mathed/math_sqrtinset.h b/src/mathed/math_sqrtinset.h index cf7c5d89c2..78e3ecedce 100644 --- a/src/mathed/math_sqrtinset.h +++ b/src/mathed/math_sqrtinset.h @@ -20,10 +20,10 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; }; #endif diff --git a/src/mathed/math_stackrelinset.C b/src/mathed/math_stackrelinset.C index 081c3b4c6d..162a8bdf64 100644 --- a/src/mathed/math_stackrelinset.C +++ b/src/mathed/math_stackrelinset.C @@ -17,9 +17,10 @@ MathInset * MathStackrelInset::clone() const } -void MathStackrelInset::metrics(MathStyles st) const +void MathStackrelInset::metrics(MathMetricsInfo const & st) const { - size_ = smallerStyleFrac(st); + size_ = st; + size_.size = smallerStyleFrac(size_.size); xcell(0).metrics(size_); xcell(1).metrics(st); width_ = std::max(xcell(0).width(), xcell(1).width()) + 4; @@ -38,13 +39,9 @@ void MathStackrelInset::draw(Painter & pain, int x, int y) const } -void MathStackrelInset::write(std::ostream & os, bool fragile) const +void MathStackrelInset::write(MathWriteInfo & os) const { - os << "\\stackrel{"; - cell(0).write(os, fragile); - os << "}{"; - cell(1).write(os, fragile); - os << '}'; + os << "\\stackrel{" << cell(0) << "}{" << cell(1) << '}'; } diff --git a/src/mathed/math_stackrelinset.h b/src/mathed/math_stackrelinset.h index 3de330a50f..5c66bdcb79 100644 --- a/src/mathed/math_stackrelinset.h +++ b/src/mathed/math_stackrelinset.h @@ -18,11 +18,11 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; }; diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 10520453ec..dd7915780d 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -16,7 +16,7 @@ MathInset * MathSymbolInset::clone() const } -void MathSymbolInset::write(ostream & os, bool /* fragile */) const +void MathSymbolInset::write(MathWriteInfo & os) const { os << '\\' << sym_->name << ' '; } @@ -58,25 +58,25 @@ MathTextCodes MathSymbolInset::code2() const } -void MathSymbolInset::metrics(MathStyles st) const +void MathSymbolInset::metrics(MathMetricsInfo const & st) const { size_ = st; MathTextCodes Code = code(); if (sym_->latex_font_id > 0 && math_font_available(Code)) { - mathed_char_dim(Code, size_, sym_->latex_font_id, + mathed_char_dim(Code, size(), sym_->latex_font_id, ascent_, descent_, width_); if (Code == LM_TC_CMEX) { h_ = 4*descent_/5; ascent_ += h_; descent_ -= h_; } - } else if (sym_->id > 0 && sym_->id < 255 && - math_font_available(LM_TC_SYMB)) { - mathed_char_dim(code2(), size_, sym_->id, - ascent_, descent_, width_); - } else { - mathed_string_dim(LM_TC_TEX, size_, sym_->name, ascent_, descent_, width_); + return; } + + if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)) + mathed_char_dim(code2(), size(), sym_->id, ascent_, descent_, width_); + else + mathed_string_dim(LM_TC_TEX, size(), sym_->name, ascent_, descent_, width_); } @@ -86,12 +86,11 @@ void MathSymbolInset::draw(Painter & pain, int x, int y) const yo(y); MathTextCodes Code = code(); if (sym_->latex_font_id > 0 && math_font_available(Code)) - drawChar(pain, Code, size_, x, y - h_, sym_->latex_font_id); - else if (sym_->id > 0 && sym_->id < 255 && - math_font_available(LM_TC_SYMB)) - drawChar(pain, code2(), size_, x, y, sym_->id); + drawChar(pain, Code, size(), x, y - h_, sym_->latex_font_id); + else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)) + drawChar(pain, code2(), size(), x, y, sym_->id); else - drawStr(pain, LM_TC_TEX, size_, x, y, sym_->name); + drawStr(pain, LM_TC_TEX, size(), x, y, sym_->name); } @@ -103,7 +102,7 @@ bool MathSymbolInset::isRelOp() const bool MathSymbolInset::isScriptable() const { - return size_ == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX; + return size() == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX; } diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index fa2b5bbf4b..a42f01ba59 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -16,11 +16,11 @@ public: /// MathInset * clone() const; /// - void write(std::ostream &, bool fragile) const; + void write(MathWriteInfo & os) const; /// void writeNormal(std::ostream &) const; /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; /// diff --git a/src/mathed/xarray.C b/src/mathed/xarray.C index 6f3ff8b3ca..ffeee12e3a 100644 --- a/src/mathed/xarray.C +++ b/src/mathed/xarray.C @@ -18,15 +18,15 @@ MathXArray::MathXArray() {} -void MathXArray::metrics(MathStyles st) const +void MathXArray::metrics(MathMetricsInfo const & st) const { - style_ = st; - mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_); + style_ = st.size; + mathed_char_dim(LM_TC_VAR, style_, 'I', ascent_, descent_, width_); if (data_.empty()) return; - math_font_max_dim(LM_TC_TEXTRM, st, ascent_, descent_); + math_font_max_dim(LM_TC_TEXTRM, style_, ascent_, descent_); width_ = 0; //lyxerr << "MathXArray::metrics(): '" << data_ << "'\n"; diff --git a/src/mathed/xarray.h b/src/mathed/xarray.h index 8627f5e62e..b09d6af344 100644 --- a/src/mathed/xarray.h +++ b/src/mathed/xarray.h @@ -24,7 +24,7 @@ public: /// MathXArray(); /// - void metrics(MathStyles st) const; + void metrics(MathMetricsInfo const & st) const; /// void draw(Painter & pain, int x, int y) const;