Enrico Forestieri wrote:
On Wed, Dec 06, 2006 at 04:30:09PM +0100, Jean-Marc Lasgouttes wrote:
"Enrico" == Enrico Forestieri <[EMAIL PROTECTED]> writes:
 I would be very interested, but I will need a windows user to do
that for me, since I cannot really test. Anyway caching ascent and
descent looks like a good idea.
Enrico> Jean-Marc are you looking at this? I had a quick look but I
Enrico> fear that backporting the patch is not as trivial as I would
Enrico> have hoped.

I would if I had time. Currently, my free time is ridiculously low. So
I won't look at this these next weeks :(

Of course, after I got my coffee it occurred to me that I should had
not tried to backport the patch but rather its philosopy...

Right!
Good job ;-)


Please, find attached a patch that caches ascent and descent values
on Windows and Mac. I don't activate the cache on *nix because I
cannot see a noticeable improvement (I could have sworn I would have
seen it), but this is a 'feeling' as I don't performed any measurement.

I think you should enable it for all platform. IIRC, some people reported that scrolling was slow with the test document.


LyX 1.4 is now usable at least as 1.3.7 was on Windows ;-)



Jean-Marc, can I apply the patch?

BTW, I noticed that LyX crashes if you press page down right after
loading this document:
http://bugzilla.lyx.org/attachment.cgi?id=1296&action=view

I cannot access this link and 1296 doesn't seem to be related. But, FYI I solved the same crash in 1.5. I thought it was 1.5 specific but perhaps not, here it the patch (more comments about your patch below):

Author: younes
Date: Tue Nov 28 18:24:44 2006
New Revision: 16092

URL: http://www.lyx.org/trac/changeset/16092
Log:
* LyXText::cursorNext(): Fix crash with PageDown when the next paragraph is a math inset bigger than the screen.
* LyXText::cursorPrevious(): Implement the same check for safety reason.


Modified:
    lyx-devel/trunk/src/text3.C

Modified: lyx-devel/trunk/src/text3.C
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/text3.C?rev=16092
==============================================================================
--- lyx-devel/trunk/src/text3.C (original)
+++ lyx-devel/trunk/src/text3.C Tue Nov 28 18:24:44 2006
@@ -207,12 +207,18 @@

// FIXME: there would maybe a need for this 'updated' boolean in the future...
        bool updated = setCursorFromCoordinates(cur, x, 0);
-       updated |= cursorUp(cur);
+       if (cur.inMathed())
+               updated |= cur.up();
+       else
+               updated |= cursorUp(cur);

        if (cpar == cur.pit() && cpos == cur.pos()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the previous row instead.
-               updated |= cursorUp(cur);
+               if (cur.inMathed())
+                       updated |= cur.up();
+               else
+                       updated |= cursorUp(cur);
        }

        finishUndo();
@@ -228,12 +234,18 @@
        int x = cur.x_target();
// FIXME: there would maybe a need for this 'updated' boolean in the future... bool updated = setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
-       updated |= cursorDown(cur);
+       if (cur.inMathed())
+               updated |= cur.down();
+       else
+               updated |= cursorDown(cur);

        if (cpar == cur.pit() && cpos == cur.pos()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
-               updated |= cursorDown(cur);
+               if (cur.inMathed())
+                       updated |= cur.down();
+               else
+                       updated |= cursorDown(cur);
        }

        finishUndo();



The crash occurs with or without this patch, though. I also attach
the backtrace I get on linux.


Index: src/frontends/qt2/qfont_loader.h
===================================================================
--- src/frontends/qt2/qfont_loader.h    (revision 16192)
+++ src/frontends/qt2/qfont_loader.h    (working copy)
@@ -22,7 +22,11 @@
 #define USE_LYX_FONTCACHE
 #endif
-#if defined(USE_LYX_FONTCACHE)
+#if defined(Q_WS_MACX) || defined(Q_WS_WIN)
+#define USE_LYX_FONTMETRICSCACHE
+#endif
+
+#if defined(USE_LYX_FONTCACHE) || defined(USE_LYX_FONTMETRICSCACHE)

Why are you distinguishing the two? The width cache is also a font metrics cache. You only need one macro.

 #include <map>
 #endif
@@ -47,6 +51,14 @@ public:
        /// Cache of char widths
        WidthCache widthcache;

Same here, WidthCache is the same as your MetricsCache below. Just define one type used for all three caches.

 #endif
+
+#if defined(USE_LYX_FONTMETRICSCACHE)
+       typedef std::map<char, int> MetricsCache;
+       /// Cache of char ascents
+       MetricsCache ascentcache;
+       /// Cache of char descents
+       MetricsCache descentcache;
+#endif
 };
@@ -75,6 +87,14 @@ public:
                return fontinfo(f).metrics;
        }
+#if defined(USE_LYX_FONTMETRICSCACHE)
+       /// Get the ascent QFont metric for this LyXFont
+       int ascent(LyXFont const & f, char c);
+
+       /// Get the descent QFont metric for this LyXFont
+       int descent(LyXFont const & f, char c);
+#endif
+
        /// Called before QApplication is initialized
        static void initFontPath();
Index: src/frontends/qt2/qfont_metrics.C
===================================================================
--- src/frontends/qt2/qfont_metrics.C   (revision 16192)
+++ src/frontends/qt2/qfont_metrics.C   (working copy)
@@ -46,6 +46,9 @@ int ascent(char c, LyXFont const & f)
 {
        if (!lyx_gui::use_gui)
                return 1;
+#if defined(USE_LYX_FONTMETRICSCACHE)
+       return fontloader.ascent(f, c);
+#else
        QRect const & r = fontloader.metrics(f).boundingRect(c);
        // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
        // value by the height: (x, -y-height, width, height).
@@ -55,6 +58,7 @@ int ascent(char c, LyXFont const & f)
 #else
        return -r.top();
 #endif
+#endif
 }
@@ -62,6 +66,9 @@ int descent(char c, LyXFont const & f)
 {
        if (!lyx_gui::use_gui)
                return 1;
+#if defined(USE_LYX_FONTMETRICSCACHE)
+       return fontloader.descent(f, c);
+#else
        QRect const & r = fontloader.metrics(f).boundingRect(c);
        // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
        // value by the height: (x, -y-height, width, height).
@@ -71,6 +78,7 @@ int descent(char c, LyXFont const & f)
 #else
        return r.bottom() + 1;
 #endif
+#endif
 }

------------------------------------------------------------------------

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1491155264 (LWP 32374)]
0x080e7141 in CursorSlice::paragraph ()
(gdb) bt
#0  0x080e7141 in CursorSlice::paragraph ()
#1  0x0819ca87 in LyXText::cursorDown ()
#2  0x0819d2f4 in LyXText::cursorNext ()
#3  0x0819f1aa in LyXText::dispatch ()
#4  0x080e64e4 in LCursor::dispatch ()
#5  0x081266e9 in LyXFunc::dispatch ()
#6  0x0812f5db in LyXFunc::processKeySym ()
#7  0x080659fc in BufferView::Pimpl::workAreaKeyPress ()
#8  0x08072b84 in boost::detail::function::void_function_obj_invoker2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, 
BufferView::Pimpl, boost::shared_ptr<LyXKeySym>, key_modifier::state>, 
boost::_bi::list3<boost::_bi::value<BufferView::Pimpl*>, boost::arg<1> (*)(), boost::arg<2> (*)()> >, 
void, boost::shared_ptr<LyXKeySym>, key_modifier::state>::invoke ()
#9  0x0838709d in boost::function2<void, boost::shared_ptr<LyXKeySym>, 
key_modifier::state, std::allocator<void> >::operator() ()
#10 0x083873c9 in 
boost::operator++<boost::signals::detail::slot_call_iterator<boost::signals::detail::call_bound2<void>::caller<boost::shared_ptr<LyXKeySym>,
 key_modifier::state, boost::function<void ()(boost::shared_ptr<LyXKeySym>, key_modifier::state), 
std::allocator<void> > >, boost::signals::detail::named_slot_map_iterator>, boost::signals::detail::unusable, 
boost::single_pass_traversal_tag, boost::signals::detail::unusable const&, int> ()
#11 0x08387b90 in boost::signal2<void, boost::shared_ptr<LyXKeySym>, key_modifier::state, 
boost::last_value<void>, int, std::less<int>, boost::function<void ()(---Type <return> to 
continue, or q <return> to quit---
boost::shared_ptr<LyXKeySym>, key_modifier::state), std::allocator<void> > 
>::operator() ()
#12 0x08386434 in QContentPane::keyeventTimeout ()
#13 0x0838f098 in QContentPane::qt_invoke ()
#14 0xa7addcb3 in QObject::activate_signal () from /usr/lib/libqt-mt.so.3
#15 0xa7ade744 in QObject::activate_signal () from /usr/lib/libqt-mt.so.3
#16 0xa7e68db6 in QTimer::timeout () from /usr/lib/libqt-mt.so.3
#17 0xa7b05567 in QTimer::event () from /usr/lib/libqt-mt.so.3
#18 0xa7a75bd6 in QApplication::internalNotify () from /usr/lib/libqt-mt.so.3
#19 0xa7a779f3 in QApplication::notify () from /usr/lib/libqt-mt.so.3
#20 0xa7a093d1 in QApplication::sendEvent () from /usr/lib/libqt-mt.so.3
#21 0xa7a685d3 in QEventLoop::activateTimers () from /usr/lib/libqt-mt.so.3
#22 0xa7a1d71f in QEventLoop::processEvents () from /usr/lib/libqt-mt.so.3
#23 0xa7a90129 in QEventLoop::enterLoop () from /usr/lib/libqt-mt.so.3
#24 0xa7a8ff4a in QEventLoop::exec () from /usr/lib/libqt-mt.so.3
#25 0xa7a7776f in QApplication::exec () from /usr/lib/libqt-mt.so.3
#26 0x082c651b in lyx_gui::start ()
#27 0x081165f9 in LyX::exec2 ()
#28 0x082c6075 in lyx_gui::exec ()
#29 0x08116c88 in LyX::priv_exec ()
#30 0x08116dcc in LyX::exec ()
#31 0x0806262a in main ()


Reply via email to