]> git.lyx.org Git - lyx.git/commitdiff
Compile fix. This was easy, since the code is alsmost identical to qt4,
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 8 Oct 2006 07:39:02 +0000 (07:39 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 8 Oct 2006 07:39:02 +0000 (07:39 +0000)
but I am not going to do gtk.

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

development/scons/scons_manifest.py
src/frontends/qt3/GuiFontMetrics.C [new file with mode: 0644]
src/frontends/qt3/GuiFontMetrics.h [new file with mode: 0644]
src/frontends/qt3/Makefile.am
src/frontends/qt3/QLPainter.C
src/frontends/qt3/qfont_loader.C
src/frontends/qt3/qfont_loader.h
src/frontends/qt3/qfont_metrics.C [deleted file]
src/frontends/qt3/qt_helpers.C
src/frontends/qt3/qt_helpers.h

index 1b0b5c058d3c270b3311e31c766cfde026bd155f..1cdaee1103274aaa1ff4d125a8c375e3e5abc25c 100644 (file)
@@ -735,6 +735,7 @@ src_frontends_qt3_header_files = Split('''
     FileDialog_private.h
     GuiApplication.h
     GuiClipboard.h
+    GuiFontMetrics.h
     GuiImplementation.h
     GuiSelection.h
     GuiWorkArea.h
@@ -856,6 +857,7 @@ src_frontends_qt3_files = Split('''
     FileDialog_private.C
     GuiApplication.C
     GuiClipboard.C
+    GuiFontMetrics.C
     GuiSelection.C
     LyXKeySymFactory.C
     QAbout.C
@@ -956,7 +958,6 @@ src_frontends_qt3_files = Split('''
     panelstack.C
     qcoloritem.C
     qfont_loader.C
-    qfont_metrics.C
     qfontexample.C
     qscreen.C
     qsetborder.C
diff --git a/src/frontends/qt3/GuiFontMetrics.C b/src/frontends/qt3/GuiFontMetrics.C
new file mode 100644 (file)
index 0000000..3e4fdd9
--- /dev/null
@@ -0,0 +1,199 @@
+/**
+ * \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.length();
+
+       for (int i = 0; i < ls; ++i) {
+               QChar const & c = s[i];
+               QChar const uc = c.upper();
+               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 const ucs2 = toqstr(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
+{
+       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/qt3/GuiFontMetrics.h b/src/frontends/qt3/GuiFontMetrics.h
new file mode 100644 (file)
index 0000000..c944269
--- /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 QT3_FONT_METRICS_H
+#define QT3_FONT_METRICS_H
+
+#include "frontends/FontMetrics.h"
+
+#include "support/docstring.h"
+
+#include <qfontmetrics.h>
+
+// 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 // QT3_FONT_METRICS_H
index 18997b26b1957806a058604f52a49b69eb2d5dee..65bbd2cf59817742432f6cf9cf8878cb36f3ae67 100644 (file)
@@ -36,6 +36,7 @@ libqt3_la_SOURCES = \
        FileDialog.C \
        GuiApplication.C GuiApplication.h \
        GuiClipboard.C GuiClipboard.h \
+       GuiFontMetrics.C GuiFontMetrics.h \
        GuiImplementation.h \
        GuiSelection.C GuiSelection.h \
        GuiWorkArea.h \
@@ -91,7 +92,6 @@ libqt3_la_SOURCES = \
        qcoloritem.h qcoloritem.C \
        qfontexample.h qfontexample.C \
        qfont_loader.h qfont_loader.C \
-       qfont_metrics.C \
        qlkey.h \
        qscreen.h qscreen.C \
        qt_helpers.h qt_helpers.C \
index 550f87ceaf0eb6084a04b3469e6cd15d572880f1..7c788193b6a34cfba813a4f5b71e5830ea594dfb 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "support/unicode.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/FontMetrics.h"
 
 #include <qpainter.h>
 
@@ -245,7 +245,7 @@ void QLPainter::text(int x, int y, lyx::char_type const * s, size_t ls,
        }
 
        if (f.underbar() == LyXFont::ON) {
-               underline(f, x, y, font_metrics::width(s, ls, f));
+               underline(f, x, y, qp_->fontMetrics().width(str));
        }
 }
 
index b0906c7cb0eac5c2af6ee3c04c70a2e3da9b0b59..8304584e3ae27baa9321ce2d544d535df0ffa711 100644 (file)
@@ -219,7 +219,6 @@ void GuiFontLoader::update()
 
 
 QLFontInfo::QLFontInfo(LyXFont const & f)
-       : metrics(font)
 {
 
        string const pat = symbolFamily(f.family());
@@ -285,25 +284,7 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
 
        lyxerr[Debug::FONT] << "XFLD: " << font.rawName() << endl;
 
-       metrics = QFontMetrics(font);
-}
-
-
-int QLFontInfo::width(Uchar val)
-{
-// Starting with version 3.1.0, Qt/X11 does its own caching of
-// character width, so it is not necessary to provide ours.
-#if defined (USE_LYX_FONTCACHE)
-       QLFontInfo::WidthCache::const_iterator cit = widthcache.find(val);
-       if (cit != widthcache.end())
-               return cit->second;
-
-       int const w = metrics.width(QChar(val));
-       widthcache[val] = w;
-       return w;
-#else
-       return metrics.width(QChar(val));
-#endif
+       metrics.reset(new lyx::frontend::GuiFontMetrics(font));
 }
 
 
index d18e729ca8d88a3bfbc6d54ed7cd2e9b741196c0..aba64084337f4c51cc13d7b239fdf66619288cc7 100644 (file)
 
 #include "frontends/FontLoader.h"
 
+#include "GuiFontMetrics.h"
+
 #include "encoding.h"
 #include "lyxfont.h"
 
 #include <qfont.h>
-#include <qfontmetrics.h>
-
-#if QT_VERSION < 0x030100 || defined(Q_WS_MACX)
-#define USE_LYX_FONTCACHE
-#endif
 
-#if defined(USE_LYX_FONTCACHE)
-#include <map>
-#endif
 
 /**
  * Qt font loader for LyX. Matches LyXFonts against
@@ -36,19 +30,10 @@ class QLFontInfo {
 public:
        QLFontInfo(LyXFont const & f);
 
-       /// Return pixel width for the given unicode char
-       int width(Uchar val);
-
        /// The font instance
        QFont font;
        /// Metrics on the font
-       QFontMetrics metrics;
-
-#if defined(USE_LYX_FONTCACHE)
-       typedef std::map<Uchar, int> WidthCache;
-       /// Cache of char widths
-       WidthCache widthcache;
-#endif
+       boost::scoped_ptr<lyx::frontend::GuiFontMetrics> metrics;
 };
 
 
@@ -73,8 +58,8 @@ public:
        }
 
        /// Get the QFont metrics for this LyXFont
-       QFontMetrics const & metrics(LyXFont const & f) {
-               return fontinfo(f).metrics;
+       lyx::frontend::FontMetrics const & metrics(LyXFont const & f) {
+               return *(fontinfo(f).metrics);
        }
 
        /// Called the first time when available() can't load a symbol font
diff --git a/src/frontends/qt3/qfont_metrics.C b/src/frontends/qt3/qfont_metrics.C
deleted file mode 100644 (file)
index 135d55e..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 "qfont_loader.h"
-
-#include "language.h"
-
-#include "support/unicode.h"
-
-using lyx::char_type;
-using lyx::docstring;
-
-using std::string;
-
-
-namespace {
-
-int smallcapswidth(unsigned short const * s, size_t ls, 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 = fontloader.metrics(f);
-       QFontMetrics const & qsmallm = fontloader.metrics(smallfont);
-
-       int w = 0;
-
-       for (size_t i = 0; i < ls; ++i) {
-               QChar const c = s[i];
-               QChar const uc = c.upper();
-               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 fontloader.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 fontloader.metrics(f).descent() + 1;
-}
-
-
-int font_metrics::ascent(char_type c, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-
-       QRect const & r = fontloader.metrics(f).boundingRect(ucs4_to_ucs2(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 = fontloader.metrics(f).boundingRect(ucs4_to_ucs2(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 fontloader.metrics(f).leftBearing(ucs4_to_ucs2(c));
-}
-
-
-int font_metrics::rbearing(char_type c, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return 1;
-
-       QFontMetrics const & m = fontloader.metrics(f);
-
-       // Qt rbearing is from the right edge of the char's width().
-       unsigned short sc = ucs4_to_ucs2(c);
-       return m.width(sc) - m.rightBearing(sc);
-}
-
-
-int font_metrics::width(lyx::char_type const * str, size_t const ls, LyXFont const & f)
-{
-       if (!lyx_gui::use_gui)
-               return ls;
-
-       std::vector<unsigned short> ucs2 = ucs4_to_ucs2(str, ls);
-       ucs2.push_back(0);
-
-       if (f.realShape() == LyXFont::SMALLCAPS_SHAPE)
-               return smallcapswidth(&ucs2[0], ls, f);
-
-       QLFontInfo & fi = fontloader.fontinfo(f);
-
-       if (ls == 1)
-               return fi.width(ucs2[0]);
-
-       int w = 0;
-       for (size_t i = 0; i < ls; ++i)
-               w += fi.width(ucs2[i]);
-
-       return w;
-}
-
-
-void font_metrics::rectText(docstring const & str, LyXFont const & f,
-       int & w, int & ascent, int & descent)
-{
-       QFontMetrics const & m = fontloader.metrics(f);
-       static int const d = 2;
-       w = font_metrics::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 = fontloader.metrics(f);
-       static int const d = 3;
-       w = font_metrics::width(str, f) + d * 2 + 2;
-       ascent = m.ascent() + d;
-       descent = m.descent() + d;
-}
-
-
-int font_metrics::signedWidth(docstring const & s, LyXFont const & f)
-{
-       if (s[0] == '-')
-               return -font_metrics::width(s.substr(1, s.length() - 1), f);
-       else
-               return font_metrics::width(s, f);
-}
index b9b4317862c5a3d57fb9a84a9cd0a984538bdb5a..51e06f2fd43b21d74796ca5fbb70cdcd0c19a75d 100644 (file)
@@ -126,6 +126,15 @@ QString const toqstr(docstring const & str)
 }
 
 
+QString const toqstr(lyx::char_type const * str, size_t ls)
+{
+       std::vector<unsigned short> ucs2 =
+               ucs4_to_ucs2(str, ls);
+       ucs2.push_back('\0');
+       return QString::fromUcs2(&ucs2[0]);
+}
+
+
 QString const qt_(char const * str)
 {
        return toqstr(_(str));
index 3ddf8b11a2dc6b74be90b79f46140a2447af7d68..72f739e89ad5e675854350c7a22cc0867baaaad9 100644 (file)
 #include "lyxlength.h"
 #include "support/docstring.h"
 
+#include <qstring.h>
+
 class LengthCombo;
 class QComboBox;
 class QLineEdit;
-class QString;
 
 std::string makeFontName(std::string const & family, std::string const & foundry);
 
@@ -62,6 +63,17 @@ QString const toqstr(std::string const & str);
 QString const toqstr(lyx::docstring const & str);
 
 
+/**
+ * toqstr - convert UCS4 encoded docstring to QString
+ */
+QString const toqstr(lyx::char_type const * str, size_t ls);
+
+
+inline QChar const ucs4_to_qchar(lyx::char_type const ucs4) {
+       return QChar(static_cast<unsigned short>(ucs4));
+}
+
+
 /**
  * qt_ - i18nize string and convert to unicode
  *