From f5e68ec257e1d18c1b94f165377dfab06c1e553e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 18 Jul 2005 12:13:32 +0000 Subject: [PATCH] fix bug 1795 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10321 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/FontIterator.C | 4 ++-- src/coordcache.C | 2 ++ src/coordcache.h | 25 ++++++++++++++++++++----- src/paragraph.C | 6 +++--- src/paragraph.h | 18 +++++++++++++----- src/rowpainter.C | 5 ++--- src/text.C | 37 ++++++++++++++++++++++--------------- src/text3.C | 2 +- 8 files changed, 65 insertions(+), 34 deletions(-) diff --git a/src/FontIterator.C b/src/FontIterator.C index 0ff120d203..ac3f52170d 100644 --- a/src/FontIterator.C +++ b/src/FontIterator.C @@ -22,7 +22,7 @@ FontIterator::FontIterator(LyXText const & text, Paragraph const & par, lyx::pos_type pos) : text_(text), par_(par), pos_(pos), font_(text.getFont(par, pos)), - endspan_(par.getFontSpan(pos).second), + endspan_(par.fontSpan(pos).last), bodypos_(par.beginOfBody()) {} @@ -44,7 +44,7 @@ FontIterator & FontIterator::operator++() ++pos_; if (pos_ > endspan_ || pos_ == bodypos_) { font_ = text_.getFont(par_, pos_); - endspan_ = par_.getFontSpan(pos_).second; + endspan_ = par_.fontSpan(pos_).last; } return *this; } diff --git a/src/coordcache.C b/src/coordcache.C index 7cc1a4beea..956ed41a9a 100644 --- a/src/coordcache.C +++ b/src/coordcache.C @@ -37,6 +37,8 @@ void CoordCache::clear() arrays_.clear(); insets_.clear(); pars_.clear(); + slices0_.clear(); + slices1_.clear(); } diff --git a/src/coordcache.h b/src/coordcache.h index 9d92388f21..79847020cf 100644 --- a/src/coordcache.h +++ b/src/coordcache.h @@ -42,7 +42,6 @@ public: int x_, y_; }; - template class CoordCacheBase { public: void clear() @@ -122,6 +121,8 @@ public: typedef std::map InnerParPosCache; /// A map from a LyXText to the map of paragraphs to screen points typedef std::map ParPosCache; + /// A map from a CursorSlice to screen points + typedef std::map SliceCache; /// A map from MathArray to position on the screen CoordCacheBase & arrays() { BOOST_ASSERT(updating); return arrays_; } @@ -132,14 +133,28 @@ public: /// A map from (LyXText, paragraph) pair to screen positions ParPosCache & parPos() { BOOST_ASSERT(updating); return pars_; } ParPosCache const & getParPos() const { return pars_; } + /// + SliceCache & slice(bool boundary) + { + BOOST_ASSERT(updating); + return boundary ? slices1_ : slices0_; + } + SliceCache const & getSlice(bool boundary) const + { + return boundary ? slices1_ : slices0_; + } + private: + /// MathArrays CoordCacheBase arrays_; - - // all insets + // All insets CoordCacheBase insets_; - - // paragraph grouped by owning text + /// Paragraph grouped by owning text ParPosCache pars_; + /// Used with boundary == 0 + SliceCache slices0_; + /// Used with boundary == 1 + SliceCache slices1_; /** * Debugging flag only: Set to true while the cache is being built. diff --git a/src/paragraph.C b/src/paragraph.C index 93003af27c..1c8905a331 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -339,7 +339,7 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams, } -std::pair Paragraph::getFontSpan(lyx::pos_type pos) const +FontSpan Paragraph::fontSpan(lyx::pos_type pos) const { BOOST_ASSERT(pos <= size()); lyx::pos_type start = 0; @@ -348,14 +348,14 @@ std::pair Paragraph::getFontSpan(lyx::pos_type pos Pimpl::FontList::const_iterator end = pimpl_->fontlist.end(); for (; cit != end; ++cit) { if (cit->pos() >= pos) - return std::make_pair(start, cit->pos()); + return FontSpan(start, cit->pos()); start = cit->pos() + 1; } // This should not happen, but if so, we take no chances. //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!" // << endl; - return std::make_pair(pos, pos); + return FontSpan(pos, pos); } diff --git a/src/paragraph.h b/src/paragraph.h index 2002676b04..9eeef130fb 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -27,7 +27,6 @@ #include "support/types.h" #include -#include class Buffer; class BufferParams; @@ -47,6 +46,15 @@ class ParagraphParameters; class TexRow; +class FontSpan { +public: + FontSpan() : first(0), last(0) {} + FontSpan(lyx::pos_type f, lyx::pos_type l) : first(f), last(l) {} + lyx::pos_type first; + lyx::pos_type last; +}; + + /// A Paragraph holds all text, attributes and insets in a text paragraph class Paragraph { public: @@ -279,11 +287,11 @@ public: /** * The font returned by the above functions is the same in a * span of characters. This method will return the first and - * the last last positions in the paragraph for which that - * font is the same. This can be used to avoid unnecessary - * calls to getFont. + * the last positions in the paragraph for which that font is + * the same. This can be used to avoid unnecessary calls to + * getFont. */ - std::pair getFontSpan(lyx::pos_type pos) const; + FontSpan fontSpan(lyx::pos_type pos) const; /// /// this is a bottleneck. value_type getChar(lyx::pos_type pos) const { return text_[pos]; } diff --git a/src/rowpainter.C b/src/rowpainter.C index 1c0e9dbf59..dfbeed0b0a 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -255,8 +255,7 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font, { pos_type pos = text_.bidi.vis2log(vpos); pos_type const end = row_.endpos(); - std::pair const font_span - = par_.getFontSpan(pos); + FontSpan const font_span = par_.fontSpan(pos); Change::Type const prev_change = par_.lookupChange(pos); // first character @@ -270,7 +269,7 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font, // collect as much similar chars as we can for (++vpos ; vpos < end ; ++vpos) { pos = text_.bidi.vis2log(vpos); - if (pos < font_span.first || pos > font_span.second) + if (pos < font_span.first || pos > font_span.last) break; if (prev_change != par_.lookupChange(pos)) diff --git a/src/text.C b/src/text.C index 8824bd3b6c..6a6922c561 100644 --- a/src/text.C +++ b/src/text.C @@ -701,24 +701,21 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const pos_type i = pos; for ( ; i < end; ++i, ++fi) { char const c = par.getChar(i); + int thiswidth = singleWidth(par, i, c, *fi); - { - int thiswidth = singleWidth(par, i, c, *fi); - - // add the auto-hfill from label end to the body - if (body_pos && i == body_pos) { - int add = font_metrics::width(layout->labelsep, getLabelFont(par)); - if (par.isLineSeparator(i - 1)) - add -= singleWidth(par, i - 1); - - add = std::max(add, labelEnd(pit) - x); - thiswidth += add; - } + // add the auto-hfill from label end to the body + if (body_pos && i == body_pos) { + int add = font_metrics::width(layout->labelsep, getLabelFont(par)); + if (par.isLineSeparator(i - 1)) + add -= singleWidth(par, i - 1); - x += thiswidth; - chunkwidth += thiswidth; + add = std::max(add, labelEnd(pit) - x); + thiswidth += add; } + x += thiswidth; + chunkwidth += thiswidth; + // break before a character that will fall off // the right of the row if (x >= width) { @@ -2103,6 +2100,10 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const (body_pos > end || !par.isLineSeparator(body_pos - 1))) body_pos = 0; + // Use font span to speed things up, see below + FontSpan font_span = par.fontSpan(row_pos); + LyXFont font = getFont(par, row_pos); + for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) { pos_type pos = bidi.vis2log(vpos); if (body_pos > 0 && pos == body_pos - 1) { @@ -2113,7 +2114,13 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const x -= singleWidth(par, body_pos - 1); } - x += singleWidth(par, pos); + // Use font span to speed things up, see above + if (pos < font_span.first || pos > font_span.last) { + font_span = par.fontSpan(pos); + font = getFont(par, pos); + } + + x += singleWidth(par, pos, par.getChar(pos), font); if (hfillExpansion(par, row, pos)) x += (pos >= body_pos) ? m.hfill : m.label_hfill; diff --git a/src/text3.C b/src/text3.C index e432525951..0db15288d9 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1520,7 +1520,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) default: lyxerr << BOOST_CURRENT_FUNCTION - << " Not DISPATCHED by LyXText" << endl; + << ": Command " << cmd << " not DISPATCHED by LyXText" << endl; cur.undispatched(); break; } -- 2.39.5