and the patch...
Index: development/scons/scons_manifest.py =================================================================== --- development/scons/scons_manifest.py (revision 15182) +++ development/scons/scons_manifest.py (working copy) @@ -101,6 +101,7 @@ filefilterlist.h filename.h filetools.h + fontutils.h forkedcall.h forkedcallqueue.h forkedcontr.h @@ -138,6 +139,7 @@ filefilterlist.C filename.C filetools.C + fontutils.C forkedcall.C forkedcallqueue.C forkedcontr.C Index: src/frontends/qt3/lyx_gui.C =================================================================== --- src/frontends/qt3/lyx_gui.C (revision 15187) +++ src/frontends/qt3/lyx_gui.C (working copy) @@ -95,9 +95,6 @@ int exec(int & argc, char * argv[]) { - // Force adding of font path _before_ QApplication is initialized - FontLoader::initFontPath(); - GuiApplication app(argc, argv); guiApp = &app; Index: src/frontends/qt3/qfont_loader.C =================================================================== --- src/frontends/qt3/qfont_loader.C (revision 15187) +++ src/frontends/qt3/qfont_loader.C (working copy) @@ -46,77 +46,8 @@ using std::vector; using std::string; -#ifdef Q_WS_MACX -#include <ApplicationServices/ApplicationServices.h> -#endif -#ifdef Q_WS_WIN -#include "windows.h" -#include "support/os.h" -#include "support/package.h" -#include "support/path.h" -using lyx::support::addName; -using lyx::support::addPath; -using lyx::support::package; -namespace os = lyx::support::os; -string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10", - "eufm10", "msam10", "msbm10", "wasy10"}; -const int num_fonts_truetype = sizeof(win_fonts_truetype) / sizeof(*win_fonts_truetype); -#endif - -void FontLoader::initFontPath() -{ -#ifdef Q_WS_MACX - CFBundleRef myAppBundle = CFBundleGetMainBundle(); - CFURLRef myAppResourcesURL, FontsURL; - FSRef fontDirRef; - FSSpec fontDirSpec; - CFStringRef filePath = CFStringCreateWithBytes(kCFAllocatorDefault, - (UInt8 *) "Fonts", strlen("Fonts"), - kCFStringEncodingISOLatin1, false); - - myAppResourcesURL = CFBundleCopyResourcesDirectoryURL(myAppBundle); - FontsURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, - myAppResourcesURL, filePath, true); - if (lyxerr.debugging(Debug::FONT)) { - UInt8 buf[255]; - if (CFURLGetFileSystemRepresentation(FontsURL, true, buf, 255)) - lyxerr << "Adding Fonts directory: " << buf << endl; - } - CFURLGetFSRef (FontsURL, &fontDirRef); - OSStatus err = FSGetCatalogInfo (&fontDirRef, kFSCatInfoNone, - NULL, NULL, &fontDirSpec, NULL); - if (err) - lyxerr << "FSGetCatalogInfo err = " << err << endl; - err = FMActivateFonts (&fontDirSpec, NULL, NULL, - kFMLocalActivationContext); - if (err) - lyxerr << "FMActivateFonts err = " << err << endl; -#endif - -#ifdef Q_WS_WIN - // Windows only: Add BaKoMa TrueType font resources - string const fonts_dir = addPath(package().system_support(), "fonts"); - - for (int i = 0 ; i < num_fonts_truetype ; ++i) { - string const font_current = - addName(fonts_dir, win_fonts_truetype[i] + ".ttf"); - AddFontResource(os::external_path(font_current).c_str()); - } -#endif -} - FontLoader::~FontLoader() { -#ifdef Q_WS_WIN - // Windows only: Remove BaKoMa TrueType font resources - string const fonts_dir = addPath(package().system_support(), "fonts"); - - for(int i = 0 ; i < num_fonts_truetype ; ++i) { - string const font_current = - addName(fonts_dir, win_fonts_truetype[i] + ".ttf"); - RemoveFontResource(os::external_path(font_current).c_str()); - } -#endif } namespace { Index: src/frontends/qt3/qfont_loader.h =================================================================== --- src/frontends/qt3/qfont_loader.h (revision 15187) +++ src/frontends/qt3/qfont_loader.h (working copy) @@ -75,9 +75,6 @@ return fontinfo(f).metrics; } - /// Called before QApplication is initialized - static void initFontPath(); - /// Called the first time when available() can't load a symbol font static void addToFontPath(); Index: src/frontends/qt4/FontLoader.C =================================================================== --- src/frontends/qt4/FontLoader.C (revision 15180) +++ src/frontends/qt4/FontLoader.C (working copy) @@ -43,77 +43,8 @@ using std::vector; using std::string; -#ifdef Q_WS_MACX -#include <ApplicationServices/ApplicationServices.h> -#endif -#ifdef Q_WS_WIN -#include "windows.h" -#include "support/os.h" -#include "support/package.h" -#include "support/path.h" -using lyx::support::addName; -using lyx::support::addPath; -using lyx::support::package; -namespace os = lyx::support::os; -string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10", - "eufm10", "msam10", "msbm10", "wasy10"}; -const int num_fonts_truetype = sizeof(win_fonts_truetype) / sizeof(*win_fonts_truetype); -#endif - -void FontLoader::initFontPath() -{ -#ifdef Q_WS_MACX - CFBundleRef myAppBundle = CFBundleGetMainBundle(); - CFURLRef myAppResourcesURL, FontsURL; - FSRef fontDirRef; - FSSpec fontDirSpec; - CFStringRef filePath = CFStringCreateWithBytes(kCFAllocatorDefault, - (UInt8 *) "Fonts", strlen("Fonts"), - kCFStringEncodingISOLatin1, false); - - myAppResourcesURL = CFBundleCopyResourcesDirectoryURL(myAppBundle); - FontsURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, - myAppResourcesURL, filePath, true); - if (lyxerr.debugging(Debug::FONT)) { - UInt8 buf[255]; - if (CFURLGetFileSystemRepresentation(FontsURL, true, buf, 255)) - lyxerr << "Adding Fonts directory: " << buf << endl; - } - CFURLGetFSRef (FontsURL, &fontDirRef); - OSStatus err = FSGetCatalogInfo (&fontDirRef, kFSCatInfoNone, - NULL, NULL, &fontDirSpec, NULL); - if (err) - lyxerr << "FSGetCatalogInfo err = " << err << endl; - err = FMActivateFonts (&fontDirSpec, NULL, NULL, - kFMLocalActivationContext); - if (err) - lyxerr << "FMActivateFonts err = " << err << endl; -#endif - -#ifdef Q_WS_WIN - // Windows only: Add BaKoMa TrueType font resources - string const fonts_dir = addPath(package().system_support(), "fonts"); - - for (int i = 0 ; i < num_fonts_truetype ; ++i) { - string const font_current = - addName(fonts_dir, win_fonts_truetype[i] + ".ttf"); - AddFontResource(os::external_path(font_current).c_str()); - } -#endif -} - FontLoader::~FontLoader() { -#ifdef Q_WS_WIN - // Windows only: Remove BaKoMa TrueType font resources - string const fonts_dir = addPath(package().system_support(), "fonts"); - - for(int i = 0 ; i < num_fonts_truetype ; ++i) { - string const font_current = - addName(fonts_dir, win_fonts_truetype[i] + ".ttf"); - RemoveFontResource(os::external_path(font_current).c_str()); - } -#endif } namespace { Index: src/frontends/qt4/FontLoader.h =================================================================== --- src/frontends/qt4/FontLoader.h (revision 15180) +++ src/frontends/qt4/FontLoader.h (working copy) @@ -75,9 +75,6 @@ return fontinfo(f).metrics; } - /// Called before QApplication is initialized - static void initFontPath(); - /// Called the first time when available() can't load a symbol font static void addToFontPath(); Index: src/frontends/qt4/lyx_gui.C =================================================================== --- src/frontends/qt4/lyx_gui.C (revision 15180) +++ src/frontends/qt4/lyx_gui.C (working copy) @@ -28,7 +28,6 @@ #include "GuiView.h" -#include "FontLoader.h" #include "QLImage.h" #include "qt_helpers.h" #include "socket_callback.h" @@ -98,9 +97,6 @@ Clipboard and Selection access. */ - // Force adding of font path _before_ QApplication is initialized - FontLoader::initFontPath(); - #if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN) static GuiApplication app(argc, argv); #else Index: src/lyx_cb.C =================================================================== --- src/lyx_cb.C (revision 15182) +++ src/lyx_cb.C (working copy) @@ -38,6 +38,7 @@ #include "support/filefilterlist.h" #include "support/filetools.h" +#include "support/fontutils.h" #include "support/forkedcall.h" #include "support/fs_extras.h" #include "support/lyxlib.h" @@ -216,6 +217,8 @@ } lyx_gui::exit(0); + // Restore original font ressources after Application is destroyed. + lyx::support::restoreFontRessources(); } Index: src/lyx_main.C =================================================================== --- src/lyx_main.C (revision 15183) +++ src/lyx_main.C (working copy) @@ -47,6 +47,7 @@ #include "support/environment.h" #include "support/filetools.h" +#include "support/fontutils.h" #include "support/lyxlib.h" #include "support/convert.h" #include "support/os.h" @@ -107,9 +108,13 @@ // FIXME: We should not directly call exit(), since it only // guarantees a return to the system, no application cleanup. // This may cause troubles with not executed destructors. - if (lyx_gui::use_gui) + if (lyx_gui::use_gui) { // lyx_gui::exit may return and only schedule the exit lyx_gui::exit(status); + // Restore original font ressources after Application is destroyed. + lyx::support::restoreFontRessources(); + } + exit(status); } @@ -216,8 +221,11 @@ lyx::support::top_build_dir_is_one_level_up); // Start the real execution loop. - if (lyx_gui::use_gui) + if (lyx_gui::use_gui) { + // Force adding of font path _before_ Application is initialized + lyx::support::addFontRessources(); return lyx_gui::exec(argc, argv); + } else return exec2(argc, argv); } Index: src/support/fontutils.C =================================================================== --- src/support/fontutils.C (revision 0) +++ src/support/fontutils.C (revision 0) @@ -0,0 +1,97 @@ +/** + * \file fontutils.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. + * + * General font utilities. + */ + +#include <config.h> + +#include "fontutils.h" + +#ifdef Q_WS_MACX +#include <ApplicationServices/ApplicationServices.h> +#endif + +#ifdef Q_WS_WIN +#include "windows.h" +#include "support/os.h" +#include "support/package.h" +#include "support/path.h" +using lyx::support::addName; +using lyx::support::addPath; +using lyx::support::package; +namespace os = lyx::support::os; +string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10", + "eufm10", "msam10", "msbm10", "wasy10"}; +const int num_fonts_truetype = sizeof(win_fonts_truetype) / sizeof(*win_fonts_truetype); +#endif + +namespace lyx { +namespace support { + +void addFontRessources() +{ +#ifdef Q_WS_MACX + CFBundleRef myAppBundle = CFBundleGetMainBundle(); + CFURLRef myAppResourcesURL, FontsURL; + FSRef fontDirRef; + FSSpec fontDirSpec; + CFStringRef filePath = CFStringCreateWithBytes(kCFAllocatorDefault, + (UInt8 *) "Fonts", strlen("Fonts"), + kCFStringEncodingISOLatin1, false); + + myAppResourcesURL = CFBundleCopyResourcesDirectoryURL(myAppBundle); + FontsURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, + myAppResourcesURL, filePath, true); + if (lyxerr.debugging(Debug::FONT)) { + UInt8 buf[255]; + if (CFURLGetFileSystemRepresentation(FontsURL, true, buf, 255)) + lyxerr << "Adding Fonts directory: " << buf << endl; + } + CFURLGetFSRef (FontsURL, &fontDirRef); + OSStatus err = FSGetCatalogInfo (&fontDirRef, kFSCatInfoNone, + NULL, NULL, &fontDirSpec, NULL); + if (err) + lyxerr << "FSGetCatalogInfo err = " << err << endl; + err = FMActivateFonts (&fontDirSpec, NULL, NULL, + kFMLocalActivationContext); + if (err) + lyxerr << "FMActivateFonts err = " << err << endl; +#endif + +#ifdef Q_WS_WIN + // Windows only: Add BaKoMa TrueType font resources + string const fonts_dir = addPath(package().system_support(), "fonts"); + + for (int i = 0 ; i < num_fonts_truetype ; ++i) { + string const font_current = + addName(fonts_dir, win_fonts_truetype[i] + ".ttf"); + AddFontResource(os::external_path(font_current).c_str()); + } +#endif +} + + +void restoreFontRessources() +{ +#ifdef Q_WS_WIN + // Windows only: Remove BaKoMa TrueType font resources + string const fonts_dir = addPath(package().system_support(), "fonts"); + + for(int i = 0 ; i < num_fonts_truetype ; ++i) { + string const font_current = + addName(fonts_dir, win_fonts_truetype[i] + ".ttf"); + RemoveFontResource(os::external_path(font_current).c_str()); + } +#endif +} + +} //namespace support +} // namespace lyx
Property changes on: src\support\fontutils.C ___________________________________________________________________ Name: svn:eol-style + native Index: src/support/fontutils.h =================================================================== --- src/support/fontutils.h (revision 0) +++ src/support/fontutils.h (revision 0) @@ -0,0 +1,29 @@ +// -*- C++ -*- +/** + * \file fontutils.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. + * + * General font utilities. + */ + +#ifndef LYX_FONTUTILS_H +#define LYX_FONTUTILS_H + +namespace lyx { +namespace support { + +/// Add fonts to the font subsystem, must be called before Application is initialized. +void addFontRessources(); + +/// Restore original font ressources, must be called after Application is destroyed. +void restoreFontRessources(); + +} // namespace support +} // namespace lyx + +#endif Property changes on: src\support\fontutils.h ___________________________________________________________________ Name: svn:eol-style + native Index: src/support/Makefile.am =================================================================== --- src/support/Makefile.am (revision 15180) +++ src/support/Makefile.am (working copy) @@ -37,6 +37,8 @@ filename.h \ filetools.C \ filetools.h \ + fontutils.C \ + fontutils.h \ forkedcall.C \ forkedcall.h \ forkedcallqueue.C \