On Mon, Oct 20, 2003 at 05:20:58PM +0200, Andre Poenitz spake thusly: > > On Mon, Oct 20, 2003 at 06:16:35PM +0300, Martin Vermeer wrote: > > I am pretty confident about this one; it fixes things cleanly in the > > right places with a minimum of fuss. > > > > Attached the slightly cleaned up patch with changelogs. This handles > > now mathinsets, footnote-like and floats. We can extend this as we go. > > > > OK to commit? > > Hm... > > in = pit->isInset(i + 1) ? pit->getInset(i + 1) : 0; > > is identical to > > in = pit->getInset(i + 1); Yes, because i + 1 is always smaller than the past-the-end value of last = pit->size() (line 698)
...yes (line 705) because i is smaller still than that. ... yes (line 1477) because next_row->pos(), if the *row* exists, will point to its first element which will never be past the end. ...NO! (line 1465) because it DOES happen that rit->pos() = pit->size() ... as evidenced by all those statements "getChar() on pos 0 in par id 131 of size 0 is a bit silly !" and easily seen by suitable lyxerr statements as well. Of course this should be fixed. But that's a longer story :-) > Even if being explicit is good in general it looks like line noise, > especically if followed by 'if (inset)' > > In general: > > > > > + // Display-style insets should always be on a centred row > > + inset = pit->isInset(rit->pos()) ? pit->getInset(rit->pos()) : 0; > > + if (inset) { > > + if (inset->display()) { > > + align = LYX_ALIGN_CENTER; > > + } > > + } > > could be > > if (inset && inset->display()) { > align = LYX_ALIGN_CENTER; > } Yes. Did this throughout. ... > > int const ns = numberOfSeparators(*pit, *rit); > > RowList::iterator next_row = boost::next(rit); > > + bool disp_inset(false); > > and this: > > bool disp_inset = false; > > Even if we could have a nice philosophical debate on use and abuse of > function-style initializing, fact is that >95% of LyX code use the '=' > version. Be consistent. OK. > > > + if (next_row != pit->rows.end()) { > > + inset = pit->isInset(next_row->pos()) ? > > + pit->getInset(next_row->pos()) : 0; > > + if (inset) > > + disp_inset = inset->display(); > > + } > > Is this 'inset' variable used 'globally'? No. Ok, I think I see your point. > But generally it looks ok (even whitespace...) so if it makes you happy > I don't oppose to committing it. > > Andre' Thanks! New version attached. - Martin
Index: ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.1637 diff -u -p -r1.1637 ChangeLog --- ChangeLog 20 Oct 2003 13:55:50 -0000 1.1637 +++ ChangeLog 20 Oct 2003 16:59:04 -0000 @@ -1,3 +1,9 @@ +2003-10-20 Martin Vermeer <[EMAIL PROTECTED]> + + * text.C: re-introduce display() for insets, fixing the + various bugs (stretch of line above, math inset + positioning, ...) + 2003-10-20 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> * text.C (rightMargin): remove spurious semicolon Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.465 diff -u -p -r1.465 text.C --- text.C 20 Oct 2003 13:55:51 -0000 1.465 +++ text.C 20 Oct 2003 16:59:04 -0000 @@ -691,6 +691,21 @@ pos_type LyXText::rowBreakPoint(Paragrap 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(Paragrap 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(ParagraphLi 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) { Index: insets/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v retrieving revision 1.873 diff -u -p -r1.873 ChangeLog --- insets/ChangeLog 17 Oct 2003 18:01:12 -0000 1.873 +++ insets/ChangeLog 20 Oct 2003 16:59:04 -0000 @@ -1,3 +1,11 @@ +2003-10-20 Martin Vermeer <[EMAIL PROTECTED]> + + * 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 <[EMAIL PROTECTED]> * insetbase.C (dispatch): new func Index: insets/inset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v retrieving revision 1.127 diff -u -p -r1.127 inset.h --- insets/inset.h 15 Oct 2003 08:49:43 -0000 1.127 +++ insets/inset.h 20 Oct 2003 16:59:04 -0000 @@ -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 Index: insets/insetfloat.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfloat.h,v retrieving revision 1.54 diff -u -p -r1.54 insetfloat.h --- insets/insetfloat.h 17 Oct 2003 18:01:12 -0000 1.54 +++ insets/insetfloat.h 20 Oct 2003 16:59:04 -0000 @@ -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); Index: insets/insetfootlike.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfootlike.h,v retrieving revision 1.20 diff -u -p -r1.20 insetfootlike.h --- insets/insetfootlike.h 28 Aug 2003 07:41:29 -0000 1.20 +++ insets/insetfootlike.h 20 Oct 2003 16:59:04 -0000 @@ -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 Index: mathed/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v retrieving revision 1.393 diff -u -p -r1.393 ChangeLog --- mathed/ChangeLog 17 Oct 2003 18:01:15 -0000 1.393 +++ mathed/ChangeLog 20 Oct 2003 16:59:05 -0000 @@ -1,3 +1,9 @@ +2003-10-20 Martin Vermeer <[EMAIL PROTECTED]> + + * 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 <[EMAIL PROTECTED]> * ref_inset.C (priv_dispatch): take the code from localDispatch Index: mathed/formula.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.C,v retrieving revision 1.302 diff -u -p -r1.302 formula.C --- mathed/formula.C 14 Oct 2003 21:30:22 -0000 1.302 +++ mathed/formula.C 20 Oct 2003 16:59:05 -0000 @@ -219,7 +219,7 @@ void InsetFormula::draw(PainterInfo & pi //p.pain.rectangle(x, y - a, w, h, LColor::mathframe); } - par_->draw(p, x + offset_, y); + par_->draw(p, x, y); } xo_ = x; @@ -274,13 +274,6 @@ void InsetFormula::metrics(MetricsInfo & par()->metrics(mi, dim); dim.asc += 1; dim.des += 1; - } - - if (display()) { - offset_ = (m.base.textwidth - dim.wid) / 2; - dim.wid = m.base.textwidth; - } else { - offset_ = 0; } dim_ = dim; Index: mathed/formula.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.h,v retrieving revision 1.102 diff -u -p -r1.102 formula.h --- mathed/formula.h 10 Oct 2003 21:08:55 -0000 1.102 +++ mathed/formula.h 20 Oct 2003 16:59:05 -0000 @@ -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<RenderPreview> const preview_;
pgp00000.pgp
Description: PGP signature