]> git.lyx.org Git - features.git/commitdiff
This commit is a big rework of the FontLoader/FontMetrics interaction. Only Qt4 for...
authorAbdelrazak Younes <younes@lyx.org>
Sat, 7 Oct 2006 16:15:06 +0000 (16:15 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 7 Oct 2006 16:15:06 +0000 (16:15 +0000)
Basically, I replaced all methods in the font_metrics namespace by a proper virtual interface FontMetrics. The FontLoader is _the_ container for FontMetrics.

This patch should also bring some optimizations in a number of place in the code. This is because we do not need any more to search for the LyXFont at each font_metrics call. In effect, the speed advantage is not as sensible and this is a bit deceiving considering that this was my primary motivation behind the patch. But I like the patch anyway as it cleans up the relation and interfacing between fonts, metrics and frontends.

* frontends/FontMetrics.h: new virtual interface. Renamed from font_metrics.h

* qt4/GuiFontMetrics: corresponding qt4 implememtation. Renamed from qfont_metrics.C. The smallCaps particular case treatment has been transfered here as well as the width cache for MacOSX and Windows.

* qt4/QLPainter.C: the smallCapsText has been reworked to return the width of the drawn text.C

all other files: replace font_metric helper function call with corresponding FontMetrics method calls.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15265 a592a061-630c-0410-9148-cb99ea01b6c8

46 files changed:
development/scons/scons_manifest.py
src/BufferView.C
src/cursor.C
src/dimension.C
src/frontends/FontLoader.h
src/frontends/FontMetrics.h [new file with mode: 0644]
src/frontends/Makefile.am
src/frontends/Painter.C
src/frontends/WorkArea.C
src/frontends/font_metrics.h [deleted file]
src/frontends/qt4/GuiFontLoader.C
src/frontends/qt4/GuiFontLoader.h
src/frontends/qt4/GuiFontMetrics.C [new file with mode: 0644]
src/frontends/qt4/GuiFontMetrics.h [new file with mode: 0644]
src/frontends/qt4/Makefile.am
src/frontends/qt4/QLPainter.C
src/frontends/qt4/QLPainter.h
src/frontends/qt4/qfont_metrics.C [deleted file]
src/frontends/qt4/qt_helpers.C
src/insets/insetbibitem.C
src/insets/insetcaption.C
src/insets/insetcharstyle.C
src/insets/insetcollapsable.C
src/insets/insetlatexaccent.C
src/insets/insetlatexaccent.h
src/insets/insetnewline.C
src/insets/insetpagebreak.C
src/insets/insetquotes.C
src/insets/insetspace.C
src/insets/insetspecialchar.C
src/insets/insettabular.C
src/insets/insettext.C
src/insets/insetvspace.C
src/insets/render_button.C
src/insets/render_graphic.C
src/insets/render_preview.C
src/lyxlength.C
src/mathed/InsetFormulaMacro.C
src/mathed/InsetMathBig.C
src/mathed/InsetMathChar.C
src/mathed/MathMacroTemplate.C
src/mathed/MathSupport.C
src/mathed/MathSupport.h
src/rowpainter.C
src/text.C
src/text2.C

index 6edf247c948741defa8476b329bfa2eb4f7d4d69..1b0b5c058d3c270b3311e31c766cfde026bd155f 100644 (file)
@@ -433,6 +433,7 @@ src_frontends_header_files = Split('''
     Dialogs.h
     FileDialog.h
     FontLoader.h
+    FontMetrics.h
     Gui.h
     LyXKeySym.h
     LyXKeySymFactory.h
@@ -443,7 +444,6 @@ src_frontends_header_files = Split('''
     Timeout.h
     Toolbars.h
     WorkArea.h
-    font_metrics.h
     guiapi.h
     key_state.h
     lyx_gui.h
@@ -1236,6 +1236,7 @@ src_frontends_qt4_files = Split('''
     GuiApplication.C
     GuiClipboard.C
     GuiFontLoader.C
+    GuiFontMetrics.C
     GuiImplementation.C
     GuiSelection.C
     GuiView.C
@@ -1335,7 +1336,6 @@ src_frontends_qt4_files = Split('''
     lengthcombo.C
     lyx_gui.C
     panelstack.C
-    qfont_metrics.C
     qfontexample.C
     qsetborder.C
     qtTimeout.C
index cea4268b0c0c2a8b8faa926b9a9902baa8bd2487..c91a92ddfb736e553099210eab56e8e005eafacb 100644 (file)
@@ -62,7 +62,8 @@
 #include "frontends/Alert.h"
 #include "frontends/Application.h"
 #include "frontends/FileDialog.h"
-#include "frontends/font_metrics.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 
 #include "graphics/Previews.h"
 
@@ -330,9 +331,10 @@ void BufferView::resize()
 bool BufferView::fitCursor()
 {
        if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) {
-               LyXFont const font = cursor_.getFont();
-               int const asc = font_metrics::maxAscent(font);
-               int const des = font_metrics::maxDescent(font);
+               lyx::frontend::FontMetrics const & fm 
+                       = theApp->fontLoader().metrics(cursor_.getFont());
+               int const asc = fm.maxAscent();
+               int const des = fm.maxDescent();
                Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
                if (p.y_ - asc >= 0 && p.y_ + des < height_)
                        return false;
index a94fdc2800800580fe1c0e8f2b78d8585828f28b..c93d642390c238efbed226cacd7ab304cb2c89aa 100644 (file)
@@ -44,7 +44,6 @@
 #include "support/limited_stack.h"
 
 #include "frontends/Application.h"
-#include "frontends/font_metrics.h"
 
 #include <boost/assert.hpp>
 #include <boost/bind.hpp>
index c1bb59540527e378815ebf3e93aba645a809ab8d..1edb794ebcc22f73f13130bb854a987a9beb8a05 100644 (file)
@@ -11,7 +11,9 @@
 #include <config.h>
 
 #include "dimension.h"
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 
 
 void Dimension::operator+=(Dimension const & dim)
@@ -26,7 +28,8 @@ void Dimension::operator+=(Dimension const & dim)
 
 void Dimension::clear(LyXFont const & font)
 {
-       asc = font_metrics::maxAscent(font);
-       des = font_metrics::maxDescent(font);
+       lyx::frontend::FontMetrics const & fm = theApp->fontLoader().metrics(font);
+       asc = fm.maxAscent();
+       des = fm.maxDescent();
        wid = 0;
 }
index ea5cf7388bd2f7db40d5808f1a43041f0f370e64..e674a26ff1de3e9c14475b91bbc16e8095274ff3 100644 (file)
@@ -17,6 +17,8 @@ class LyXFont;
 namespace lyx {
 namespace frontend {
 
+class FontMetrics;
+
 /// Hold info about a particular font
 class FontLoader
 {
@@ -31,6 +33,9 @@ public:
 
        /// Is the given font available ?
        virtual bool available(LyXFont const & f) = 0;
+
+       /// Get the Font metrics for this LyXFont
+       virtual FontMetrics const & metrics(LyXFont const & f) = 0;
 };
 
 } // namespace frontend
diff --git a/src/frontends/FontMetrics.h b/src/frontends/FontMetrics.h
new file mode 100644 (file)
index 0000000..9a190f4
--- /dev/null
@@ -0,0 +1,117 @@
+// -*- C++ -*-
+/**
+ * \file FontMetrics.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef FONT_METRICS_H
+#define FONT_METRICS_H
+
+#include "support/docstring.h"
+
+/**
+ * A class holding helper functions for determining
+ * the screen dimensions of fonts.
+ *
+ * The geometry is the standard typographical geometry,
+ * as follows :
+ *
+ * --------------+------------------<maxAscent
+ *               |          |
+ *               <-------> (right bearing)
+ *               <-> (left bearing)
+ * char ascent>___          |
+ *               ^   oooo   |  oooo
+ *   origin>____ |  oo  oo  | oo  oo
+ *              \|  oo  oo  | oo  oo
+ * --------------+---ooooo--|--oooo-<baseline
+ *               |      oo  |
+ * char          |  oo  oo  |
+ * descent>______|   oooo   |
+ *               <-  width ->
+ * --------------+----------+-------<maxDescent
+ *
+ */
+
+namespace lyx {
+namespace frontend {
+
+class FontMetrics
+{
+public:
+       virtual ~FontMetrics() {}
+
+       /// return the maximum ascent of the font
+       virtual int maxAscent() const = 0;
+       /// return the maximum descent of the font
+       virtual int maxDescent() const = 0;
+       /// return the ascent of the char in the font
+       virtual int ascent(lyx::char_type c) const = 0;
+       /// return the descent of the char in the font
+       virtual int descent(lyx::char_type c) const = 0;
+       /// return the left bearing of the char in the font
+       virtual int lbearing(lyx::char_type c) const = 0;
+       /// return the right bearing of the char in the font
+       virtual int rbearing(lyx::char_type c) const = 0;
+       /// return the width of the string in the font
+       virtual int width(lyx::char_type const * s, size_t n) const = 0;
+       /// FIXME ??
+       virtual int signedWidth(lyx::docstring const & s) const = 0;
+       /**
+        * fill in width,ascent,descent with the values for the
+        * given string in the font.
+        */
+       virtual void rectText(lyx::docstring const & str,
+               int & width,
+               int & ascent,
+               int & descent) const = 0;
+       /**
+        * fill in width,ascent,descent with the values for the
+        * given string in the font for a button.
+        */
+       virtual void buttonText(lyx::docstring const & str,
+               int & width,
+               int & ascent,
+               int & descent) const = 0;
+
+       /// return the maximum descent of the font
+       inline int maxHeight() const {
+               return maxAscent() + maxDescent();
+       }
+
+       /// return the descent of the char in the font
+       inline int height(lyx::char_type c) const
+       {
+               return ascent(c) + descent(c);
+       }
+
+       /// return the inner width of the char in the font
+       inline int center(lyx::char_type c) const {
+               return (rbearing(c) - lbearing(c)) / 2;
+       }
+
+       /// return the width of the char in the font
+       inline int width(lyx::char_type c) const
+       {
+               lyx::char_type tmp[2] = { c, L'\0'};
+               return width(tmp, 1);
+       }
+
+       /// return the width of the string in the font
+       inline int width(lyx::docstring const & s) const
+       {
+           return s.empty() ? 0 : width(s.data(), s.length());
+       }
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // FONT_METRICS_H
index cb5a5832b5dcbedd8dd74f339c386ae1dc6c1e00..f0387da1ef29bd578740d51fd08c8bffd72b9fd9 100644 (file)
@@ -22,6 +22,7 @@ libfrontends_la_SOURCES = \
        Dialogs.h \
        FileDialog.h \
        FontLoader.h \
+       FontMetrics.h \
        LyXKeySym.h \
        LyXKeySymFactory.h \
        LyXView.C \
@@ -38,7 +39,6 @@ libfrontends_la_SOURCES = \
        Selection.h \
        WorkArea.C \
        WorkArea.h \
-       font_metrics.h \
        guiapi.h \
        guiapi.C \
        key_state.h \
index 757d85188620169e1672a0dd8bd5b3b36be5bd43..8d14ae3cf0c62a66da66c2c040fe58e35b43324b 100644 (file)
 
 #include <config.h>
 
-#include "Painter.h"
-#include "font_metrics.h"
+#include "frontends/Painter.h"
+
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 
 #include "LColor.h"
 #include "lyxfont.h"
@@ -59,7 +62,8 @@ void Painter::rectText(int x, int y,
        int ascent;
        int descent;
 
-       font_metrics::rectText(str, font, width, ascent, descent);
+       FontMetrics const & fm = theApp->fontLoader().metrics(font);
+       fm.rectText(str, width, ascent, descent);
 
        if (back != LColor::none)
                fillRectangle(x + 1, y - ascent + 1, width - 1,
@@ -78,7 +82,8 @@ void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & fo
        int ascent;
        int descent;
 
-       font_metrics::buttonText(str, font, width, ascent, descent);
+       FontMetrics const & fm = theApp->fontLoader().metrics(font);
+       fm.buttonText(str, width, ascent, descent);
 
        button(x, y - ascent, width, descent + ascent);
        text(x + 4, y, str, font);
@@ -87,8 +92,10 @@ void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & fo
 
 void Painter::underline(LyXFont const & f, int x, int y, int width)
 {
-       int const below = max(font_metrics::maxDescent(f) / 2, 2);
-       int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
+       FontMetrics const & fm = theApp->fontLoader().metrics(f);
+
+       int const below = max(fm.maxDescent() / 2, 2);
+       int const height = max((fm.maxDescent() / 4) - 1, 1);
 
        if (height < 2)
                line(x, y + below, x + width, y + below, f.color());
index aa4089a26cffe60a294cd48de75149ace8e9f1c5..0f6d88d6895d1e275d0c251bd38d3f69565fade2 100644 (file)
 
 #include <config.h>
 
-#include "WorkArea.h"
+#include "frontends/WorkArea.h"
+
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 
-#include "font_metrics.h"
 #include "funcrequest.h"
 #include "lyx_gui.h"
 #include "lyxfunc.h"
@@ -372,8 +375,9 @@ void WorkArea::showCursor()
                shape = BAR_SHAPE;
 
        LyXFont const font = buffer_view_->cursor().getFont();
-       int const asc = font_metrics::maxAscent(font);
-       int const des = font_metrics::maxDescent(font);
+       FontMetrics const & fm = theApp->fontLoader().metrics(font);
+       int const asc = fm.maxAscent();
+       int const des = fm.maxDescent();
        int h = asc + des;
        int x = 0;
        int y = 0;
diff --git a/src/frontends/font_metrics.h b/src/frontends/font_metrics.h
deleted file mode 100644 (file)
index 9c6becd..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-// -*- C++ -*-
-/**
- * \file font_metrics.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef FONT_METRICS_H
-#define FONT_METRICS_H
-
-#include "support/docstring.h"
-
-
-class LyXFont;
-
-/**
- * A namespace holding helper functions for determining
- * the screen dimensions of fonts.
- *
- * The geometry is the standard typographical geometry,
- * as follows :
- *
- * --------------+------------------<maxAscent
- *               |          |
- *               <-------> (right bearing)
- *               <-> (left bearing)
- * char ascent>___          |
- *               ^   oooo   |  oooo
- *   origin>____ |  oo  oo  | oo  oo
- *              \|  oo  oo  | oo  oo
- * --------------+---ooooo--|--oooo-<baseline
- *               |      oo  |
- * char          |  oo  oo  |
- * descent>______|   oooo   |
- *               <-  width ->
- * --------------+----------+-------<maxDescent
- *
- */
-namespace font_metrics {
-       /// return the maximum ascent of the font
-       int maxAscent(LyXFont const & f);
-       /// return the maximum descent of the font
-       int maxDescent(LyXFont const & f);
-       /// return the maximum descent of the font
-       inline int maxHeight(LyXFont const & f) {
-               return maxAscent(f) + maxDescent(f);
-       }
-       /// return the ascent of the char in the font
-       int ascent(lyx::char_type c, LyXFont const & f);
-       /// return the descent of the char in the font
-       int descent(lyx::char_type c, LyXFont const & f);
-       /// return the descent of the char in the font
-       inline int height(lyx::char_type c, LyXFont const & f)
-       {
-               return ascent(c, f) + descent(c, f);
-       }
-       /// return the left bearing of the char in the font
-       int lbearing(lyx::char_type c, LyXFont const & f);
-       /// return the right bearing of the char in the font
-       int rbearing(lyx::char_type c, LyXFont const & f);
-       /// return the inner width of the char in the font
-       inline int center(lyx::char_type c, LyXFont const & f) {
-               return (rbearing(c, f) - lbearing(c, f)) / 2;
-       }
-       /// return the width of the string in the font
-       int width(lyx::char_type const * s, size_t n, LyXFont const & f);
-       /// return the width of the char in the font
-       inline int width(lyx::char_type c, LyXFont const & f)
-       {
-               lyx::char_type tmp[2] = { c, L'\0'};
-               return width(tmp, 1, f);
-       }
-       /// return the width of the string in the font
-       inline int width(lyx::docstring const & s, LyXFont const & f)
-       {
-           return s.empty() ? 0 : width(s.data(), s.length(), f);
-       }
-       /// FIXME ??
-       int signedWidth(lyx::docstring const & s, LyXFont const & f);
-       /**
-        * fill in width,ascent,descent with the values for the
-        * given string in the font.
-        */
-       void rectText(lyx::docstring const & str, LyXFont const & font,
-               int & width,
-               int & ascent,
-               int & descent);
-       /**
-        * fill in width,ascent,descent with the values for the
-        * given string in the font for a button.
-        */
-       void buttonText(lyx::docstring const & str, LyXFont const & font,
-               int & width,
-               int & ascent,
-               int & descent);
-}
-
-#endif // FONT_METRICS_H
index e75bbad8490eddc3ed7a2aa976ee8ddcac5845c1..f98c4a7324e33ee8e8df95c6f5681534705ac7f7 100644 (file)
@@ -220,9 +220,7 @@ void GuiFontLoader::update()
 
 
 QLFontInfo::QLFontInfo(LyXFont const & f)
-       : metrics(font)
 {
-
        string const pat = symbolFamily(f.family());
        if (!pat.empty()) {
                bool tmp;
@@ -246,9 +244,6 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
                }
        }
 
-       font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
-                              * lyxrc.zoom / 100.0);
-
        switch (f.series()) {
                case LyXFont::MEDIUM_SERIES:
                        font.setWeight(QFont::Normal);
@@ -274,9 +269,6 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
                        << "' matched by\n" << fromqstr(font.rawName()) << endl;
        }
 
-       lyxerr[Debug::FONT] << "The font has size: "
-                           << font.pointSizeF() << endl;
-
        // Is this an exact match?
        if (font.exactMatch())
                lyxerr[Debug::FONT] << "This font is an exact match" << endl;
@@ -286,21 +278,27 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
 
        lyxerr[Debug::FONT] << "XFLD: " << fromqstr(font.rawName()) << endl;
 
-       metrics = QFontMetrics(font);
-}
+       font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
+                              * lyxrc.zoom / 100.0);
 
-#ifdef USE_LYX_FONTCACHE
-int QLFontInfo::width(Uchar val)
-{
-       QLFontInfo::WidthCache::const_iterator cit = widthcache.find(val);
-       if (cit != widthcache.end())
-               return cit->second;
+       lyxerr[Debug::FONT] << "The font has size: "
+                           << font.pointSizeF() << endl;
+
+       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
+               metrics.reset(new GuiFontMetrics(font));
+       }
+       else {  
+               // handle small caps ourselves ...
+               LyXFont smallfont = f;
+               smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
+               QFont font2(font);
+               font2.setPointSizeF(convert<double>(lyxrc.font_sizes[smallfont.size()])
+                              * lyxrc.zoom / 100.0);
+
+               metrics.reset(new GuiFontMetrics(font, font2));
+       }
 
-       int const w = metrics.width(QChar(val));
-       widthcache[val] = w;
-       return w;
 }
-#endif
 
 
 bool GuiFontLoader::available(LyXFont const & f)
index d526ff3ef1c8900c3de49a2fc0bee72ac84a7718..71d10b26d2d272406068539a04cc3a6607521eaf 100644 (file)
 
 #include "frontends/FontLoader.h"
 
+#include "GuiFontMetrics.h"
+
 #include "encoding.h"
 #include "lyxfont.h"
 
 #include <QFont>
-#include <QFontMetrics>
-
-// 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(Q_WS_MACX) || defined(Q_WS_WIN32)
-#define USE_LYX_FONTCACHE
-#include <map>
-#endif
 
 namespace lyx {
 namespace frontend {
@@ -41,21 +35,7 @@ public:
        /// The font instance
        QFont font;
        /// Metrics on the font
-       QFontMetrics metrics;
-
-#ifndef USE_LYX_FONTCACHE
-       /// Return pixel width for the given unicode char
-       int width(Uchar val) { return metrics.width(QChar(val)); }
-
-#else
-       /// Return pixel width for the given unicode char
-       int width(Uchar val);
-
-private:
-       typedef std::map<Uchar, int> WidthCache;
-       /// Cache of char widths
-       WidthCache widthcache;
-#endif // USE_LYX_FONTCACHE
+       boost::scoped_ptr<GuiFontMetrics> metrics;
 };
 
 
@@ -69,21 +49,17 @@ public:
        /// Destructor
        virtual ~GuiFontLoader();
 
-       /// Update fonts after zoom, dpi, font names, or norm change
        virtual void update();
-
-       /// Do we have anything matching?
        virtual bool available(LyXFont const & f);
+       inline virtual FontMetrics const & metrics(LyXFont const & f) {
+               return *fontinfo(f).metrics.get();
+       }
 
        /// Get the QFont for this LyXFont
        QFont const & get(LyXFont const & f) {
                return fontinfo(f).font;
        }
 
-       /// Get the QFont metrics for this LyXFont
-       QFontMetrics const & metrics(LyXFont const & f) {
-               return fontinfo(f).metrics;
-       }
 
        /// Get font info (font + metrics) for the given LyX font.
        QLFontInfo & fontinfo(LyXFont const & f) {
diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C
new file mode 100644 (file)
index 0000000..b5a2b0a
--- /dev/null
@@ -0,0 +1,200 @@
+/**
+ * \file GuiFontMetrics.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiFontMetrics.h"
+
+#include "qt_helpers.h"
+
+#include "language.h"
+
+#include "frontends/lyx_gui.h"
+
+#include "support/unicode.h"
+
+using lyx::char_type;
+using lyx::docstring;
+
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+
+GuiFontMetrics::GuiFontMetrics(QFont const & font)
+: metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false)
+{
+}
+
+
+GuiFontMetrics::GuiFontMetrics(QFont const & font, QFont const & smallcaps_font)
+: metrics_(font), smallcaps_metrics_(smallcaps_font), smallcaps_shape_(true)
+{
+}
+
+
+int GuiFontMetrics::maxAscent() const
+{
+       if (!lyx_gui::use_gui)
+               return 1;
+       return metrics_.ascent();
+}
+
+
+int GuiFontMetrics::maxDescent() const
+{
+       if (!lyx_gui::use_gui)
+               return 1;
+       // We add 1 as the value returned by QT is different than X
+       // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
+       return metrics_.descent() + 1;
+}
+
+
+int GuiFontMetrics::ascent(char_type c) const
+{
+       if (!lyx_gui::use_gui)
+               return 1;
+       QRect const & r = metrics_.boundingRect(ucs4_to_qchar(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
+}
+
+
+int GuiFontMetrics::descent(char_type c) const
+{
+       if (!lyx_gui::use_gui)
+               return 1;
+       QRect const & r = metrics_.boundingRect(ucs4_to_qchar(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
+}
+
+
+int GuiFontMetrics::lbearing(char_type c) const
+{
+       if (!lyx_gui::use_gui)
+               return 1;
+       return metrics_.leftBearing(ucs4_to_qchar(c));
+}
+
+
+int GuiFontMetrics::rbearing(char_type c) const
+{
+       if (!lyx_gui::use_gui)
+               return 1;
+
+       // Qt rbearing is from the right edge of the char's width().
+       QChar sc = ucs4_to_qchar(c);
+       return metrics_.width(sc) - metrics_.rightBearing(sc);
+}
+
+
+int GuiFontMetrics::smallcapsWidth(QString const & s) const
+{
+       if (!lyx_gui::use_gui)
+               return 1;
+
+       int w = 0;
+       int const ls = s.size();
+
+       for (int i = 0; i < ls; ++i) {
+               QChar const & c = s[i];
+               QChar const uc = c.toUpper();
+               if (c != uc)
+                       w += smallcaps_metrics_.width(uc);
+               else
+                       w += metrics_.width(c);
+       }
+       return w;
+}
+
+
+int GuiFontMetrics::width(char_type const * s, size_t ls) const
+{
+       if (!lyx_gui::use_gui)
+               return ls;
+
+       QString ucs2 = ucs4_to_qstring(s, ls);
+
+       if (smallcaps_shape_)
+               return smallcapsWidth(ucs2);
+
+       if (ls == 1)
+               return width(ucs2[0].unicode());
+
+       int w = 0;
+       for (unsigned int i = 0; i < ls; ++i)
+               w += width(ucs2[i].unicode());
+
+       return w;
+}
+
+
+int GuiFontMetrics::signedWidth(docstring const & s) const
+{
+       if (s[0] == '-')
+               return -FontMetrics::width(s.substr(1, s.length() - 1));
+       else
+               return FontMetrics::width(s);
+}
+
+
+void GuiFontMetrics::rectText(docstring const & str,
+       int & w, int & ascent, int & descent) const
+{
+       static int const d = 2;
+       w = FontMetrics::width(str) + d * 2 + 2;
+       ascent = metrics_.ascent() + d;
+       descent = metrics_.descent() + d;
+}
+
+
+
+void GuiFontMetrics::buttonText(docstring const & str,
+       int & w, int & ascent, int & descent) const
+{
+       QFontMetrics const & m = metrics_;
+       static int const d = 3;
+       w = FontMetrics::width(str) + d * 2 + 2;
+       ascent = metrics_.ascent() + d;
+       descent = metrics_.descent() + d;
+}
+
+#ifdef USE_LYX_FONTCACHE
+int GuiFontMetrics::width(unsigned short val) const
+{
+       GuiFontMetrics::WidthCache::const_iterator cit = widthcache.find(val);
+       if (cit != widthcache.end())
+               return cit->second;
+
+       int const w = metrics_.width(QChar(val));
+       widthcache[val] = w;
+       return w;
+}
+#endif
+
+}
+}
diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h
new file mode 100644 (file)
index 0000000..44ee9c3
--- /dev/null
@@ -0,0 +1,83 @@
+// -*- C++ -*-
+/**
+ * \file FontMetrics.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef QT4_FONT_METRICS_H
+#define QT4_FONT_METRICS_H
+
+#include "frontends/FontMetrics.h"
+
+#include "support/docstring.h"
+
+#include <QFontMetrics>
+
+// 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(Q_WS_MACX) || defined(Q_WS_WIN32)
+#define USE_LYX_FONTCACHE
+#include <map>
+#endif
+
+namespace lyx {
+namespace frontend {
+
+class GuiFontMetrics: public FontMetrics
+{
+public:
+
+       GuiFontMetrics(QFont const & font);
+       GuiFontMetrics(QFont const & font, QFont const & smallcaps_font);
+
+       virtual ~GuiFontMetrics() {}
+
+       virtual int maxAscent() const;
+       virtual int maxDescent() const;
+       virtual int ascent(lyx::char_type c) const;
+       int descent(lyx::char_type c) const;
+       virtual int lbearing(lyx::char_type c) const;
+       virtual int rbearing(lyx::char_type c) const;
+       virtual int width(lyx::char_type const * s, size_t n) const;
+       virtual int signedWidth(lyx::docstring const & s) const;
+       virtual void rectText(lyx::docstring const & str,
+               int & width,
+               int & ascent,
+               int & descent) const;
+       virtual void buttonText(lyx::docstring const & str,
+               int & width,
+               int & ascent,
+               int & descent) const;
+
+private:
+       int smallcapsWidth(QString const & s) const;
+
+       /// Metrics on the font
+       QFontMetrics metrics_;
+       QFontMetrics smallcaps_metrics_;
+
+       bool smallcaps_shape_;
+
+#ifndef USE_LYX_FONTCACHE
+       /// Return pixel width for the given unicode char
+       int width(unsigned short val) const { return metrics_.width(QChar(val)); }
+
+#else
+       /// Return pixel width for the given unicode char
+       int width(unsigned short val) const;
+
+       typedef std::map<unsigned short, int> WidthCache;
+       /// Cache of char widths
+       mutable WidthCache widthcache;
+#endif // USE_LYX_FONTCACHE
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // QT4_FONT_METRICS_H
index c20a0970abd0df423936408e67585447d7728ee8..650ff7b343173bfc7658235e33b808fe5fda1e96 100644 (file)
@@ -37,6 +37,7 @@ libqt4_la_SOURCES = \
        GuiApplication.C GuiApplication.h \
        GuiClipboard.h GuiClipboard.C \
        GuiFontLoader.h GuiFontLoader.C \
+       GuiFontMetrics.h GuiFontMetrics.C \
        GuiSelection.h GuiSelection.C \
        GuiImplementation.h GuiImplementation.C \
        LyXKeySymFactory.C \
@@ -86,7 +87,6 @@ libqt4_la_SOURCES = \
        lyx_gui.C \
        panelstack.h panelstack.C \
        qfontexample.h qfontexample.C \
-       qfont_metrics.C \
        qlkey.h \
        qt_helpers.h qt_helpers.C \
        qtTimeout.C qtTimeout.h \
index f306ebc330944b6873d35b2859837300030d184e..3fcfba0ee199fbbc83b9ec7f3e697bc2fc5e4a07 100644 (file)
@@ -25,7 +25,7 @@
 #include "language.h"
 #include "LColor.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/FontMetrics.h"
 
 #include "support/unicode.h"
 
@@ -196,7 +196,7 @@ void QLPainter::text(int x, int y, char_type c, LyXFont const & f)
 }
 
 
-void QLPainter::smallCapsText(int x, int y,
+int QLPainter::smallCapsText(int x, int y,
        QString const & s, LyXFont const & f)
 {
        LyXFont smallfont(f);
@@ -204,24 +204,21 @@ void QLPainter::smallCapsText(int x, int y,
 
        QFont const & qfont = guiApp->guiFontLoader().get(f);
        QFont const & qsmallfont = guiApp->guiFontLoader().get(smallfont);
-       QFontMetrics const & qfontm = QFontMetrics(qfont);
-       QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
 
        setQPainterPen(f.realColor());
-       int tmpx = x;
+       int textwidth = 0;
        size_t ls = s.length();
        for (unsigned int i = 0; i < ls; ++i) {
                QChar const c = s[i].toUpper();
                if (c != s.at(i)) {
                        qp_->setFont(qsmallfont);
-                       qp_->drawText(tmpx, y, c);
-                       tmpx += qsmallfontm.width(c);
                } else {
                        qp_->setFont(qfont);
-                       qp_->drawText(tmpx, y, c);
-                       tmpx += qfontm.width(c);
                }
+               qp_->drawText(x + textwidth, y, c);
+               textwidth += qp_->fontMetrics().width(c);
        }
+       return textwidth;
 }
 
 
@@ -250,18 +247,23 @@ void QLPainter::text(int x, int y, char_type const * s, size_t ls,
                str = ' ' + str;
 #endif
 
+       QLFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
+
+       int textwidth;
+
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
                setQPainterPen(f.realColor());
-               qp_->setFont(guiApp->guiFontLoader().get(f));
+               qp_->setFont(fi.font);
                // We need to draw the text as LTR as we use our own bidi code.
                qp_->setLayoutDirection(Qt::LeftToRight);
                qp_->drawText(x, y, str);
+               textwidth = qp_->fontMetrics().width(str);
        } else {
-               smallCapsText(x, y, str, f);
+               textwidth = smallCapsText(x, y, str, f);
        }
 
        if (f.underbar() == LyXFont::ON) {
-               underline(f, x, y, font_metrics::width(s, ls, f));
+               underline(f, x, y, textwidth);
        }
 
 }
index 291b337f3493c2561824d24d1ed22581df1c2a8e..f53b0e67c9323504fb59b21f1745b6b473079b5c 100644 (file)
@@ -125,7 +125,10 @@ public:
 
 private:
        /// draw small caps text
-       void smallCapsText(int x, int y,
+       /**
+       \return width of the drawn text.
+       */
+       int smallCapsText(int x, int y,
                QString const & str, LyXFont const & f);
 
        /// set pen parameters
diff --git a/src/frontends/qt4/qfont_metrics.C b/src/frontends/qt4/qfont_metrics.C
deleted file mode 100644 (file)
index 00f924c..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * \file qfont_metrics.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/font_metrics.h"
-#include "frontends/lyx_gui.h"
-
-#include "GuiApplication.h"
-#include "FontLoader.h"
-#include "qt_helpers.h"
-
-#include "language.h"
-
-#include "support/unicode.h"
-
-using lyx::char_type;
-using lyx::docstring;
-
-using std::string;
-
-
-namespace {
-
-int smallcapswidth(QString const & s, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-       // handle small caps ourselves ...
-
-       LyXFont smallfont = f;
-       smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
-
-       QFontMetrics const & qm = guiApp->guiFontLoader().metrics(f);
-       QFontMetrics const & qsmallm = guiApp->guiFontLoader().metrics(smallfont);
-
-       int w = 0;
-
-       int const ls = s.size();
-
-       for (int i = 0; i < ls; ++i) {
-               QChar const & c = s[i];
-               QChar const uc = c.toUpper();
-               if (c != uc)
-                       w += qsmallm.width(uc);
-               else
-                       w += qm.width(c);
-       }
-       return w;
-}
-
-
-} // anon namespace
-
-
-int font_metrics::maxAscent(LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-       return guiApp->guiFontLoader().metrics(f).ascent();
-}
-
-
-int font_metrics::maxDescent(LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-       // We add 1 as the value returned by QT is different than X
-       // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
-       return guiApp->guiFontLoader().metrics(f).descent() + 1;
-}
-
-
-int font_metrics::ascent(char_type c, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-       QRect const & r = guiApp->guiFontLoader().metrics(f).boundingRect(ucs4_to_qchar(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
-}
-
-
-int font_metrics::descent(char_type c, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-       QRect const & r = guiApp->guiFontLoader().metrics(f).boundingRect(ucs4_to_qchar(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
-}
-
-
-int font_metrics::lbearing(char_type c, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-       return guiApp->guiFontLoader().metrics(f).leftBearing(ucs4_to_qchar(c));
-}
-
-
-int font_metrics::rbearing(char_type c, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-       QFontMetrics const & m = guiApp->guiFontLoader().metrics(f);
-
-       // Qt rbearing is from the right edge of the char's width().
-       QChar sc = ucs4_to_qchar(c);
-       return m.width(sc) - m.rightBearing(sc);
-}
-
-
-int font_metrics::width(char_type const * s, size_t ls, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return ls;
-
-       QString ucs2 = ucs4_to_qstring(s, ls);
-
-       if (f.realShape() == LyXFont::SMALLCAPS_SHAPE)
-               return smallcapswidth(ucs2, f);
-
-       lyx::frontend::QLFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
-
-       if (ls == 1)
-               return fi.width(ucs2[0].unicode());
-
-       int w = 0;
-       for (unsigned int i = 0; i < ls; ++i)
-               w += fi.width(ucs2[i].unicode());
-
-       return w;
-}
-
-
-int font_metrics::signedWidth(docstring const & s, LyXFont const & f)
-{
-       if (s[0] == '-')
-               return -width(s.substr(1, s.length() - 1), f);
-       else
-               return width(s, f);
-}
-
-
-void font_metrics::rectText(docstring const & str, LyXFont const & f,
-       int & w, int & ascent, int & descent)
-{
-       QFontMetrics const & m = guiApp->guiFontLoader().metrics(f);
-       static int const d = 2;
-       w = width(str, f) + d * 2 + 2;
-       ascent = m.ascent() + d;
-       descent = m.descent() + d;
-}
-
-
-
-void font_metrics::buttonText(docstring const & str, LyXFont const & f,
-       int & w, int & ascent, int & descent)
-{
-       QFontMetrics const & m = guiApp->guiFontLoader().metrics(f);
-       static int const d = 3;
-       w = width(str, f) + d * 2 + 2;
-       ascent = m.ascent() + d;
-       descent = m.descent() + d;
-}
index 3f419624f38839979c434ed338ddfff3fcbbc228..394c13341d5384b05946f2e9bfaec452bf1f17ac 100644 (file)
@@ -123,6 +123,7 @@ QString const toqstr(string const & str)
 QString const ucs4_to_qstring(char_type const * str, size_t ls)
 {
        QString s;
+       s.reserve(ls);
 
        for (size_t i = 0; i < ls; ++i)
                s.append(ucs4_to_qchar(str[i]));
index ca11c02129b15618bc4b588b79f0480a710ed64c..4cb361ca183e68b99bc748399b4b4ff1e855240b 100644 (file)
@@ -20,7 +20,9 @@
 #include "paragraph.h"
 #include "ParagraphList.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 
 #include "support/lstrings.h"
 #include "support/std_ostream.h"
@@ -136,7 +138,10 @@ string const bibitemWidest(Buffer const & buffer)
        // Does look like a hack? It is! (but will change at 0.13)
 
        InsetBibitem const * bitem = 0;
+       // FIXME font is used unitialized, is that correct?
        LyXFont font;
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
 
        ParagraphList::const_iterator it = buffer.paragraphs().begin();
        ParagraphList::const_iterator end = buffer.paragraphs().end();
@@ -147,7 +152,7 @@ string const bibitemWidest(Buffer const & buffer)
                         docstring const dlab(label.begin(), label.end());
                     
                        int const wx =
-                               font_metrics::width(dlab, font);
+                               fm.width(dlab);
                        if (wx > w) {
                                w = wx;
                                bitem = it->bibitem();
index 4a34e60fdc494a921c2e094be00e81c6e41ff601..6c6c1755b4d0ae1b9e8d31ea8797c4a3faeb60a3 100644 (file)
@@ -26,7 +26,9 @@
 #include "metricsinfo.h"
 #include "paragraph.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "support/lstrings.h"
@@ -125,7 +127,7 @@ void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
        LCursor cur = mi.base.bv->cursor();
        setLabel(cur);
        docstring dlab(label.begin(), label.end());
-       labelwidth_ = font_metrics::width(dlab, mi.base.font);
+       labelwidth_ = theApp->fontLoader().metrics(mi.base.font).width(dlab);
        dim.wid = labelwidth_;
        Dimension textdim;
        InsetText::metrics(mi, textdim);
@@ -153,7 +155,9 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) const
        LCursor cur = pi.base.bv->cursor();
        setLabel(cur);
        docstring dlab(label.begin(), label.end());
-       labelwidth_ = font_metrics::width(dlab, pi.base.font);
+       // FXIME: instead of using the fontLoader metrics, we should make
+       // painter::text() returns the drawn text witdh.
+       labelwidth_ = theApp->fontLoader().metrics(pi.base.font).width(dlab);
        pi.pain.text(x, y, dlab, pi.base.font);
        InsetText::draw(pi, x + labelwidth_, y);
        setPosCache(pi, x, y);
index 853b02b3ca26e1fec31785f4ac1e2d6435092a24..77bb8698db4b427379ec17ee721885f82202fd70 100644 (file)
@@ -31,7 +31,9 @@
 #include "paragraph_funcs.h"
 #include "sgml.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include <sstream>
@@ -157,7 +159,7 @@ void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
                        // FIXME UNICODE
                        s = lyx::to_utf8(_("Undef: ")) + s;
                docstring ds(s.begin(), s.end());
-               font_metrics::rectText(ds, font, w, a, d);
+               theApp->fontLoader().metrics(font).rectText(ds, w, a, d);
                dim.wid = max(dim.wid, w);
        }
        dim.asc += TEXT_TO_INSET_OFFSET;
@@ -205,7 +207,7 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
                        // FIXME UNICODE
                        s = lyx::to_utf8(_("Undef: ")) + s;
                docstring ds(s.begin(), s.end());
-               font_metrics::rectText(ds, font, w, a, d);
+               theApp->fontLoader().metrics(font).rectText(ds, w, a, d);
                pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
                        ds, font, LColor::none, LColor::none);
        }
index ad2fbea91d2c0d240a3728d079fe5b6bf2732138..e7a547f475b77054cfcc14cfff76805e3eec221f 100644 (file)
@@ -26,7 +26,9 @@
 #include "metricsinfo.h"
 #include "paragraph.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 using lyx::docstring;
@@ -121,8 +123,9 @@ void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
 Dimension InsetCollapsable::dimensionCollapsed() const
 {
        Dimension dim;
-        docstring dlab(label.begin(), label.end());
-       font_metrics::buttonText(dlab, labelfont_, dim.wid, dim.asc, dim.des);
+       docstring dlab(label.begin(), label.end());
+       theApp->fontLoader().metrics(labelfont_).buttonText(
+               dlab, dim.wid, dim.asc, dim.des);
        return dim;
 }
 
index c880b967a20afe8c533bffcc912cb04b20fc1d87..9f15861be3c7d944f9445532a4d343a8938348e7 100644 (file)
@@ -19,7 +19,9 @@
 #include "lyxrc.h"
 #include "metricsinfo.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "support/lstrings.h"
@@ -244,48 +246,39 @@ void InsetLatexAccent::checkContents()
 void InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        LyXFont & font = mi.base.font;
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
+
        // This function is a bit too simplistic and is just a
        // "try to make a fit for all accents" approach, to
        // make it better we need to know what kind of accent is
        // used and add to max based on that.
        if (candisp) {
                if (ic == ' ')
-                       dim.asc = font_metrics::ascent('a', font);
+                       dim.asc = fm.ascent('a');
                else
-                       dim.asc = font_metrics::ascent(ic, font);
+                       dim.asc = fm.ascent(ic);
                if (plusasc)
-                       dim.asc += (font_metrics::maxAscent(font) + 3) / 3;
+                       dim.asc += (fm.maxAscent() + 3) / 3;
 
                if (ic == ' ')
-                       dim.des = font_metrics::descent('a', font);
+                       dim.des = fm.descent('a');
                else
-                       dim.des = font_metrics::descent(ic, font);
+                       dim.des = fm.descent(ic);
                if (plusdesc)
                        dim.des += 3;
 
-               dim.wid = font_metrics::width(ic, font);
+               dim.wid = fm.width(ic);
        } else {
-               dim.asc = font_metrics::maxAscent(font) + 4;
-               dim.des = font_metrics::maxDescent(font) + 4;
+               dim.asc = fm.maxAscent() + 4;
+               dim.des = fm.maxDescent() + 4;
                docstring dcon(contents.begin(), contents.end());
-               dim.wid = font_metrics::width(dcon, font) + 4;
+               dim.wid = fm.width(dcon) + 4;
        }
        dim_ = dim;
 }
 
 
-int InsetLatexAccent::lbearing(LyXFont const & font) const
-{
-       return font_metrics::lbearing(ic, font);
-}
-
-
-int InsetLatexAccent::rbearing(LyXFont const & font) const
-{
-       return font_metrics::rbearing(ic, font);
-}
-
-
 bool InsetLatexAccent::displayISO8859_9(PainterInfo & pi, int x, int y) const
 {
        unsigned char tmpic = ic;
@@ -338,10 +331,13 @@ void InsetLatexAccent::drawAccent(PainterInfo const & pi, int x, int y,
        char_type accent) const
 {
        LyXFont const & font = pi.base.font;
-       x -= font_metrics::center(accent, font);
-       y -= font_metrics::ascent(ic, font);
-       y -= font_metrics::descent(accent, font);
-       y -= font_metrics::height(accent, font) / 2;
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
+
+       x -= fm.center(accent);
+       y -= fm.ascent(ic);
+       y -= fm.descent(accent);
+       y -= fm.height(accent) / 2;
        pi.pain.text(x, y, accent, font);
 }
 
@@ -360,13 +356,16 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
        if (lyxrc.font_norm_type == LyXRC::ISO_10646_1)
                font.setLanguage(english_language);
 
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
+
        if (candisp) {
-               int x2 = int(x + (rbearing(font) - lbearing(font)) / 2);
+               int x2 = int(x + (fm.rbearing(ic) - fm.lbearing(ic)) / 2);
                int hg;
                int y;
                if (plusasc) {
                        // mark at the top
-                       hg = font_metrics::maxDescent(font);
+                       hg = fm.maxDescent();
                        y = baseline - dim_.asc;
                        if (font.shape() == LyXFont::ITALIC_SHAPE)
                                x2 += int(0.8 * hg); // italic
@@ -383,15 +382,15 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
                pi.pain.text(x, baseline, ic, font);
 
                if (remdot) {
-                       int tmpvar = baseline - font_metrics::ascent('i', font);
+                       int tmpvar = baseline - fm.ascent('i');
                        int tmpx = 0;
                        if (font.shape() == LyXFont::ITALIC_SHAPE)
                                tmpx += int(0.8 * hg); // italic
                        lyxerr[Debug::KEY] << "Removing dot." << endl;
                        // remove the dot first
                        pi.pain.fillRectangle(x + tmpx, tmpvar, dim_.wid,
-                                          font_metrics::ascent('i', pi.base.font) -
-                                          font_metrics::ascent('x', pi.base.font) - 1,
+                                          fm.ascent('i') -
+                                          fm.ascent('x') - 1,
                                           backgroundColor());
                        // the five lines below is a simple hack to
                        // make the display of accent 'i' and 'j'
@@ -430,21 +429,21 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
 
                case UNDERBAR: {
                        char_type const underbar = 0x5F; //('\x5F');
-                       pi.pain.text(x2 - font_metrics::center(underbar, font),
+                       pi.pain.text(x2 - fm.center(underbar),
                                     baseline, underbar, font);
                        break;
                }
 
                case CEDILLA: {
                        char_type const cedilla = 0xB8; //('\xB8');
-                       pi.pain.text(x2  - font_metrics::center(cedilla, font),
+                       pi.pain.text(x2  - fm.center(cedilla),
                                     baseline, cedilla, font);
                        break;
                }
 
                case UNDERDOT:
-                       pi.pain.text(x2  - font_metrics::center('.', font),
-                                 int(baseline + 1.5 * font_metrics::height('.', font)),
+                       pi.pain.text(x2  - fm.center('.'),
+                                 int(baseline + 1.5 * fm.height('.')),
                                  '.', font);
                        break;
 
@@ -496,8 +495,8 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
                }
 
                case HUNGARIAN_UMLAUT:
-                       drawAccent(pi, x2 - font_metrics::center('´', font), baseline, '´');
-                       drawAccent(pi, x2 + font_metrics::center('´', font), baseline, '´');
+                       drawAccent(pi, x2 - fm.center('´'), baseline, '´');
+                       drawAccent(pi, x2 + fm.center('´'), baseline, '´');
                        break;
 
                case UMLAUT:
index 6e7e0ca2347fc2aa3d8e0cdf456b4c798622ba28..9d270e1bcf5426c01ae039c5213b570ac2dc541c 100644 (file)
@@ -37,10 +37,6 @@ public:
        ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
-       int lbearing(LyXFont const & font) const;
-       ///
-       int rbearing(LyXFont const & font) const;
-       ///
        bool displayISO8859_9(PainterInfo & pi, int x, int y) const;
        ///
        void write(Buffer const &, std::ostream &) const;
index 403ba0d707d6c32ffb91271ada5fe8d163d30b32..e9fa97b89ecfb26249e3c65a64366a217399b386 100644 (file)
@@ -19,7 +19,9 @@
 #include "paragraph.h"
 #include "paragraph_funcs.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 using std::endl;
@@ -40,10 +42,11 @@ void InsetNewline::write(Buffer const &, ostream & os) const
 
 void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LyXFont & font = mi.base.font;
-       dim.asc = font_metrics::maxAscent(font);
-       dim.des = font_metrics::maxDescent(font);
-       dim.wid = font_metrics::width('n', font);
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(mi.base.font);
+       dim.asc = fm.maxAscent();
+       dim.des = fm.maxDescent();
+       dim.wid = fm.width('n');
        dim_ = dim;
 }
 
@@ -74,8 +77,10 @@ int InsetNewline::docbook(Buffer const &, std::ostream & os,
 
 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
 {
-       int const wid = font_metrics::width('n', pi.base.font);
-       int const asc = font_metrics::maxAscent(pi.base.font);
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(pi.base.font);
+       int const wid = fm.width('n');
+       int const asc = fm.maxAscent();
 
        int xp[3];
        int yp[3];
index 7c4b3d56e060c4fe165dc9ee693e08954b070b96..037e9b7293381b2f89ec43e0b5c8596ec6e10449 100644 (file)
 #include "metricsinfo.h"
 #include "gettext.h"
 
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
 
 using lyx::docstring;
 using lyx::frontend::Painter;
@@ -60,7 +62,7 @@ void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const
        int w = 0;
        int a = 0;
        int d = 0;
-       font_metrics::rectText(label, font, w, a, d);
+       theApp->fontLoader().metrics(font).rectText(label, w, a, d);
 
        int const text_start = int(x + (dim_.wid - w) / 2);
        int const text_end = text_start + w;
index 7d9d4edddcba95ab28fe66ee07f02c73f963c605..26f5e53916d83f149dc2eeb35ef5b4916836671f 100644 (file)
@@ -24,7 +24,9 @@
 #include "paragraph.h"
 #include "paragraph_funcs.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "support/lstrings.h"
@@ -199,18 +201,20 @@ string const InsetQuotes::dispString(Language const * loclang) const
 void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        LyXFont & font = mi.base.font;
-       dim.asc = font_metrics::maxAscent(font);
-       dim.des = font_metrics::maxDescent(font);
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
+       dim.asc = fm.maxAscent();
+       dim.des = fm.maxDescent();
        dim.wid = 0;
 
        string const text = dispString(font.language());
        for (string::size_type i = 0; i < text.length(); ++i) {
                if (text[i] == ' ')
-                       dim.wid += font_metrics::width('i', font);
+                       dim.wid += fm.width('i');
                else if (i == 0 || text[i] != text[i - 1])
-                       dim.wid += font_metrics::width(text[i], font);
+                       dim.wid += fm.width(text[i]);
                else
-                       dim.wid += font_metrics::width(',', font);
+                       dim.wid += fm.width(',');
        }
        dim_ = dim;
 }
@@ -235,7 +239,8 @@ void InsetQuotes::draw(PainterInfo & pi, int x, int y) const
 
        if (text.length() == 2 && text[0] == text[1]) {
                pi.pain.text(x, y, text[0], pi.base.font);
-               int const t = font_metrics::width(',', pi.base.font);
+               int const t = theApp->fontLoader().metrics(pi.base.font)
+                       .width(',');
                pi.pain.text(x + t, y, text[0], pi.base.font);
        } else {
                 docstring dtext(text.begin(), text.end());
index c97a3ebb08b49ae8eed002498a9a6a9f1e4c57af..9be6ee484a4ef7759dcb4c072290d3995656619a 100644 (file)
@@ -21,7 +21,9 @@
 #include "metricsinfo.h"
 #include "outputparams.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 
@@ -48,18 +50,19 @@ InsetSpace::Kind InsetSpace::kind() const
 
 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LyXFont & font = mi.base.font;
-       dim.asc = font_metrics::maxAscent(font);
-       dim.des = font_metrics::maxDescent(font);
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(mi.base.font);
+       dim.asc = fm.maxAscent();
+       dim.des = fm.maxDescent();
 
        switch (kind_) {
                case THIN:
                case NEGTHIN:
-                    dim.wid = font_metrics::width(lyx::char_type('x'), font) / 3;
+                    dim.wid = fm.width(lyx::char_type('x')) / 3;
                        break;
                case PROTECTED:
                case NORMAL:
-                    dim.wid = font_metrics::width(lyx::char_type('x'), font);
+                    dim.wid = fm.width(lyx::char_type('x'));
                        break;
                case QUAD:
                        dim.wid = 20;
@@ -79,7 +82,8 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
 {
        int const w = width();
-       int const h = font_metrics::ascent('x', pi.base.font);
+       int const h = theApp->fontLoader().metrics(pi.base.font)
+               .ascent('x');
        int xp[4], yp[4];
 
        xp[0] = x;
index 665c0dc923e2203b05cbfa6187ff8ebf6f725984..edf1053557a04802525faf7cd1ff7d6fac15f4c1 100644 (file)
@@ -20,7 +20,9 @@
 #include "lyxlex.h"
 #include "metricsinfo.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 using lyx::docstring;
@@ -43,9 +45,10 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const
 
 void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LyXFont & font = mi.base.font;
-       dim.asc = font_metrics::maxAscent(font);
-       dim.des = font_metrics::maxDescent(font);
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(mi.base.font);
+       dim.asc = fm.maxAscent();
+       dim.des = fm.maxDescent();
 
        string s;
        switch (kind_) {
@@ -56,7 +59,7 @@ void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
                case HYPHENATION:      s = "-";   break;
        }
         docstring ds(s.begin(), s.end());
-       dim.wid = font_metrics::width(ds, font);
+       dim.wid = fm.width(ds);
        if (kind_ == HYPHENATION && dim.wid > 5)
                dim.wid -= 2; // to make it look shorter
        dim_ = dim;
@@ -96,10 +99,13 @@ void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
        }
        case MENU_SEPARATOR:
        {
+               lyx::frontend::FontMetrics const & fm =
+                       theApp->fontLoader().metrics(font);
+
                // A triangle the width and height of an 'x'
-                int w = font_metrics::width(lyx::char_type('x'), font);
-               int ox = font_metrics::width(lyx::char_type(' '), font) + x;
-               int h = font_metrics::ascent(lyx::char_type('x'), font);
+                int w = fm.width(lyx::char_type('x'));
+               int ox = fm.width(lyx::char_type(' ')) + x;
+               int h = fm.ascent(lyx::char_type('x'));
                int xp[4], yp[4];
 
                xp[0] = ox;     yp[0] = y;
index 3d772296c48fe12b2f00e9f84c80144c21df59e1..bbe11a42fd02b9da8b5337ed8fe831a36e77c115 100644 (file)
@@ -38,7 +38,6 @@
 
 #include "frontends/Alert.h"
 #include "frontends/Application.h"
-#include "frontends/font_metrics.h"
 #include "frontends/Clipboard.h"
 #include "frontends/Painter.h"
 #include "frontends/Selection.h"
index 35d229d798f9f33570cf8b52729bd8b4728222e8..7519d91470cbd39458520c28c9091aa1e2585b57 100644 (file)
@@ -43,7 +43,6 @@
 #include "undo.h"
 
 #include "frontends/Alert.h"
-#include "frontends/font_metrics.h"
 #include "frontends/Painter.h"
 
 #include "support/lyxalgo.h" // lyx::count
index 8a80dd3853506124e7e8f473acffb08533be489b..7a42d5024dc2ad30e211198b38e9ef0cb31b7def 100644 (file)
@@ -23,7 +23,9 @@
 #include "lyxtext.h"
 #include "metricsinfo.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include <sstream>
@@ -131,7 +133,7 @@ void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
        int d = 0;
        string lab = label();
        docstring dlab(lab.begin(), lab.end());
-       font_metrics::rectText(dlab, font, w, a, d);
+       theApp->fontLoader().metrics(font).rectText(dlab, w, a, d);
 
        height = max(height, a + d);
 
@@ -183,7 +185,7 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
        font.decSize();
        string lab = label();
        docstring dlab(lab.begin(), lab.end());
-       font_metrics::rectText(dlab, font, w, a, d);
+       theApp->fontLoader().metrics(font).rectText(dlab, w, a, d);
 
        pi.pain.rectText(x + 2 * arrow_size + 5,
                         start + (end - start) / 2 + (a - d) / 2,
index 1537ecf14ccd46491997bf78274eae6f5cbb87b6..883b6244fe7bbbd4ae4fa4b7538973a0596757c2 100644 (file)
@@ -15,7 +15,9 @@
 #include "LColor.h"
 #include "metricsinfo.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 using lyx::docstring;
@@ -46,13 +48,15 @@ void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
 {
        LyXFont font(LyXFont::ALL_SANE);
        font.decSize();
-
-        docstring dtext(text_.begin(), text_.end());
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
+       
+       docstring dtext(text_.begin(), text_.end());
         
        if (editable_)
-               font_metrics::buttonText(dtext, font, dim.wid, dim.asc, dim.des);
+               fm.buttonText(dtext, dim.wid, dim.asc, dim.des);
        else
-               font_metrics::rectText(dtext, font, dim.wid, dim.asc, dim.des);
+               fm.rectText(dtext, dim.wid, dim.asc, dim.des);
 
        dim.wid += 4;
 }
index 442d89d5a3693ae1a28da928d1abc8d6f6360e05..3b470bde30cf6653b3fe6fb06d4e539e24ee87b9 100644 (file)
@@ -20,7 +20,9 @@
 #include "lyxrc.h"
 #include "metricsinfo.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "graphics/GraphicsImage.h"
@@ -163,15 +165,16 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
                docstring djust(justname.begin(), justname.end());
                if (!justname.empty()) {
                        msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
-                       font_width = font_metrics::width(djust, msgFont);
+                       font_width = theApp->fontLoader().metrics(msgFont)
+                               .width(djust);
                }
 
                string const msg = statusMessage(params_, loader_.status());
                if (!msg.empty()) {
                        docstring dmsg(msg.begin(), msg.end());
                        msgFont.setSize(LyXFont::SIZE_TINY);
-                       font_width = std::max(font_width,
-                                             font_metrics::width(dmsg, msgFont));
+                       font_width = std::max(font_width, theApp->fontLoader()
+                               .metrics(msgFont).width(dmsg));
                }
 
                dim.wid = std::max(50, font_width + 15);
@@ -216,7 +219,7 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
                        docstring djust(justname.begin(), justname.end());
                        msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
                        pi.pain.text(x + InsetOld::TEXT_TO_INSET_OFFSET + 6,
-                                  y - font_metrics::maxAscent(msgFont) - 4,
+                                  y - theApp->fontLoader().metrics(msgFont).maxAscent() - 4,
                                   djust, msgFont);
                }
 
index dd61fe71348ef3336dbcc256593a3ac824d775b7..c6532a4e55e03f351e5a2dc125d1dcfcf4cd0de6 100644 (file)
@@ -21,7 +21,9 @@
 #include "lyxrc.h"
 #include "metricsinfo.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "graphics/PreviewImage.h"
@@ -133,7 +135,7 @@ void RenderPreview::metrics(MetricsInfo & mi, Dimension & dim) const
                font.setSize(LyXFont::SIZE_FOOTNOTE);
                string stat = statusMessage(mi.base.bv, snippet_);
                docstring dstat(stat.begin(), stat.end());
-               dim.wid = 15 + font_metrics::width(dstat, font);
+               dim.wid = 15 + theApp->fontLoader().metrics(font).width(dstat);
        }
 
        dim_ = dim;
@@ -168,7 +170,7 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const
                string stat = statusMessage(pi.base.bv, snippet_);
                docstring dstat(stat.begin(), stat.end());
                pi.pain.text(x + offset + 6,
-                            y - font_metrics::maxAscent(font) - 4,
+                            y - theApp->fontLoader().metrics(font).maxAscent() - 4,
                             dstat, font);
        }
 }
index 70a8aaad4204d20c66f3ec7a7b6330bc8c2fc357..f08d9191a4cc494c57e9f4c5364f83fe6daa39d3 100644 (file)
@@ -136,7 +136,7 @@ int LyXLength::inPixels(int text_width, int em_width_base) const
                ? em_width_base
                : 10*(dpi/72.27)*zoom;
        // A different estimate for em_width is
-       // font_metrics::width('M', LyXFont(LyXFont::ALL_SANE))
+       // theApp->fontLoader().metrics(LyXFont(LyXFont::ALL_SANE)).width('M')
        // but this estimate might not be more accurate as the screen font
        // is different then the latex font.
 
index 4544151305ef600cc72bf01345b5eae752966192..3b644b65e45243abac603dd5cb3946e5de5fbd56 100644 (file)
 #include "lyxlex.h"
 #include "outputparams.h"
 
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
 
 #include "support/lstrings.h"
 
@@ -127,7 +129,8 @@ void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
        tmpl()->metrics(mi, dim);
        dim.asc += 5;
        dim.des += 5;
-       dim.wid += 10 + font_metrics::width(prefix(), mi.base.font);
+       dim.wid += 10 
+               + theApp->fontLoader().metrics(mi.base.font).width(prefix());
        dim_ = dim;
 }
 
@@ -162,7 +165,9 @@ void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
        pi.pain.text(x + 2, y, prefix(), font);
 
        // body
-       tmpl()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);
+       tmpl()->draw(pi,
+               x + theApp->fontLoader().metrics(p.base.font).width(prefix()) + 5,
+               y);
 
        setPosCache(pi, x, y);
 }
index b06654ae9e9581cf20af453c8bf8129b71da1ccd..3b8b87abe38c38275da66b2d406f4d7bd24e5696 100644 (file)
 #include "MathMLStream.h"
 #include "MathStream.h"
 
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
+
 #include "support/lstrings.h"
 
 
@@ -61,7 +65,8 @@ double InsetMathBig::increase() const
 
 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       double const h = mathed_char_ascent(mi.base.font, 'I');
+       double const h 
+               = theApp->fontLoader().metrics(mi.base.font).ascent('I');
        double const f = increase();
        dim_.wid = 6;
        dim_.asc = int(h + f * h);
index edec8c43d08d829828d9cefd450c221e37d63fd9..2d3c12026d68d87cf95bb9df1746d9474c4c5d54 100644 (file)
 #include "support/lstrings.h"
 #include "TextPainter.h"
 
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
+
 using std::auto_ptr;
 
 extern bool has_math_fonts;
@@ -76,7 +80,7 @@ void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
        whichFont(font_, code_, mi);
        mathed_char_dim(font_, char_, dim_);
        if (isBinaryOp(char_, code_))
-               width_ += 2 * font_metrics::width(' ', font_);
+               width_ += 2 * theApp->fontLoader().metrics(font_).width(' ');
        lyxerr << "InsetMathChar::metrics: " << dim << endl;
 #endif
        width_ = dim.wid;
index 35e433b2ee58284cf90c956ef0e52a16714e6178..32e7bc885bb2192d8f397f9a258335d93f5cff4d 100644 (file)
 #include "lyxlex.h"
 #include "LColor.h"
 
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
 
 #include "support/lstrings.h"
 
@@ -117,7 +119,7 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
        cell(1).metrics(mi);
        docstring dp = prefix();
        dim.wid = cell(0).width() + cell(1).width() + 20
-               + font_metrics::width(dp, mi.base.font);
+               + theApp->fontLoader().metrics(mi.base.font).width(dp);
        dim.asc = std::max(cell(0).ascent(),  cell(1).ascent())  + 7;
        dim.des = std::max(cell(0).descent(), cell(1).descent()) + 7;
        dim_ = dim;
@@ -155,7 +157,8 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
 #endif
        docstring dp = prefix();
        pi.pain.text(x + 2, y, dp, font);
-       x += font_metrics::width(dp, pi.base.font) + 6;
+       // FIXME: Painter text should retain the drawn text width
+       x += theApp->fontLoader().metrics(font).width(dp) + 6;
 
        int const w0 = cell(0).width();
        int const w1 = cell(1).width();
index 448b74055e41829d914ebeed767c0b41edc74ebd..f89289b5b77d32383bbccbd5140eed6283df9c7e 100644 (file)
@@ -21,9 +21,9 @@
 #include "LColor.h"
 
 #include "frontends/Application.h"
-#include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
 #include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
+#include "frontends/Painter.h"
 
 #include <map>
 #include <sstream>
@@ -368,52 +368,44 @@ deco_struct const * search_deco(string const & name)
 
 void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim)
 {
-       dim.des = font_metrics::descent(c, font);
-       dim.asc = font_metrics::ascent(c, font);
-       dim.wid = mathed_char_width(font, c);
-}
-
-
-int mathed_char_ascent(LyXFont const & font, unsigned char c)
-{
-       return font_metrics::ascent(c, font);
-}
-
-
-int mathed_char_descent(LyXFont const & font, unsigned char c)
-{
-       return font_metrics::descent(c, font);
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
+       dim.des = fm.descent(c);
+       dim.asc = fm.ascent(c);
+       dim.wid = fm.width(c);
 }
 
 
 int mathed_char_width(LyXFont const & font, unsigned char c)
 {
-       return font_metrics::width(c, font);
+       return theApp->fontLoader().metrics(font).width(c);
 }
 
 
 void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
 {
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
 #if 1
        dim.asc = 0;
        dim.des = 0;
        for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
-               dim.asc = max(dim.asc, font_metrics::ascent(*it, font));
-               dim.des = max(dim.des, font_metrics::descent(*it, font));
+               dim.asc = max(dim.asc, fm.ascent(*it));
+               dim.des = max(dim.des, fm.descent(*it));
        }
 #else
-       dim.asc = font_metrics::maxAscent(font);
-       dim.des = font_metrics::maxDescent(font);
+       dim.asc = fm.maxAscent();
+       dim.des = fm.maxDescent();
 #endif
-        docstring ds(s.begin(), s.end());
-       dim.wid = font_metrics::width(ds, font);
+       docstring ds(s.begin(), s.end());
+       dim.wid = fm.width(ds);
 }
 
 
 int mathed_string_width(LyXFont const & font, string const & s)
 {
-        docstring ds(s.begin(), s.end());
-       return font_metrics::width(ds, font);
+       docstring ds(s.begin(), s.end());
+       return theApp->fontLoader().metrics(font).width(ds);
 }
 
 
@@ -507,8 +499,10 @@ void drawStrBlack(PainterInfo & pi, int x, int y, string const & str)
 
 void math_font_max_dim(LyXFont const & font, int & asc, int & des)
 {
-       asc = font_metrics::maxAscent(font);
-       des = font_metrics::maxDescent(font);
+       lyx::frontend::FontMetrics const & fm =
+               theApp->fontLoader().metrics(font);
+       asc = fm.maxAscent();
+       des = fm.maxDescent();
 }
 
 
index 3874735e1e58a389179433d1a44cc44e3824f3ed..68fd49d6e10c52d911e3140bb74a61c2cf7833e9 100644 (file)
@@ -25,8 +25,6 @@ class InsetMath;
 
 void mathed_char_dim(LyXFont const &, unsigned char c, Dimension & dim);
 int mathed_char_width(LyXFont const &, unsigned char c);
-int mathed_char_ascent(LyXFont const &, unsigned char c);
-int mathed_char_descent(LyXFont const &, unsigned char c);
 
 void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
        std::string const & name);
index a280defd3f8f808cadbfe30bfcd9316cb37a7902..bb223599289fb204896b00b4d49d38d84ad06b01 100644 (file)
@@ -32,7 +32,9 @@
 #include "ParagraphParameters.h"
 #include "vspace.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/nullpainter.h"
 #include "frontends/Painter.h"
 
@@ -45,6 +47,8 @@
 using lyx::docstring;
 using lyx::frontend::Painter;
 using lyx::frontend::NullPainter;
+using lyx::frontend::FontMetrics;
+
 using lyx::char_type;
 using lyx::pos_type;
 using lyx::pit_type;
@@ -198,7 +202,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
        str += c;
        ++vpos;
 
-       int const width = font_metrics::width(c, font);
+       int const width = theApp->fontLoader().metrics(font).width(c);
        int dx = 0;
 
        for (pos_type i = pos - 1; i >= 0; --i) {
@@ -233,7 +237,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
        str += c;
        ++vpos;
 
-       int const width = font_metrics::width(c, font);
+       int const width = theApp->fontLoader().metrics(font).width(c);
        int dx = 0;
 
        for (pos_type i = pos - 1; i >= 0; --i) {
@@ -313,10 +317,10 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font,
        //lyxerr << "paint row: yo_ " << yo_ << "\n";
 #if 0
        pain_.text(int(x_), yo_, str, font);
-       x_ += font_metrics::width(str, font);
+       x_ += theApp->fontLoader().metrics(font).width(str);
 #else
        pain_.text(int(x_), yo_, &str[0], str.size(), font);
-       x_ += font_metrics::width(&str[0], str.size(), font);
+       x_ += theApp->fontLoader().metrics(font).width(&str[0], str.size());
 #endif
 }
 
@@ -460,7 +464,7 @@ int RowPainter::paintAppendixStart(int y)
        int a = 0;
        int d = 0;
         docstring dlab(label.begin(), label.end());
-       font_metrics::rectText(dlab, pb_font, w, a, d);
+       theApp->fontLoader().metrics(pb_font).rectText(dlab, w, a, d);
 
        int const text_start = int(xo_ + (width_ - w) / 2);
        int const text_end = text_start + w;
@@ -515,6 +519,9 @@ void RowPainter::paintFirst()
                      || is_seq)) {
 
                LyXFont const font = getLabelFont();
+               FontMetrics const & fm =
+                       theApp->fontLoader().metrics(font);
+
                string const str = par_.getLabelstring();
                if (!str.empty()) {
                        double x = x_;
@@ -531,14 +538,14 @@ void RowPainter::paintFirst()
                                        spacing_val = buffer.params().spacing().getValue();
                                }
 
-                               int const labeladdon = int(font_metrics::maxHeight(font) * layout->spacing.getValue() * spacing_val);
+                               int const labeladdon = int(fm.maxHeight() * layout->spacing.getValue() * spacing_val);
 
-                               int const maxdesc = int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
+                               int const maxdesc = int(fm.maxDescent() * layout->spacing.getValue() * spacing_val)
                                        + int(layout->parsep) * defaultRowHeight();
 
                                if (is_rtl) {
                                        x = width_ - leftMargin() -
-                                               font_metrics::width(dstr, font);
+                                               fm.width(dstr);
                                }
 
                                pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font);
@@ -547,10 +554,10 @@ void RowPainter::paintFirst()
                                 docstring dlab(lab.begin(), lab.end());
                                if (is_rtl) {
                                        x = width_ - leftMargin()
-                                               + font_metrics::width(dlab, font);
+                                               + fm.width(dlab);
                                } else {
-                                       x = x_ - font_metrics::width(dlab, font)
-                                               - font_metrics::width(dstr, font);
+                                       x = x_ - fm.width(dlab)
+                                               - fm.width(dstr);
                                }
 
                                pain_.text(int(x), yo_, dstr, font);
@@ -573,10 +580,14 @@ void RowPainter::paintFirst()
                        else
                                spacing_val = buffer.params().spacing().getValue();
 
-                       int const labeladdon = int(font_metrics::maxHeight(font) * layout->spacing.getValue() * spacing_val);
+                       FontMetrics const & fm =
+                               theApp->fontLoader().metrics(font);
+
+                       int const labeladdon = int(fm.maxHeight()
+                               * layout->spacing.getValue() * spacing_val);
 
                        int maxdesc =
-                               int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
+                               int(fm.maxDescent() * layout->spacing.getValue() * spacing_val
                                + (layout->labelbottomsep * defaultRowHeight()));
 
                        double x = x_;
@@ -584,10 +595,9 @@ void RowPainter::paintFirst()
                                if (is_rtl)
                                        x = leftMargin();
                                x += (width_ - text_.rightMargin(par_) - leftMargin()) / 2;
-                               x -= font_metrics::width(dstr, font) / 2;
+                               x -= fm.width(dstr) / 2;
                        } else if (is_rtl) {
-                               x = width_ - leftMargin() -
-                                       font_metrics::width(dstr, font);
+                               x = width_ - leftMargin() -     fm.width(dstr);
                        }
                        pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font);
                }
@@ -605,7 +615,8 @@ void RowPainter::paintLast()
        case END_LABEL_BOX:
        case END_LABEL_FILLED_BOX: {
                LyXFont const font = getLabelFont();
-               int const size = int(0.75 * font_metrics::maxAscent(font));
+               FontMetrics const & fm = theApp->fontLoader().metrics(font);
+               int const size = int(0.75 * fm.maxAscent());
                int const y = yo_ - size;
                int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
 
@@ -621,10 +632,11 @@ void RowPainter::paintLast()
 
        case END_LABEL_STATIC: {
                LyXFont font = getLabelFont();
+               FontMetrics const & fm = theApp->fontLoader().metrics(font);
                string const & str = par_.layout()->endlabelstring();
                 docstring dstr(str.begin(), str.end());
                double const x = is_rtl ?
-                       x_ - font_metrics::width(dstr, font)
+                       x_ - fm.width(dstr)
                        : - text_.rightMargin(par_) - row_.width();
                pain_.text(int(x), yo_, dstr, font);
                break;
@@ -695,9 +707,9 @@ void RowPainter::paintText()
                // We also don't paint across things like tables
                if (running_strikeout && (highly_editable_inset || !is_struckout)) {
                        // Calculate 1/3 height of the buffer's default font
-                       int const middle =
-                               yo_ -
-                               font_metrics::maxAscent(bv_.buffer()->params().getFont()) / 3;
+                       FontMetrics const & fm = theApp->fontLoader().metrics(
+                               bv_.buffer()->params().getFont());
+                       int const middle = yo_ - fm.maxAscent() / 3;
                        pain_.line(last_strikeout_x, middle, int(x_), middle,
                                LColor::strikeout, Painter::line_solid, Painter::line_thin);
                        running_strikeout = false;
@@ -706,8 +718,8 @@ void RowPainter::paintText()
                if (body_pos > 0 && pos == body_pos - 1) {
                         string lab = layout->labelsep;
                         docstring dlab(lab.begin(), lab.end());
-                       int const lwidth = font_metrics::width(dlab,
-                               getLabelFont());
+                       int const lwidth =
+                               theApp->fontLoader().metrics(getLabelFont()).width(dlab);
 
                        x_ += label_hfill_ + lwidth - width_pos;
                }
@@ -751,9 +763,9 @@ void RowPainter::paintText()
        // if we reach the end of a struck out range, paint it
        if (running_strikeout) {
                // calculate 1/3 height of the buffer's default font
-               int const middle =
-                       yo_ -
-                       font_metrics::maxAscent(bv_.buffer()->params().getFont()) / 3;
+               FontMetrics const & fm = theApp->fontLoader().metrics(
+                       bv_.buffer()->params().getFont());
+               int const middle = yo_ - fm.maxAscent() / 3;
                pain_.line(last_strikeout_x, middle, int(x_), middle,
                        LColor::strikeout, Painter::line_solid, Painter::line_thin);
                running_strikeout = false;
index b7eccfcadbe3c5e2eb74c93aff666b5fa9dbcb21..26b31905114c84d7c4a3b012f83cc5851da46e15 100644 (file)
@@ -51,7 +51,9 @@
 #include "vspace.h"
 #include "WordLangTuple.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "insets/insettext.h"
@@ -89,6 +91,8 @@ using lyx::support::uppercase;
 using lyx::cap::cutSelection;
 using lyx::cap::pasteParagraphList;
 
+using lyx::frontend::FontMetrics;
+
 using std::auto_ptr;
 using std::advance;
 using std::distance;
@@ -462,13 +466,13 @@ int LyXText::singleWidth(Paragraph const & par,
                                   Encodings::isComposeChar_hebrew(c))
                                return 0;
                }
-               return font_metrics::width(c, font);
+               return theApp->fontLoader().metrics(font).width(c);
        }
 
        if (c == Paragraph::META_INSET)
                return par.getInset(pos)->width();
 
-       return font_metrics::width(c, font);
+       return theApp->fontLoader().metrics(font).width(c);
 }
 
 
@@ -501,7 +505,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
 
        string leftm = tclass.leftmargin();
        docstring dleft(leftm.begin(), leftm.end());
-       l_margin += font_metrics::signedWidth(dleft, params.getFont());
+       l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(dleft);
 
        if (par.getDepth() != 0) {
                // find the next level paragraph
@@ -527,43 +531,41 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
                parindent.erase();
 
        LyXFont const labelfont = getLabelFont(par);
+       FontMetrics const & labelfont_metrics = theApp->fontLoader().metrics(labelfont);
+
        switch (layout->margintype) {
        case MARGIN_DYNAMIC:
                if (!layout->leftmargin.empty()) {
                        string leftm = layout->leftmargin;
                        docstring dleft(leftm.begin(), leftm.end());
-                       l_margin += font_metrics::signedWidth(dleft,
-                                                             params.getFont());
+                       l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(dleft);
                }
                if (!par.getLabelstring().empty()) {
                        string labin = layout->labelindent;
                        docstring dlabin(labin.begin(), labin.end());
-                       l_margin += font_metrics::signedWidth(dlabin,
-                                                 labelfont);
+                       l_margin += labelfont_metrics.signedWidth(dlabin);
                        string labstr = par.getLabelstring();
                        docstring dlabstr(labstr.begin(), labstr.end());
-                       l_margin += font_metrics::width(dlabstr,
-                                           labelfont);
+                       l_margin += labelfont_metrics.width(dlabstr);
                        string labsep = layout->labelsep;
                        docstring dlabsep(labsep.begin(), labsep.end());
-                       l_margin += font_metrics::width(dlabsep, labelfont);
+                       l_margin += labelfont_metrics.width(dlabsep);
                }
                break;
 
        case MARGIN_MANUAL: {
                string labin = layout->labelindent;
                docstring dlabin(labin.begin(), labin.end());
-               l_margin += font_metrics::signedWidth(dlabin, labelfont);
+               l_margin += labelfont_metrics.signedWidth(dlabin);
                // The width of an empty par, even with manual label, should be 0
                if (!par.empty() && pos >= par.beginOfBody()) {
                        if (!par.getLabelWidthString().empty()) {
                                string labstr = par.getLabelWidthString();
                                docstring dlabstr(labstr.begin(), labstr.end());
-                               l_margin += font_metrics::width(dlabstr,
-                                              labelfont);
+                               l_margin += labelfont_metrics.width(dlabstr);
                                string labsep = layout->labelsep;
                                docstring dlabsep(labsep.begin(), labsep.end());
-                               l_margin += font_metrics::width(dlabsep, labelfont);
+                               l_margin += labelfont_metrics.width(dlabsep);
                        }
                }
                break;
@@ -572,8 +574,9 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
        case MARGIN_STATIC: {
                string leftm = layout->leftmargin;
                docstring dleft(leftm.begin(), leftm.end());
-               l_margin += font_metrics::signedWidth(dleft, params.getFont()) * 4
-                       / (par.getDepth() + 4);
+               l_margin += 
+                       theApp->fontLoader().metrics(params.getFont()).signedWidth(dleft)
+                       * 4     / (par.getDepth() + 4);
                break;
        }
 
@@ -582,13 +585,11 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
                        if (pos >= par.beginOfBody()) {
                                string leftm = layout->leftmargin;
                                docstring dleft(leftm.begin(), leftm.end());
-                               l_margin += font_metrics::signedWidth(dleft,
-                                                         labelfont);
+                               l_margin += labelfont_metrics.signedWidth(dleft);
                        } else {
                                string labin = layout->labelindent;
                                docstring dlabin(labin.begin(), labin.end());
-                               l_margin += font_metrics::signedWidth(dlabin,
-                                                         labelfont);
+                               l_margin += labelfont_metrics.signedWidth(dlabin);
                        }
                } else if (pos != 0
                           // Special case to fix problems with
@@ -598,22 +599,20 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
                               && !isFirstInSequence(pit, pars_))) {
                        string leftm = layout->leftmargin;
                        docstring dleft(leftm.begin(), leftm.end());
-                       l_margin += font_metrics::signedWidth(dleft,
-                                                 labelfont);
+                       l_margin += labelfont_metrics.signedWidth(dleft);
                } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
                           && layout->labeltype != LABEL_BIBLIO
                           && layout->labeltype !=
                           LABEL_CENTERED_TOP_ENVIRONMENT) {
                        string labin = layout->labelindent;
                        docstring dlabin(labin.begin(), labin.end());
-                       l_margin += font_metrics::signedWidth(dlabin,
-                                                 labelfont);
+                       l_margin += labelfont_metrics.signedWidth(dlabin);
                        string labsep = layout->labelsep;
                        docstring dlabsep(labsep.begin(), labsep.end());
-                       l_margin += font_metrics::width(dlabsep, labelfont);
+                       l_margin += labelfont_metrics.width(dlabsep);
                        string labstr = par.getLabelstring();
                        docstring dlabstr(labstr.begin(), labstr.end());
-                       l_margin += font_metrics::width(dlabstr, labelfont);
+                       l_margin += labelfont_metrics.width(dlabstr);
                }
                break;
 
@@ -630,8 +629,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
                for ( ; rit != end; ++rit)
                        if (rit->fill() < minfill)
                                minfill = rit->fill();
-               l_margin += font_metrics::signedWidth(layout->leftmargin,
-                       params.getFont());
+               l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(layout->leftmargin);
                l_margin += minfill;
 #endif
                // also wrong, but much shorter.
@@ -671,7 +669,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
                   BufferParams::PARSEP_INDENT))
        {
                docstring din(parindent.begin(), parindent.end());
-               l_margin += font_metrics::signedWidth(din, params.getFont());
+               l_margin += theApp->fontLoader().metrics(params.getFont()).signedWidth(din);
        }
 
        return l_margin;
@@ -693,12 +691,11 @@ int LyXText::rightMargin(Paragraph const & par) const
        docstring dtrmarg(trmarg.begin(), trmarg.end());
        string lrmarg = par.layout()->rightmargin;
        docstring dlrmarg(lrmarg.begin(), lrmarg.end());
+       FontMetrics const & fm = theApp->fontLoader().metrics(params.getFont());
        int const r_margin =
                ::rightMargin()
-               + font_metrics::signedWidth(dtrmarg,
-                                           params.getFont())
-               + font_metrics::signedWidth(dlrmarg,
-                                           params.getFont())
+               + fm.signedWidth(dtrmarg)
+               + fm.signedWidth(dlrmarg)
                * 4 / (par.getDepth() + 4);
 
        return r_margin;
@@ -772,6 +769,7 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
        FontIterator fi = FontIterator(*this, par, pos);
        pos_type point = end;
        pos_type i = pos;
+       FontMetrics const & fm = theApp->fontLoader().metrics(getLabelFont(par));
        for ( ; i < end; ++i, ++fi) {
                char_type const c = par.getChar(i);
                int thiswidth = singleWidth(par, i, c, *fi);
@@ -780,7 +778,7 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
                if (body_pos && i == body_pos) {
                        string lsep = layout->labelsep;
                        docstring dlsep(lsep.begin(), lsep.end());
-                       int add = font_metrics::width(dlsep, getLabelFont(par));
+                       int add = fm.width(dlsep);
                        if (par.isLineSeparator(i - 1))
                                add -= singleWidth(par, i - 1);
 
@@ -860,11 +858,13 @@ void LyXText::setRowWidth(pit_type const pit, Row & row) const
        pos_type const body_pos = par.beginOfBody();
        pos_type i = row.pos();
 
+       FontMetrics const & fm = theApp->fontLoader().metrics(getLabelFont(par));
+
        if (i < end) {
                FontIterator fi = FontIterator(*this, par, i);
                for ( ; i < end; ++i, ++fi) {
                        if (body_pos > 0 && i == body_pos) {
-                               w += font_metrics::width(dlsep, getLabelFont(par));
+                               w += fm.width(dlsep);
                                if (par.isLineSeparator(i - 1))
                                        w -= singleWidth(par, i - 1);
                                w = max(w, labelEnd(pit));
@@ -875,7 +875,7 @@ void LyXText::setRowWidth(pit_type const pit, Row & row) const
        }
 
        if (body_pos > 0 && body_pos >= end) {
-               w += font_metrics::width(dlsep, getLabelFont(par));
+               w += fm.width(dlsep);
                if (end > 0 && par.isLineSeparator(end - 1))
                        w -= singleWidth(par, end - 1);
                w = max(w, labelEnd(pit));
@@ -908,7 +908,10 @@ int LyXText::labelFill(Paragraph const & par, Row const & row) const
                return 0;
 
        docstring dlab(label.begin(), label.end());
-       return max(0, font_metrics::width(dlab, getLabelFont(par)) - w);
+
+       FontMetrics const & fm = theApp->fontLoader().metrics(getLabelFont(par));
+
+       return max(0, fm.width(dlab) - w);
 }
 
 
@@ -943,11 +946,14 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
 
        LyXFont labelfont = getLabelFont(par);
 
+       FontMetrics const & labelfont_metrics = theApp->fontLoader().metrics(labelfont);
+       FontMetrics const & fontmetrics = theApp->fontLoader().metrics(font);
+
        // these are minimum values
        double const spacing_val = layout->spacing.getValue() * spacing(par);
        //lyxerr << "spacing_val = " << spacing_val << endl;
-       int maxasc  = int(font_metrics::maxAscent(font)  * spacing_val);
-       int maxdesc = int(font_metrics::maxDescent(font) * spacing_val);
+       int maxasc  = int(fontmetrics.maxAscent()  * spacing_val);
+       int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
 
        // insets may be taller
        InsetList::const_iterator ii = par.insetlist.begin();
@@ -969,8 +975,8 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
                par.highestFontInRange(row.pos(), pos_end, size);
        if (maxsize > font.size()) {
                font.setSize(maxsize);
-               maxasc  = max(maxasc,  font_metrics::maxAscent(font));
-               maxdesc = max(maxdesc, font_metrics::maxDescent(font));
+               maxasc  = max(maxasc,  fontmetrics.maxAscent());
+               maxdesc = max(maxdesc, fontmetrics.maxDescent());
        }
 
        // This is nicer with box insets:
@@ -1000,7 +1006,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
                // layout is printed in an extra row
                if (layout->counter == "chapter"
                    && !par.params().labelString().empty()) {
-                       labeladdon = int(font_metrics::maxHeight(labelfont)
+                       labeladdon = int(labelfont_metrics.maxHeight()
                                     * layout->spacing.getValue()
                                     * spacing(par));
                }
@@ -1013,7 +1019,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
                    && !par.getLabelstring().empty())
                {
                        labeladdon = int(
-                                 font_metrics::maxHeight(labelfont)
+                                 labelfont_metrics.maxHeight()
                                        * layout->spacing.getValue()
                                        * spacing(par)
                                + (layout->topsep + layout->labelbottomsep) * dh);
@@ -1390,7 +1396,7 @@ LyXText::computeRowMetrics(pit_type const pit, Row const & row) const
                {
                        string lsep = layout->labelsep;
                        docstring dlsep(lsep.begin(), lsep.end());
-                       result.x += font_metrics::width(dlsep, getLabelFont(par));
+                       result.x += theApp->fontLoader().metrics(getLabelFont(par)).width(dlsep);
                        if (body_pos <= end)
                                result.x += result.label_hfill;
                }
@@ -2294,15 +2300,14 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
        // Use font span to speed things up, see below
        FontSpan font_span;
        LyXFont font;
+       FontMetrics const & labelfm = theApp->fontLoader().metrics(getLabelFont(par));
 
        for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
                pos_type pos = bidi.vis2log(vpos);
                if (body_pos > 0 && pos == body_pos - 1) {
                        string lsep = par.layout()->labelsep;
                        docstring dlsep(lsep.begin(), lsep.end());
-                       x += m.label_hfill
-                               + font_metrics::width(dlsep,
-                                                     getLabelFont(par));
+                       x += m.label_hfill + labelfm.width(dlsep);
                        if (par.isLineSeparator(body_pos - 1))
                                x -= singleWidth(par, body_pos - 1);
                }
index 403300a987fab14de7d3b2cd3ace8f558daf237b..2ce03f2d0984b4e5f4658bc1771babe4732bee7a 100644 (file)
@@ -51,7 +51,8 @@
 #include "vspace.h"
 
 #include "frontends/Application.h"
-#include "frontends/font_metrics.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
 
 #include "insets/insetenv.h"
 
@@ -804,14 +805,16 @@ pos_type LyXText::getColumnNearX(pit_type const pit,
                return 0;
        }
 
+       lyx::frontend::FontMetrics const & fm = theApp->fontLoader().metrics(
+               getLabelFont(par));
+
        while (vc < end && tmpx <= x) {
                c = bidi.vis2log(vc);
                last_tmpx = tmpx;
                if (body_pos > 0 && c == body_pos - 1) {
                        string lsep = layout->labelsep;
                        docstring dlsep(lsep.begin(), lsep.end());
-                       tmpx += r.label_hfill +
-                               font_metrics::width(dlsep, getLabelFont(par));
+                       tmpx += r.label_hfill + fm.width(dlsep);
                        if (par.isLineSeparator(body_pos - 1))
                                tmpx -= singleWidth(par, body_pos - 1);
                }
@@ -1342,5 +1345,5 @@ void LyXText::recUndo(pit_type par) const
 
 int defaultRowHeight()
 {
-       return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) *  1.2);
+       return int(theApp->fontLoader().metrics(LyXFont(LyXFont::ALL_SANE)).maxHeight() *  1.2);
 }