]> git.lyx.org Git - features.git/commitdiff
fix bug 1795
authorAndré Pönitz <poenitz@gmx.net>
Mon, 18 Jul 2005 12:13:32 +0000 (12:13 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 18 Jul 2005 12:13:32 +0000 (12:13 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10321 a592a061-630c-0410-9148-cb99ea01b6c8

src/FontIterator.C
src/coordcache.C
src/coordcache.h
src/paragraph.C
src/paragraph.h
src/rowpainter.C
src/text.C
src/text3.C

index 0ff120d2038d04d4ff52fc4d2ed88a8eafa6158a..ac3f52170d6b6c2cf9dde1fbbc8d13c2eae3d160 100644 (file)
@@ -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;
 }
index 7cc1a4beeaf7db9a99b654040658918a7ebdecb5..956ed41a9a98a11e21b90c1a3f33b88cf6b39a27 100644 (file)
@@ -37,6 +37,8 @@ void CoordCache::clear()
        arrays_.clear();
        insets_.clear();
        pars_.clear();
+       slices0_.clear();
+       slices1_.clear();
 }
 
 
index 9d92388f2177852149da5a5a22e247b1068865fd..79847020cfce61bfe2f662c5d57301321af2024e 100644 (file)
@@ -42,7 +42,6 @@ public:
        int x_, y_;
 };
 
-
 template <class T> class CoordCacheBase {
 public:
        void clear()
@@ -122,6 +121,8 @@ public:
        typedef std::map<lyx::pit_type, Point> InnerParPosCache;
        /// A map from a LyXText to the map of paragraphs to screen points
        typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
+       /// A map from a CursorSlice to screen points
+       typedef std::map<LyXText const *, InnerParPosCache> SliceCache;
 
        /// A map from MathArray to position on the screen
        CoordCacheBase<MathArray> & 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<MathArray> arrays_;
-
-       // all insets
+       // All insets
        CoordCacheBase<InsetBase> 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.
index 93003af27c41aa00e22367a4c4d0ca841602bb5b..1c8905a331bbf1f9dafd88c45ef7a9d4a8df14a6 100644 (file)
@@ -339,7 +339,7 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
 }
 
 
-std::pair<lyx::pos_type, lyx::pos_type> 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<lyx::pos_type, lyx::pos_type> 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);
 }
 
 
index 2002676b04e065b34b28ae606244bd193482ec57..9eeef130fb4e96795582347e177d2e90193ef991 100644 (file)
@@ -27,7 +27,6 @@
 #include "support/types.h"
 
 #include <string>
-#include <utility>
 
 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<lyx::pos_type, lyx::pos_type> 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]; }
index 1c0e9dbf59ab5594775f54ec84d61b8d5c86aa4e..dfbeed0b0a24034d1f24c36ee3b6b54ab26f8bba 100644 (file)
@@ -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<lyx::pos_type, lyx::pos_type> 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))
index 8824bd3b6c3deffb408d998ac381e9a2179dff68..6a6922c561a97731c3d84806204ece667efa45c8 100644 (file)
@@ -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;
index e43252595113b7d861dfc7b5ea9af006e54b1ffd..0db15288d93512d72b5d470c2a7b7593d040a968 100644 (file)
@@ -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;
        }