On Wed, Jul 04, 2007 at 04:31:55PM +0200, Jean-Marc Lasgouttes wrote:

> With Qt4.2, we can also use QFontDatabase::addApplicationFont
> http://doc.trolltech.com/4.2/qfontdatabase.html#addApplicationFont

I tried this option (see attached patch). It works on Win2k and solves
the problem of having fonts with the same name as the bakoma ones in
the system font directory, but fails on Vista, where addApplicationFont
always returns -1.

However, pointing addApplicationFont to the the fonts of the installed
LyX 1.4.4, it succeeds. So, this seems to be the same bug afflicting
AddFontResource. Having spent some (too much) time on this problem,
I think I can say there is no way to solve it on Vista, the only
workaround being installing the bakoma fonts in the Windows font
directory.

-- 
Enrico
Index: src/frontends/qt4/GuiFontLoader.cpp
===================================================================
--- src/frontends/qt4/GuiFontLoader.cpp (revision 18990)
+++ src/frontends/qt4/GuiFontLoader.cpp (working copy)
@@ -21,8 +21,11 @@
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/Systemcall.h"
+#include "support/Package.h"
+#include "support/os.h"
 
 #include <qfontinfo.h>
+#include <QFontDatabase>
 
 #include <boost/tuple/tuple.hpp>
 
@@ -33,6 +36,9 @@
 #endif
 
 using lyx::support::contains;
+using lyx::support::package;
+using lyx::support::addPath;
+using lyx::support::addName;
 
 using std::endl;
 using std::make_pair;
@@ -41,6 +47,12 @@ using std::pair;
 using std::vector;
 using std::string;
 
+#if defined(Q_WS_WIN) && QT_VERSION >= 0x040200
+string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
+       "eufm10", "msam10", "msbm10", "wasy10", "esint10"};
+const int num_fonts_truetype = sizeof(win_fonts_truetype) / 
sizeof(*win_fonts_truetype);
+#endif
+
 
 namespace lyx {
 namespace frontend {
@@ -189,6 +201,19 @@ pair<QFont, bool> const getSymbolFont(st
 
 GuiFontLoader::GuiFontLoader()
 {
+#if defined(Q_WS_WIN) && QT_VERSION >= 0x040200
+       string const fonts_dir = 
addPath(package().system_support().absFilename(), "fonts");
+
+       for (int i = 0 ; i < num_fonts_truetype ; ++i) {
+               string const font_file = lyx::support::os::external_path(
+                       addName(fonts_dir, win_fonts_truetype[i] + ".ttf"));
+               fontID[i] = 
QFontDatabase::addApplicationFont(toqstr(font_file));
+               LYXERR(Debug::FONT) << "Adding font " << font_file
+                                   << static_cast<const char *>
+                                       (fontID[i] < 0 ? " FAIL" : " OK")
+                                   << endl;
+       }
+#endif
        for (int i1 = 0; i1 < Font::NUM_FAMILIES; ++i1)
                for (int i2 = 0; i2 < 2; ++i2)
                        for (int i3 = 0; i3 < 4; ++i3)
@@ -197,6 +222,17 @@ GuiFontLoader::GuiFontLoader()
 }
 
 
+GuiFontLoader::~GuiFontLoader()
+{
+#if defined(Q_WS_WIN) && QT_VERSION >= 0x040200
+       for (int i = 0 ; i < num_fonts_truetype ; ++i) {
+               if (fontID[i] >= 0)
+                       QFontDatabase::removeApplicationFont(fontID[i]);
+       }
+#endif
+}
+
+
 void GuiFontLoader::update()
 {
        for (int i1 = 0; i1 < Font::NUM_FAMILIES; ++i1)
Index: src/frontends/qt4/GuiFontLoader.h
===================================================================
--- src/frontends/qt4/GuiFontLoader.h   (revision 18990)
+++ src/frontends/qt4/GuiFontLoader.h   (working copy)
@@ -47,7 +47,7 @@ public:
        GuiFontLoader();
 
        /// Destructor
-       virtual ~GuiFontLoader() {}
+       ~GuiFontLoader();
 
        virtual void update();
        virtual bool available(Font const & f);
@@ -75,6 +75,8 @@ public:
 private:
        /// BUTT ugly !
        QLFontInfo * fontinfo_[Font::NUM_FAMILIES][2][4][10];
+
+       int fontID[10];
 };
 
 

Reply via email to