Cache width, ascent, and descent font metrics as their calculation may be

really expensive on some platforms.

	* src/frontends/qt2/qfont_loader.[Ch]
	(QLFontInfo::width): rename WidthCache as MetricsCache.
	(QLFontInfo::ascent,QLFontInfo::descent): new, return (possibly cached)
	ascent/descent values.

	* src/frontends/qt2/qfont_loader.h:
	implement cache for ascent/descent values in the QLFontInfo class.

	* src/frontends/qt2/qfont_metrics.C
	(ascent, descent): use the corresponding methods in QLFontInfo class.
	Remove support for obsolete Qt/Win 3.2.1nc.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@16224 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2006-12-10 02:25:05 +00:00
parent 2a436e855d
commit 2800f35900
5 changed files with 66 additions and 22 deletions

View File

@ -1,3 +1,14 @@
2006-12-09 Enrico Forestieri <forenr@tlc.unipr.it>
* 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. Remove support for obsolete Qt/Win 3.2.1nc.
2006-10-27 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* 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.

View File

@ -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,44 @@ 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;
QRect const & r = metrics.boundingRect(c);
int const w = -r.top();
ascentcache[val] = w;
return w;
#else
QRect const & r = metrics.boundingRect(c);
return -r.top();
#endif
}
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;
QRect const & r = metrics.boundingRect(c);
int const w = r.bottom() + 1;
descentcache[val] = w;
return w;
#else
QRect const & r = metrics.boundingRect(c);
return r.bottom() + 1;
#endif
}
bool FontLoader::available(LyXFont const & f)
{
if (!lyx_gui::use_gui)

View File

@ -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
};

View File

@ -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);
}

View File

@ -122,6 +122,8 @@ What's new
- Don't reset cell selection when opening tabular dialog (bug 2715).
- Fix slowness with lots of math on Windows (bug 2900).
* Build/installation:
- Allow autoconf 2.60 for building.