namespace lyx {
+class Dimension;
+
namespace frontend {
class FontMetrics
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
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.
#include "qt_helpers.h"
#include "language.h"
+#include "dimension.h"
#include "support/unicode.h"
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
{
return metrics_cache_.value(c).descent;
}
-#endif
-
} // frontend
} // lyx
#include <QFontMetrics>
#include <QHash>
-#if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
-#define USE_LYX_FONTCACHE
-#endif
namespace lyx {
namespace frontend {
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,
bool smallcaps_shape_;
-#ifdef USE_LYX_FONTCACHE
-
/// Cache of char widths
mutable QHash<char_type, int> width_cache_;
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