Hello,
This patch implement my promised FontLoader interface. In the future, I
intend to extend it with a proper encapsulation of font metrics.
I've tried to update qt3 and gtk but as usual I cannot guaranty that it
will compile nor work.
I am going to commit soon.
Abdel.
Index: development/scons/scons_manifest.py
===================================================================
--- development/scons/scons_manifest.py (revision 15208)
+++ development/scons/scons_manifest.py (working copy)
@@ -432,6 +432,7 @@
Clipboard.h
Dialogs.h
FileDialog.h
+ FontLoader.h
Gui.h
LyXKeySym.h
LyXKeySymFactory.h
@@ -1112,9 +1113,9 @@
BulletsModule.h
ColorCache.h
FileDialog_private.h
- FontLoader.h
GuiApplication.h
GuiClipboard.h
+ GuiFontLoader.h
GuiImplementation.h
GuiSelection.h
GuiView.h
@@ -1232,9 +1233,9 @@
Dialogs.C
FileDialog.C
FileDialog_private.C
- FontLoader.C
GuiApplication.C
GuiClipboard.C
+ GuiFontLoader.C
GuiImplementation.C
GuiSelection.C
GuiView.C
Index: src/frontends/Application.h
===================================================================
--- src/frontends/Application.h (revision 15217)
+++ src/frontends/Application.h (working copy)
@@ -27,6 +27,7 @@
struct Application_pimpl;
class Clipboard;
+class FontLoader;
class Gui;
class Selection;
@@ -65,6 +66,8 @@
virtual Clipboard & clipboard() = 0;
///
virtual Selection & selection() = 0;
+ ///
+ virtual FontLoader & fontLoader() = 0;
/// return a suitable serif font name.
virtual std::string const romanFontName() = 0;
Index: src/frontends/FontLoader.h
===================================================================
--- src/frontends/FontLoader.h (revision 0)
+++ src/frontends/FontLoader.h (revision 0)
@@ -0,0 +1,39 @@
+// -*- C++ -*-
+/**
+ * \file FontLoader.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 LYX_FONTLOADER_H
+#define LYX_FONTLOADER_H
+
+class LyXFont;
+
+namespace lyx {
+namespace frontend {
+
+/// Hold info about a particular font
+class FontLoader
+{
+public:
+ ///
+ FontLoader() {}
+ ///
+ virtual ~FontLoader() {}
+
+ /// Update fonts after zoom, dpi, font names, or norm change
+ virtual void update() = 0;
+
+ /// Is the given font available ?
+ virtual bool available(LyXFont const & f) = 0;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // QFONT_LOADER_H
Property changes on: src\frontends\FontLoader.h
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/frontends/gtk/GuiApplication.h
===================================================================
--- src/frontends/gtk/GuiApplication.h (revision 15217)
+++ src/frontends/gtk/GuiApplication.h (working copy)
@@ -50,6 +50,7 @@
//@{
virtual Clipboard& clipboard();
virtual Selection& selection();
+ virtual FontLoader & fontLoader() { return font_loader_; }
virtual int const exec();
virtual Gui & gui() { return gui_; }
virtual void exit(int status);
@@ -59,7 +60,6 @@
//@}
///
- xftFontLoader & fontLoader() { return font_loader_; }
private:
///
Index: src/frontends/gtk/lyx_gui.C
===================================================================
--- src/frontends/gtk/lyx_gui.C (revision 15217)
+++ src/frontends/gtk/lyx_gui.C (working copy)
@@ -152,18 +152,6 @@
}
-void lyx_gui::update_fonts()
-{
- fontLoader.update();
-}
-
-
-bool lyx_gui::font_available(LyXFont const & font)
-{
- return fontLoader.available(font);
-}
-
-
namespace {
std::map<int, boost::shared_ptr<io_callback> > callbacks;
Index: src/frontends/gtk/xftFontLoader.h
===================================================================
--- src/frontends/gtk/xftFontLoader.h (revision 15217)
+++ src/frontends/gtk/xftFontLoader.h (working copy)
@@ -12,6 +12,8 @@
#ifndef XFT_FONT_LOADER_H
#define XFT_FONT_LOADER_H
+#include "frontends/FontLoader.h"
+
#include "lyxfont.h"
#include <gtkmm.h>
@@ -20,18 +22,18 @@
class GWorkArea;
-class xftFontLoader {
+class xftFontLoader: public lyx::frontend::FontLoader {
public:
///
xftFontLoader();
///
- ~xftFontLoader();
+ virtual ~xftFontLoader();
/// Update fonts after zoom, dpi, font names, or norm change
- void update();
+ virtual void update();
- bool available(LyXFont const & f);
+ virtual bool available(LyXFont const & f);
/// Load font
XftFont * load(LyXFont::FONT_FAMILY family,
Index: src/frontends/lyx_gui.h
===================================================================
--- src/frontends/lyx_gui.h (revision 15217)
+++ src/frontends/lyx_gui.h (working copy)
@@ -76,16 +76,6 @@
void update_color(LColor_color col);
/**
- * update the font cache
- */
-void update_fonts();
-
-/**
- * is the given font available ?
- */
-bool font_available(LyXFont const & font);
-
-/**
* add a callback for socket read notification
* @param fd socket descriptor (file/socket/etc)
*/
Index: src/frontends/Makefile.am
===================================================================
--- src/frontends/Makefile.am (revision 15217)
+++ src/frontends/Makefile.am (working copy)
@@ -21,6 +21,7 @@
Dialogs.C \
Dialogs.h \
FileDialog.h \
+ FontLoader.h \
LyXKeySym.h \
LyXKeySymFactory.h \
LyXView.C \
Index: src/frontends/qt3/GuiApplication.h
===================================================================
--- src/frontends/qt3/GuiApplication.h (revision 15217)
+++ src/frontends/qt3/GuiApplication.h (working copy)
@@ -56,6 +56,7 @@
//@{
virtual Clipboard& clipboard();
virtual Selection& selection();
+ virtual FontLoader & fontLoader() { return font_loader_; }
virtual int const exec();
virtual Gui & gui() { return gui_; }
virtual void exit(int status);
@@ -65,8 +66,6 @@
//@}
///
- FontLoader & fontLoader() { return font_loader_; }
-
private:
///
GuiImplementation gui_;
@@ -75,7 +74,7 @@
///
GuiSelection selection_;
///
- FontLoader font_loader_;
+ GuiFontLoader font_loader_;
#ifdef Q_WS_X11
public:
Index: src/frontends/qt3/lyx_gui.C
===================================================================
--- src/frontends/qt3/lyx_gui.C (revision 15217)
+++ src/frontends/qt3/lyx_gui.C (working copy)
@@ -137,18 +137,6 @@
}
-void update_fonts()
-{
- fontloader.update();
-}
-
-
-bool font_available(LyXFont const & font)
-{
- return fontloader.available(font);
-}
-
-
void register_socket_callback(int fd, boost::function<void()> func)
{
socket_callbacks[fd] = shared_ptr<socket_callback>(new
socket_callback(fd, func));
Index: src/frontends/qt3/qfont_loader.C
===================================================================
--- src/frontends/qt3/qfont_loader.C (revision 15217)
+++ src/frontends/qt3/qfont_loader.C (working copy)
@@ -47,7 +47,7 @@
using std::string;
-FontLoader::~FontLoader() {
+GuiFontLoader::~GuiFontLoader() {
}
namespace {
@@ -193,7 +193,7 @@
} // namespace anon
-FontLoader::FontLoader()
+GuiFontLoader::GuiFontLoader()
{
for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
for (int i2 = 0; i2 < 2; ++i2)
@@ -203,7 +203,7 @@
}
-void FontLoader::update()
+void GuiFontLoader::update()
{
for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
for (int i2 = 0; i2 < 2; ++i2)
@@ -307,7 +307,7 @@
}
-bool FontLoader::available(LyXFont const & f)
+bool GuiFontLoader::available(LyXFont const & f)
{
if (!lyx_gui::use_gui)
return false;
Index: src/frontends/qt3/qfont_loader.h
===================================================================
--- src/frontends/qt3/qfont_loader.h (revision 15217)
+++ src/frontends/qt3/qfont_loader.h (working copy)
@@ -12,6 +12,8 @@
#ifndef QFONTLOADER_H
#define QFONTLOADER_H
+#include "frontends/FontLoader.h"
+
#include "encoding.h"
#include "lyxfont.h"
@@ -51,19 +53,19 @@
/// Hold info about a particular font
-class FontLoader {
+class GuiFontLoader: public lyx::frontend::FontLoader {
public:
///
- FontLoader();
+ GuiFontLoader();
/// Destructor
- ~FontLoader();
+ virtual ~GuiFontLoader();
/// Update fonts after zoom, dpi, font names, or norm change
- void update();
+ virtual void update();
/// Do we have anything matching?
- bool available(LyXFont const & f);
+ virtual bool available(LyXFont const & f);
/// Get the QFont for this LyXFont
QFont const & get(LyXFont const & f) {
@@ -94,6 +96,6 @@
QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
};
-extern FontLoader fontloader;
+extern GuiFontLoader fontloader;
#endif // QFONT_LOADER_H
Index: src/frontends/qt3/QtView.C
===================================================================
--- src/frontends/qt3/QtView.C (revision 15217)
+++ src/frontends/qt3/QtView.C (working copy)
@@ -40,7 +40,7 @@
using std::string;
-FontLoader fontloader;
+GuiFontLoader fontloader;
namespace lyx {
Index: src/frontends/qt4/FontLoader.C
===================================================================
--- src/frontends/qt4/FontLoader.C (revision 15217)
+++ src/frontends/qt4/FontLoader.C (working copy)
@@ -1,332 +0,0 @@
-/**
- * \file FontLoader.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Asger Alstrup
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "FontLoader.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-#include "lyxrc.h"
-
-#include "frontends/lyx_gui.h"
-
-#include "support/convert.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
-#include "support/systemcall.h"
-
-#include <qfontinfo.h>
-
-#include <boost/tuple/tuple.hpp>
-
-#ifdef Q_WS_X11
-#include <qwidget.h>
-#include <X11/Xlib.h>
-#include <algorithm>
-#endif
-
-using lyx::support::contains;
-
-using std::endl;
-using std::make_pair;
-
-using std::pair;
-using std::vector;
-using std::string;
-
-
-FontLoader::~FontLoader() {
-}
-
-namespace {
-
-struct symbol_font {
- LyXFont::FONT_FAMILY lyx_family;
- string family;
- string xlfd;
-};
-
-symbol_font symbol_fonts[] = {
- { LyXFont::SYMBOL_FAMILY,
- "symbol",
- "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific" },
-
- { LyXFont::CMR_FAMILY,
- "cmr10",
- "-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*" },
-
- { LyXFont::CMSY_FAMILY,
- "cmsy10",
- "-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*" },
-
- { LyXFont::CMM_FAMILY,
- "cmmi10",
- "-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*" },
-
- { LyXFont::CMEX_FAMILY,
- "cmex10",
- "-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*" },
-
- { LyXFont::MSA_FAMILY,
- "msam10",
- "-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*" },
-
- { LyXFont::MSB_FAMILY,
- "msbm10",
- "-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*" },
-
- { LyXFont::EUFRAK_FAMILY,
- "eufm10",
- "-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*" },
-
- { LyXFont::WASY_FAMILY,
- "wasy10",
- "-*-wasy10-medium-*-*-*-*-*-*-*-*-*-*-*" }
-};
-
-size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_font);
-
-
-string getRawName(string const & family)
-{
- for (size_t i = 0; i < nr_symbol_fonts; ++i)
- if (family == symbol_fonts[i].family)
- return symbol_fonts[i].xlfd;
-
- lyxerr[Debug::FONT] << "BUG: family not found !" << endl;
- return string();
-}
-
-
-string const symbolFamily(LyXFont::FONT_FAMILY family)
-{
- for (size_t i = 0; i < nr_symbol_fonts; ++i) {
- if (family == symbol_fonts[i].lyx_family)
- return symbol_fonts[i].family;
- }
- return string();
-}
-
-
-bool isSymbolFamily(LyXFont::FONT_FAMILY family)
-{
- return family >= LyXFont::SYMBOL_FAMILY &&
- family <= LyXFont::WASY_FAMILY;
-}
-
-
-bool isChosenFont(QFont & font, string const & family)
-{
- lyxerr[Debug::FONT] << "raw: " << fromqstr(font.rawName()) << endl;
-
- QFontInfo fi(font);
-
- // Note Qt lies about family quite often
- lyxerr[Debug::FONT] << "alleged fi family: "
- << fromqstr(fi.family()) << endl;
-
- // So we check rawName first
- if (contains(fromqstr(font.rawName()), family)) {
- lyxerr[Debug::FONT] << " got it ";
- return true;
- }
-
- // Qt 3.2 beta1 returns "xft" for all xft fonts
- // Qt 4.1 returns "Multi" for all ? xft fonts
- if (font.rawName() == "xft" || font.rawName() == "Multi") {
- if (contains(fromqstr(fi.family()), family)) {
- lyxerr[Debug::FONT] << " got it (Xft) ";
- return true;
- }
- }
-
- return false;
-}
-
-
-pair<QFont, bool> const getSymbolFont(string const & family)
-{
- lyxerr[Debug::FONT] << "Looking for font family "
- << family << " ... ";
- string upper = family;
- upper[0] = toupper(family[0]);
-
- QFont font;
- font.setFamily(toqstr(family));
-
- if (isChosenFont(font, family)) {
- lyxerr[Debug::FONT] << "normal!" << endl;
- return make_pair<QFont, bool>(font, true);
- }
-
- font.setFamily(toqstr(upper));
-
- if (isChosenFont(font, upper)) {
- lyxerr[Debug::FONT] << "upper!" << endl;
- return make_pair<QFont, bool>(font, true);
- }
-
- // A simple setFamily() fails on Qt 2
-
- font.setRawName(toqstr(getRawName(family)));
-
- if (isChosenFont(font, family)) {
- lyxerr[Debug::FONT] << "raw version!" << endl;
- return make_pair<QFont, bool>(font, true);
- }
-
- lyxerr[Debug::FONT] << " FAILED :-(" << endl;
- return make_pair<QFont, bool>(font, false);
-}
-
-} // namespace anon
-
-
-FontLoader::FontLoader()
-{
- for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
- for (int i2 = 0; i2 < 2; ++i2)
- for (int i3 = 0; i3 < 4; ++i3)
- for (int i4 = 0; i4 < 10; ++i4)
- fontinfo_[i1][i2][i3][i4] = 0;
-}
-
-
-void FontLoader::update()
-{
- for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
- for (int i2 = 0; i2 < 2; ++i2)
- for (int i3 = 0; i3 < 4; ++i3)
- for (int i4 = 0; i4 < 10; ++i4) {
- delete fontinfo_[i1][i2][i3][i4];
- fontinfo_[i1][i2][i3][i4] = 0;
- }
-}
-
-
-/////////////////////////////////////////////////
-
-
-QLFontInfo::QLFontInfo(LyXFont const & f)
- : metrics(font)
-{
-
- string const pat = symbolFamily(f.family());
- if (!pat.empty()) {
- bool tmp;
- boost::tie(font, tmp) = getSymbolFont(pat);
- } else {
- switch (f.family()) {
- case LyXFont::ROMAN_FAMILY:
-
font.setFamily(toqstr(makeFontName(lyxrc.roman_font_name,
- lyxrc.roman_font_foundry)));
- break;
- case LyXFont::SANS_FAMILY:
- font.setFamily(toqstr(makeFontName(lyxrc.sans_font_name,
- lyxrc.sans_font_foundry)));
- break;
- case LyXFont::TYPEWRITER_FAMILY:
-
font.setFamily(toqstr(makeFontName(lyxrc.typewriter_font_name,
-
lyxrc.typewriter_font_foundry)));
- break;
- default:
- break;
- }
- }
-
- font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
- * lyxrc.zoom / 100.0);
-
- switch (f.series()) {
- case LyXFont::MEDIUM_SERIES:
- font.setWeight(QFont::Normal);
- break;
- case LyXFont::BOLD_SERIES:
- font.setWeight(QFont::Bold);
- break;
- default:
- break;
- }
-
- switch (f.realShape()) {
- case LyXFont::ITALIC_SHAPE:
- case LyXFont::SLANTED_SHAPE:
- font.setItalic(true);
- break;
- default:
- break;
- }
-
- if (lyxerr.debugging(Debug::FONT)) {
- lyxerr[Debug::FONT] << "Font '" << f.stateText(0)
- << "' 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;
- else
- lyxerr[Debug::FONT] << "This font is NOT an exact match"
- << endl;
-
- lyxerr[Debug::FONT] << "XFLD: " << fromqstr(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
-}
-
-
-bool FontLoader::available(LyXFont const & f)
-{
- if (!lyx_gui::use_gui)
- return false;
-
- static vector<int> cache_set(LyXFont::NUM_FAMILIES, false);
- static vector<int> cache(LyXFont::NUM_FAMILIES, false);
-
- LyXFont::FONT_FAMILY family = f.family();
- if (cache_set[family])
- return cache[family];
- cache_set[family] = true;
-
- string const pat = symbolFamily(family);
- if (pat.empty())
- // We don't care about non-symbol fonts
- return false;
-
- pair<QFont, bool> tmp = getSymbolFont(pat);
- if (!tmp.second)
- return false;
-
- cache[family] = true;
- return true;
-}
Index: src/frontends/qt4/FontLoader.h
===================================================================
--- src/frontends/qt4/FontLoader.h (revision 15217)
+++ src/frontends/qt4/FontLoader.h (working copy)
@@ -1,97 +0,0 @@
-// -*- C++ -*-
-/**
- * \file FontLoader.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef QFONTLOADER_H
-#define QFONTLOADER_H
-
-#include "encoding.h"
-#include "lyxfont.h"
-
-#include <QFont>
-#include <QFontMetrics>
-
-//#if QT_VERSION < 0x030100
-#define USE_LYX_FONTCACHE
-//#endif
-
-#if defined(USE_LYX_FONTCACHE)
-#include <map>
-#endif
-
-/**
- * Qt font loader for LyX. Matches LyXFonts against
- * actual QFont instances, and also caches metrics.
- */
-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
-};
-
-
-/// Hold info about a particular font
-class FontLoader {
-public:
- ///
- FontLoader();
-
- /// Destructor
- ~FontLoader();
-
- /// Update fonts after zoom, dpi, font names, or norm change
- void update();
-
- /// Do we have anything matching?
- bool available(LyXFont const & f);
-
- /// 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;
- }
-
- /// Called the first time when available() can't load a symbol font
- static void addToFontPath();
-
- /// Get font info (font + metrics) for the given LyX font.
- QLFontInfo & fontinfo(LyXFont const & f) {
- // fi is a reference to the pointer type (QLFontInfo *) in the
- // fontinfo_ table.
- QLFontInfo * & fi =
-
fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
- if (!fi)
- fi = new QLFontInfo(f);
- return *fi;
- }
-
-private:
- /// BUTT ugly !
- QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
-};
-
-#endif // QFONT_LOADER_H
Index: src/frontends/qt4/GuiApplication.h
===================================================================
--- src/frontends/qt4/GuiApplication.h (revision 15217)
+++ src/frontends/qt4/GuiApplication.h (working copy)
@@ -14,7 +14,7 @@
#define QT4_APPLICATION_H
#include "ColorCache.h"
-#include "FontLoader.h"
+#include "GuiFontLoader.h"
#include "GuiClipboard.h"
#include "GuiImplementation.h"
#include "GuiSelection.h"
@@ -57,6 +57,7 @@
//@{
virtual Clipboard& clipboard();
virtual Selection& selection();
+ virtual FontLoader & fontLoader() { return font_loader_; }
virtual int const exec();
virtual Gui & gui() { return gui_; }
virtual void exit(int status);
@@ -68,7 +69,8 @@
///
ColorCache & colorCache() { return color_cache_; }
///
- FontLoader & fontLoader() { return font_loader_; }
+ ///
+ GuiFontLoader & guiFontLoader() { return font_loader_; }
private:
///
@@ -78,7 +80,7 @@
///
GuiSelection selection_;
///
- FontLoader font_loader_;
+ GuiFontLoader font_loader_;
///
ColorCache color_cache_;
Index: src/frontends/qt4/GuiFontLoader.C
===================================================================
--- src/frontends/qt4/GuiFontLoader.C (revision 15206)
+++ src/frontends/qt4/GuiFontLoader.C (working copy)
@@ -1,5 +1,5 @@
/**
- * \file FontLoader.C
+ * \file GuiFontLoader.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@@ -11,7 +11,7 @@
#include <config.h>
-#include "FontLoader.h"
+#include "GuiFontLoader.h"
#include "qt_helpers.h"
#include "debug.h"
@@ -44,7 +44,10 @@
using std::string;
-FontLoader::~FontLoader() {
+namespace lyx {
+namespace frontend {
+
+GuiFontLoader::~GuiFontLoader() {
}
namespace {
@@ -191,7 +194,7 @@
} // namespace anon
-FontLoader::FontLoader()
+GuiFontLoader::GuiFontLoader()
{
for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
for (int i2 = 0; i2 < 2; ++i2)
@@ -201,7 +204,7 @@
}
-void FontLoader::update()
+void GuiFontLoader::update()
{
for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
for (int i2 = 0; i2 < 2; ++i2)
@@ -305,7 +308,7 @@
}
-bool FontLoader::available(LyXFont const & f)
+bool GuiFontLoader::available(LyXFont const & f)
{
if (!lyx_gui::use_gui)
return false;
@@ -330,3 +333,6 @@
cache[family] = true;
return true;
}
+
+} // namespace frontend
+} // namespace lyx
Index: src/frontends/qt4/GuiFontLoader.h
===================================================================
--- src/frontends/qt4/GuiFontLoader.h (revision 15206)
+++ src/frontends/qt4/GuiFontLoader.h (working copy)
@@ -1,6 +1,6 @@
// -*- C++ -*-
/**
- * \file FontLoader.h
+ * \file GuiFontLoader.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@@ -9,9 +9,11 @@
* Full author contact details are available in file CREDITS.
*/
-#ifndef QFONTLOADER_H
-#define QFONTLOADER_H
+#ifndef QT4_FONTLOADER_H
+#define QT4_FONTLOADER_H
+#include "frontends/FontLoader.h"
+
#include "encoding.h"
#include "lyxfont.h"
@@ -26,6 +28,9 @@
#include <map>
#endif
+namespace lyx {
+namespace frontend {
+
/**
* Qt font loader for LyX. Matches LyXFonts against
* actual QFont instances, and also caches metrics.
@@ -51,19 +56,20 @@
/// Hold info about a particular font
-class FontLoader {
+class GuiFontLoader: public FontLoader
+{
public:
///
- FontLoader();
+ GuiFontLoader();
/// Destructor
- ~FontLoader();
+ virtual ~GuiFontLoader();
/// Update fonts after zoom, dpi, font names, or norm change
- void update();
+ virtual void update();
/// Do we have anything matching?
- bool available(LyXFont const & f);
+ virtual bool available(LyXFont const & f);
/// Get the QFont for this LyXFont
QFont const & get(LyXFont const & f) {
@@ -75,9 +81,6 @@
return fontinfo(f).metrics;
}
- /// Called the first time when available() can't load a symbol font
- static void addToFontPath();
-
/// Get font info (font + metrics) for the given LyX font.
QLFontInfo & fontinfo(LyXFont const & f) {
// fi is a reference to the pointer type (QLFontInfo *) in the
@@ -94,4 +97,8 @@
QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
};
-#endif // QFONT_LOADER_H
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // QT4_FONTLOADER_H
Index: src/frontends/qt4/lyx_gui.C
===================================================================
--- src/frontends/qt4/lyx_gui.C (revision 15217)
+++ src/frontends/qt4/lyx_gui.C (working copy)
@@ -140,18 +140,6 @@
}
-void update_fonts()
-{
- guiApp->fontLoader().update();
-}
-
-
-bool font_available(LyXFont const & font)
-{
- return guiApp->fontLoader().available(font);
-}
-
-
void register_socket_callback(int fd, boost::function<void()> func)
{
socket_callbacks[fd] = shared_ptr<socket_callback>(new
socket_callback(fd, func));
Index: src/frontends/qt4/Makefile.am
===================================================================
--- src/frontends/qt4/Makefile.am (revision 15217)
+++ src/frontends/qt4/Makefile.am (working copy)
@@ -34,9 +34,9 @@
ColorCache.h ColorCache.C \
Dialogs.C \
FileDialog.C \
- FontLoader.h FontLoader.C \
GuiApplication.C GuiApplication.h \
GuiClipboard.h GuiClipboard.C \
+ GuiFontLoader.h GuiFontLoader.C \
GuiSelection.h GuiSelection.C \
GuiImplementation.h GuiImplementation.C \
LyXKeySymFactory.C \
Index: src/frontends/qt4/qfont_metrics.C
===================================================================
--- src/frontends/qt4/qfont_metrics.C (revision 15217)
+++ src/frontends/qt4/qfont_metrics.C (working copy)
@@ -39,8 +39,8 @@
LyXFont smallfont = f;
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
- QFontMetrics const & qm = guiApp->fontLoader().metrics(f);
- QFontMetrics const & qsmallm = guiApp->fontLoader().metrics(smallfont);
+ QFontMetrics const & qm = guiApp->guiFontLoader().metrics(f);
+ QFontMetrics const & qsmallm =
guiApp->guiFontLoader().metrics(smallfont);
int w = 0;
@@ -65,7 +65,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- return guiApp->fontLoader().metrics(f).ascent();
+ return guiApp->guiFontLoader().metrics(f).ascent();
}
@@ -75,7 +75,7 @@
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->fontLoader().metrics(f).descent() + 1;
+ return guiApp->guiFontLoader().metrics(f).descent() + 1;
}
@@ -83,7 +83,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QRect const & r =
guiApp->fontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
+ 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)
@@ -99,7 +99,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QRect const & r =
guiApp->fontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
+ 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)
@@ -115,7 +115,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- return guiApp->fontLoader().metrics(f).leftBearing(ucs4_to_qchar(c));
+ return guiApp->guiFontLoader().metrics(f).leftBearing(ucs4_to_qchar(c));
}
@@ -123,7 +123,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QFontMetrics const & m = guiApp->fontLoader().metrics(f);
+ 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);
@@ -141,7 +141,7 @@
if (f.realShape() == LyXFont::SMALLCAPS_SHAPE)
return smallcapswidth(ucs2, f);
- QLFontInfo & fi = guiApp->fontLoader().fontinfo(f);
+ lyx::frontend::QLFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
if (ls == 1)
return fi.width(ucs2[0].unicode());
@@ -166,7 +166,7 @@
void font_metrics::rectText(docstring const & str, LyXFont const & f,
int & w, int & ascent, int & descent)
{
- QFontMetrics const & m = guiApp->fontLoader().metrics(f);
+ QFontMetrics const & m = guiApp->guiFontLoader().metrics(f);
static int const d = 2;
w = width(str, f) + d * 2 + 2;
ascent = m.ascent() + d;
@@ -178,7 +178,7 @@
void font_metrics::buttonText(docstring const & str, LyXFont const & f,
int & w, int & ascent, int & descent)
{
- QFontMetrics const & m = guiApp->fontLoader().metrics(f);
+ QFontMetrics const & m = guiApp->guiFontLoader().metrics(f);
static int const d = 3;
w = width(str, f) + d * 2 + 2;
ascent = m.ascent() + d;
Index: src/frontends/qt4/QLPainter.C
===================================================================
--- src/frontends/qt4/QLPainter.C (revision 15217)
+++ src/frontends/qt4/QLPainter.C (working copy)
@@ -202,8 +202,8 @@
LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
- QFont const & qfont = guiApp->fontLoader().get(f);
- QFont const & qsmallfont = guiApp->fontLoader().get(smallfont);
+ QFont const & qfont = guiApp->guiFontLoader().get(f);
+ QFont const & qsmallfont = guiApp->guiFontLoader().get(smallfont);
QFontMetrics const & qfontm = QFontMetrics(qfont);
QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
@@ -252,7 +252,7 @@
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
setQPainterPen(f.realColor());
- qp_->setFont(guiApp->fontLoader().get(f));
+ qp_->setFont(guiApp->guiFontLoader().get(f));
// We need to draw the text as LTR as we use our own bidi code.
qp_->setLayoutDirection(Qt::LeftToRight);
qp_->drawText(x, y, str);
Index: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C (revision 15217)
+++ src/lyxfunc.C (working copy)
@@ -76,6 +76,7 @@
#include "frontends/Alert.h"
#include "frontends/Dialogs.h"
#include "frontends/FileDialog.h"
+#include "frontends/FontLoader.h"
#include "frontends/lyx_gui.h"
#include "frontends/LyXKeySym.h"
#include "frontends/LyXView.h"
@@ -1352,7 +1353,7 @@
case LFUN_SCREEN_FONT_UPDATE:
// handle the screen font changes.
lyxrc.set_font_norm_type();
- lyx_gui::update_fonts();
+ theApp->fontLoader().update();
// All visible buffers will need resize
view()->resize();
break;
Index: src/mathed/MathFactory.C
===================================================================
--- src/mathed/MathFactory.C (revision 15217)
+++ src/mathed/MathFactory.C (working copy)
@@ -60,7 +60,8 @@
#include "support/filetools.h" // LibFileSearch
#include "support/lstrings.h"
-#include "frontends/lyx_gui.h"
+#include "frontends/Application.h"
+#include "frontends/FontLoader.h"
#include <fstream>
#include <sstream>
@@ -88,7 +89,7 @@
augmentFont(f, name);
// Do we have the font proper?
- if (lyx_gui::font_available(f))
+ if (theApp->fontLoader().available(f))
return true;
// can we fake it?
Index: src/mathed/MathSupport.C
===================================================================
--- src/mathed/MathSupport.C (revision 15217)
+++ src/mathed/MathSupport.C (working copy)
@@ -20,9 +20,10 @@
#include "debug.h"
#include "LColor.h"
+#include "frontends/Application.h"
#include "frontends/Painter.h"
#include "frontends/font_metrics.h"
-#include "frontends/lyx_gui.h"
+#include "frontends/FontLoader.h"
#include <map>
#include <sstream>
@@ -670,9 +671,9 @@
if (!initialized) {
initialized = true;
// fake fonts if necessary
- if (!lyx_gui::font_available(getFont("mathfrak")))
+ if (!theApp->fontLoader().available(getFont("mathfrak")))
fakeFont("mathfrak", "lyxfakefrak");
- if (!lyx_gui::font_available(getFont("mathcal")))
+ if (!theApp->fontLoader().available(getFont("mathcal")))
fakeFont("mathcal", "lyxfakecal");
}
fontinfo * info = searchFont(name);