From: Martin Vermeer Date: Mon, 20 Oct 2003 18:56:48 +0000 (+0000) Subject: Re-introduce display() for insets, fixing various bugs X-Git-Tag: 1.6.10~15928 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=50bbb55cb07642f4fa80fa5659de4826609da8f0;p=lyx.git Re-introduce display() for insets, fixing various bugs git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7940 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index c941076080..0549439755 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-10-20 Martin Vermeer + + * text.C: re-introduce display() for insets, fixing the + various bugs (stretch of line above, math inset + positioning, ...) + 2003-10-20 Jean-Marc Lasgouttes * text.C (rightMargin): remove spurious semicolon diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 8010849776..eb25292ab9 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,11 @@ +2003-10-20 Martin Vermeer + + * inset.h: + * insetfloat.h: + * insetfootlike.h: re-introduce display() for insets, + fixing the various bugs (stretch of line above, math inset + positioning, ...) + 2003-10-17 Lars Gullik Bjønnes * insetbase.C (dispatch): new func diff --git a/src/insets/inset.h b/src/insets/inset.h index 7fd12af7bf..cb0a3850a8 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -274,6 +274,8 @@ public: // is this equivalent to a space (which is BTW different from // a line separator)? virtual bool isSpace() const { return false; } + // should we have a non-filled line before this inset? + virtual bool display() const { return false; } // should we break lines after this inset? virtual bool isLineSeparator() const { return false; } // if this inset has paragraphs should they be output all as default diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index 5416845ac2..2ffa79218e 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -45,6 +45,8 @@ public: /// ~InsetFloat(); /// + virtual bool display() const { return true; } + /// void write(Buffer const & buf, std::ostream & os) const; /// void read(Buffer const & buf, LyXLex & lex); diff --git a/src/insets/insetfootlike.h b/src/insets/insetfootlike.h index c6489f53d3..12615d57a0 100644 --- a/src/insets/insetfootlike.h +++ b/src/insets/insetfootlike.h @@ -28,6 +28,8 @@ public: /// void write(Buffer const & buf, std::ostream & os) const; /// + bool display() const { return true; } + /// bool insetAllowed(InsetOld::Code) const; /** returns true if, when outputing LaTeX, font changes should be closed before generating this inset. This is needed for diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 514983b19f..7c349a3c56 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,9 @@ +2003-10-20 Martin Vermeer + + * formula.[Ch]: re-introduce display() for insets, fixing the + various bugs (stretch of line above, math inset + positioning, ...) + 2003-10-17 Lars Gullik Bjønnes * ref_inset.C (priv_dispatch): take the code from localDispatch diff --git a/src/mathed/formula.C b/src/mathed/formula.C index e6c7cf1939..f5abd3aef2 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -219,7 +219,7 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const //p.pain.rectangle(x, y - a, w, h, LColor::mathframe); } - par_->draw(p, x + offset_, y); + par_->draw(p, x, y); } xo_ = x; @@ -276,13 +276,6 @@ void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const dim.des += 1; } - if (display()) { - offset_ = (m.base.textwidth - dim.wid) / 2; - dim.wid = m.base.textwidth; - } else { - offset_ = 0; - } - dim_ = dim; } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 6a26dce01e..2f8642f521 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -83,8 +83,6 @@ private: /// contents MathAtom par_; - /// x offset for drawing displayed formula - mutable int offset_; /// The pointer never changes although *preview_'s contents may. boost::scoped_ptr const preview_; diff --git a/src/text.C b/src/text.C index 0620599b0e..a3c33d9f8b 100644 --- a/src/text.C +++ b/src/text.C @@ -691,6 +691,21 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, point = i; break; } + InsetOld * in; + // Break before... + if (i + 1 < last) { + in = pit->getInset(i + 1); + if (in && in->display()) { + point = i; + break; + } + // ...and after. + in = pit->getInset(i); + if (in && in->display()) { + point = i; + break; + } + } char const c = pit->getChar(i); if (i > endPosOfFontSpan) { @@ -716,7 +731,7 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, x += thiswidth; chunkwidth += thiswidth; - InsetOld * in = pit->isInset(i) ? pit->getInset(i) : 0; + in = pit->getInset(i); // break before a character that will fall off // the right of the row @@ -1445,14 +1460,32 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, align = LYX_ALIGN_LEFT; } + // Display-style insets should always be on a centred row + // (Simplify this to inset = pit->getInset(rit->pos()) once + // the "bit silly" bug is fixed, MV) + inset = pit->isInset(rit->pos()) ? pit->getInset(rit->pos()) : 0; + if (inset && inset->display()) { + align = LYX_ALIGN_CENTER; + } + switch (align) { case LYX_ALIGN_BLOCK: { int const ns = numberOfSeparators(*pit, *rit); RowList::iterator next_row = boost::next(rit); + bool disp_inset = false; + if (next_row != pit->rows.end()) { + InsetOld * in = pit->getInset(next_row->pos()); + if (in) + disp_inset = in->display(); + } + // If we have separators, this is not the last row of a + // par, does not end in newline, and is not row above a + // display inset... then stretch it if (ns && next_row != pit->rows.end() && !pit->isNewline(next_row->pos() - 1) + && !disp_inset ) { fill_separator = w / ns; } else if (is_rtl) {