]> git.lyx.org Git - features.git/commitdiff
* enable font metrics cache for all platforms.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 4 Dec 2006 10:09:22 +0000 (10:09 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 4 Dec 2006 10:09:22 +0000 (10:09 +0000)
* 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

src/frontends/FontMetrics.h
src/frontends/qt4/GuiFontMetrics.C
src/frontends/qt4/GuiFontMetrics.h

index 20c7808f9f8b45d098897fb9740c761f58df190a..89890c1ba005ff9e7c3b6dab00cb7c41158752ce 100644 (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.
index ecfe48722e07ae3c5bf8d75683f58db5147b9d11..0b0dbaf085917f1ff580991da80b2373eaabef31 100644 (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
index a3b680d66166c25f848a36f3e4578b89e24302fd..bb320dcce1a79871f4b30a7c05a6ed9120bfa4d2 100644 (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