* enable font metrics cache for all platforms.

* introduce defaultDimension() and dimension() in preparation of Dimension class cleanup.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16165 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-12-04 10:09:22 +00:00
parent a0534e02c1
commit e318e0e4ef
3 changed files with 15 additions and 23 deletions

View File

@ -47,6 +47,8 @@
namespace lyx {
class Dimension;
namespace frontend {
class FontMetrics
@ -58,6 +60,9 @@ public:
virtual int maxAscent() const = 0;
/// return the maximum descent of the font
virtual int maxDescent() const = 0;
/// return default dimension of the font.
/// \warning \c width is set to zero.
virtual Dimension const defaultDimension() const = 0;
/// return the width of the char in the font
virtual int width(char_type c) const = 0;
/// return the ascent of the char in the font
@ -72,6 +77,8 @@ public:
virtual int width(char_type const * s, size_t n) const = 0;
/// FIXME ??
virtual int signedWidth(docstring const & s) const = 0;
/// return char dimension for the font.
virtual Dimension const dimension(char_type c) const = 0;
/**
* fill in width,ascent,descent with the values for the
* given string in the font.

View File

@ -16,6 +16,7 @@
#include "qt_helpers.h"
#include "language.h"
#include "dimension.h"
#include "support/unicode.h"
@ -155,22 +156,18 @@ void GuiFontMetrics::buttonText(docstring const & str,
descent = metrics_.descent() + d;
}
#ifndef USE_LYX_FONTCACHE
int GuiFontMetrics::ascent(char_type c) const
Dimension const GuiFontMetrics::defaultDimension() const
{
QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
return -r.top();
return Dimension(maxAscent(), maxDescent(), 0);
}
int GuiFontMetrics::descent(char_type c) const
Dimension const GuiFontMetrics::dimension(char_type c) const
{
QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
return r.bottom() + 1;
return Dimension(ascent(c), descent(c), width(c));
}
#else
void GuiFontMetrics::fillMetricsCache(char_type c) const
{
@ -209,7 +206,5 @@ int GuiFontMetrics::descent(char_type c) const
return metrics_cache_.value(c).descent;
}
#endif
} // frontend
} // lyx

View File

@ -19,9 +19,6 @@
#include <QFontMetrics>
#include <QHash>
#if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
#define USE_LYX_FONTCACHE
#endif
namespace lyx {
namespace frontend {
@ -37,19 +34,16 @@ public:
virtual int maxAscent() const;
virtual int maxDescent() const;
#ifndef USE_LYX_FONTCACHE
virtual int width(char_type c) const {
return metrics_.width(QChar(static_cast<short int>(c)));
}
#else
virtual Dimension const defaultDimension() const;
virtual int width(char_type c) const;
#endif
virtual int ascent(char_type c) const;
virtual int descent(char_type c) const;
virtual int lbearing(char_type c) const;
virtual int rbearing(char_type c) const;
virtual int width(char_type const * s, size_t n) const;
virtual int signedWidth(docstring const & s) const;
virtual Dimension const dimension(char_type c) const;
virtual void rectText(docstring const & str,
int & width,
int & ascent,
@ -70,8 +64,6 @@ private:
bool smallcaps_shape_;
#ifdef USE_LYX_FONTCACHE
/// Cache of char widths
mutable QHash<char_type, int> width_cache_;
@ -83,8 +75,6 @@ private:
mutable QHash<char_type, AscendDescend> metrics_cache_;
/// fill in \c metrics_cache_ at specified value.
void fillMetricsCache(char_type) const;
#endif // USE_LYX_FONTCACHE
};
} // namespace frontend