On Thu, Dec 07, 2006 at 03:18:44PM +0100, Jean-Marc Lasgouttes wrote:
> >>>>> "Enrico" == Enrico Forestieri <[EMAIL PROTECTED]> writes:
>
> >> I'd still like this patch to be done in a slightly cleaner way.
> >> Currently, one can see that the special code for qt 3.2.1nc is
> >> copied in two different file. Enrico, you should model the
> >> ascent/descent caching code on the existing width caching code.
>
> Enrico> Ok. Will I activate the caches for all platforms?
>
> Go for it.
I did that, even if I still cannot see any improvement on *nix.
Anyway, the memory penalty is less than about 200 Kbytes for any
document I test it with.
With this patch LyX/Win 1.4 is again on a par with LyX/X11, if not
a bit more snappier. I would like to know how it performs on Mac.
Revised patch attached.
--
Enrico
Index: src/frontends/qt2/ChangeLog
===================================================================
--- src/frontends/qt2/ChangeLog (revision 16192)
+++ src/frontends/qt2/ChangeLog (working copy)
@@ -1,3 +1,14 @@
+2006-12-07 Enrico Forestieri <[EMAIL PROTECTED]>
+
+ * qfont_loader.[Ch] (width): rename WidthCache as MetricsCache.
+ (ascent, descent): New, return (possibly cached) ascent/descent values.
+
+ * qfont_loader.h: Implement cache for ascent/descent values in the
+ QLFontInfo class.
+
+ * qfont_metrics.C (ascent, descent): use the corresponding methods
+ in QLFontInfo class.
+
2006-10-27 Jean-Marc Lasgouttes <[EMAIL PROTECTED]>
* QtView.C (hasFocus): return a correct value now (and fix bug 1720).
@@ -6,6 +17,7 @@
* QDelimiterDialog.[Ch] (fix_name, QDelimiterDialog, insertClicked,
size_selected): Allow for fixed size delimiters.
+
* ui/QDelimiterDialogBase.ui: Added a combobox for selecting
delimiter size.
Index: src/frontends/qt2/qfont_loader.C
===================================================================
--- src/frontends/qt2/qfont_loader.C (revision 16192)
+++ src/frontends/qt2/qfont_loader.C (working copy)
@@ -364,7 +364,7 @@ int QLFontInfo::width(Uchar val)
// Starting with version 3.1.0, Qt/X11 does its own caching of
// character width, so it is not necessary to provide ours.
#if defined (USE_LYX_FONTCACHE)
- QLFontInfo::WidthCache::const_iterator cit = widthcache.find(val);
+ QLFontInfo::MetricsCache::const_iterator cit = widthcache.find(val);
if (cit != widthcache.end())
return cit->second;
@@ -377,6 +377,54 @@ int QLFontInfo::width(Uchar val)
}
+int QLFontInfo::ascent(char c)
+{
+#if defined(USE_LYX_FONTCACHE)
+ Uchar const val = static_cast<Uchar>(c);
+ QLFontInfo::MetricsCache::const_iterator cit = ascentcache.find(val);
+ if (cit != ascentcache.end())
+ return cit->second;
+#endif
+ QRect const & r = metrics.boundingRect(c);
+ // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
+ // value by the height: (x, -y-height, width, height).
+ // Other versions return: (x, -y, width, height)
+#if defined(Q_WS_WIN) && (QT_VERSION == 0x030201)
+ int const w = -r.top() - r.height();
+#else
+ int const w = -r.top();
+#endif
+#if defined(USE_LYX_FONTCACHE)
+ ascentcache[val] = w;
+#endif
+ return w;
+}
+
+
+int QLFontInfo::descent(char c)
+{
+#if defined(USE_LYX_FONTCACHE)
+ Uchar const val = static_cast<Uchar>(c);
+ QLFontInfo::MetricsCache::const_iterator cit = descentcache.find(val);
+ if (cit != descentcache.end())
+ return cit->second;
+#endif
+ QRect const & r = metrics.boundingRect(c);
+ // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
+ // value by the height: (x, -y-height, width, height).
+ // Other versions return: (x, -y, width, height)
+#if defined(Q_WS_WIN) && (QT_VERSION == 0x030201)
+ int const w = r.bottom() + r.height() + 1;
+#else
+ int const w = r.bottom() + 1;
+#endif
+#if defined(USE_LYX_FONTCACHE)
+ descentcache[val] = w;
+#endif
+ return w;
+}
+
+
bool FontLoader::available(LyXFont const & f)
{
if (!lyx_gui::use_gui)
Index: src/frontends/qt2/qfont_loader.h
===================================================================
--- src/frontends/qt2/qfont_loader.h (revision 16192)
+++ src/frontends/qt2/qfont_loader.h (working copy)
@@ -18,7 +18,7 @@
#include <qfont.h>
#include <qfontmetrics.h>
-#if QT_VERSION < 0x030100 || defined(Q_WS_MACX)
+#ifndef I_AM_AFRAID_OF_FONTCACHE
#define USE_LYX_FONTCACHE
#endif
@@ -36,6 +36,10 @@ public:
/// Return pixel width for the given unicode char
int width(Uchar val);
+ /// Return the pixel ascent for the given unicode char
+ int ascent(char val);
+ /// Return the pixel descent for the given unicode char
+ int descent(char val);
/// The font instance
QFont font;
@@ -43,9 +47,13 @@ public:
QFontMetrics metrics;
#if defined(USE_LYX_FONTCACHE)
- typedef std::map<Uchar, int> WidthCache;
+ typedef std::map<Uchar, int> MetricsCache;
/// Cache of char widths
- WidthCache widthcache;
+ MetricsCache widthcache;
+ /// Cache of char ascents
+ MetricsCache ascentcache;
+ /// Cache of char descents
+ MetricsCache descentcache;
#endif
};
Index: src/frontends/qt2/qfont_metrics.C
===================================================================
--- src/frontends/qt2/qfont_metrics.C (revision 16192)
+++ src/frontends/qt2/qfont_metrics.C (working copy)
@@ -46,15 +46,7 @@ int ascent(char c, LyXFont const & f)
{
if (!lyx_gui::use_gui)
return 1;
- 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).
- // Other versions return: (x, -y, width, height)
-#if defined(Q_WS_WIN) && (QT_VERSION == 0x030201)
- return -r.top() - r.height();
-#else
- return -r.top();
-#endif
+ return fontloader.fontinfo(f).ascent(c);
}
@@ -62,15 +54,7 @@ int descent(char c, LyXFont const & f)
{
if (!lyx_gui::use_gui)
return 1;
- 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).
- // Other versions return: (x, -y, width, height)
-#if defined(Q_WS_WIN) && (QT_VERSION == 0x030201)
- return r.bottom() + r.height() + 1;
-#else
- return r.bottom() + 1;
-#endif
+ return fontloader.fontinfo(f).descent(c);
}
Index: status.14x
===================================================================
--- status.14x (revision 16192)
+++ status.14x (working copy)
@@ -120,6 +120,8 @@ What's new
- Don't reset cell selection when opening tabular dialog (bug 2715).
+- Fix slowness with lots of math on Mac and Windows (bug 2900).
+
* Build/installation:
- Allow autoconf 2.60 for building.