]> git.lyx.org Git - lyx.git/commitdiff
This commit moves system font initialization and restoration to new support/fontutils...
authorAbdelrazak Younes <younes@lyx.org>
Mon, 2 Oct 2006 10:48:03 +0000 (10:48 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 2 Oct 2006 10:48:03 +0000 (10:48 +0000)
These font related functions were identical for qt3 and qt4. They are not Qt dependent at all and could also apply to an eventual Win32 or MacOSX gtk port.

Jen-Marc says: It would be nice to convince fontconfig to do the same for linux.

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

12 files changed:
development/scons/scons_manifest.py
src/frontends/qt3/lyx_gui.C
src/frontends/qt3/qfont_loader.C
src/frontends/qt3/qfont_loader.h
src/frontends/qt4/FontLoader.C
src/frontends/qt4/FontLoader.h
src/frontends/qt4/lyx_gui.C
src/lyx_cb.C
src/lyx_main.C
src/support/Makefile.am
src/support/fontutils.C [new file with mode: 0644]
src/support/fontutils.h [new file with mode: 0644]

index 4dd46ba802127ffc52dda6221c3a9d77cdbfc168..9289f6741d311afa5d61a217866da103dab337f2 100644 (file)
@@ -101,6 +101,7 @@ src_support_header_files = Split('''
     filefilterlist.h
     filename.h
     filetools.h
+    fontutils.h
     forkedcall.h
     forkedcallqueue.h
     forkedcontr.h
@@ -138,6 +139,7 @@ src_support_files = Split('''
     filefilterlist.C
     filename.C
     filetools.C
+    fontutils.C
     forkedcall.C
     forkedcallqueue.C
     forkedcontr.C
index 812129397ae81ae7b140257b28311b976af5b139..4be85e78e36777a600f8dbd4124dc7444ba6e0aa 100644 (file)
@@ -95,9 +95,6 @@ bool use_gui = true;
 
 int exec(int & argc, char * argv[])
 {
-       // Force adding of font path _before_ QApplication is initialized
-       FontLoader::initFontPath();
-
        GuiApplication app(argc, argv);
 
        guiApp = &app;
index a42f13cb18727e6c9bc4327aa65e7bb24a0675ff..7fc882a03d33a78afc553619aa89e3482266e0fb 100644 (file)
@@ -46,77 +46,8 @@ using std::pair;
 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 2376303b4bcaafb6f3efeceba7516714f86f48b4..eadf2b46cc350e3929fa7b6cdd36fe674da4f049 100644 (file)
@@ -75,9 +75,6 @@ public:
                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 6fea91ab688968dcb0f12c482f775bb3d9da1061..467156329f6d84a8e628a75461eb0a4aad329251 100644 (file)
@@ -43,77 +43,8 @@ using std::pair;
 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 3dbf151c1dcdff946153b543633c4a785844340c..1a933d73f524201e8ff2d331025b871a532d5c41 100644 (file)
@@ -75,9 +75,6 @@ public:
                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 4195e4d82740638fafeda1805500757418cd23f0..8192332dd35b2b70b86f1382802d25eea42c4383 100644 (file)
@@ -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 @@ int exec(int & argc, char * argv[])
        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 aeaee83489a3ff5c0646ba461eb873d066dc467f..bc806950d88389249c3db859efcac059bd7803be 100644 (file)
@@ -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 @@ void quitLyX(bool noask)
        }
 
        lyx_gui::exit(0);
+       // Restore original font resources after Application is destroyed.
+       lyx::support::restoreFontResources();
 }
 
 
index 1d77e53ff76eaee527bb87f556a362d72f706b0a..6485af0939631ebb8e0ee299180a41030084a9f4 100644 (file)
@@ -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 @@ void lyx_exit(int status)
        // 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 resources after Application is destroyed.
+               lyx::support::restoreFontResources();
+       }
+
        exit(status);
 }
 
@@ -216,8 +221,11 @@ int LyX::priv_exec(int & argc, char * argv[])
                                   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::addFontResources();
                return lyx_gui::exec(argc, argv);
+       }
        else
                return exec2(argc, argv);
 }
index 986bf0a43d64ca5b035dfd13a4f9edf33734ee2d..de535eebb3c643c15e3d92f09feaa894ea9e6673 100644 (file)
@@ -37,6 +37,8 @@ libsupport_la_SOURCES = \
        filename.h \
        filetools.C \
        filetools.h \
+       fontutils.C \
+       fontutils.h \
        forkedcall.C \
        forkedcall.h \
        forkedcallqueue.C \
diff --git a/src/support/fontutils.C b/src/support/fontutils.C
new file mode 100644 (file)
index 0000000..f0e8ae9
--- /dev/null
@@ -0,0 +1,105 @@
+/**
+ * \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"
+
+#include "support/filetools.h"
+#include "support/lstrings.h"
+#include "support/systemcall.h"
+
+#ifdef __APPLE__
+#include <ApplicationServices/ApplicationServices.h>
+#endif
+
+#ifdef _WIN32
+#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;
+
+using std::string;
+
+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 addFontResources()
+{
+#ifdef __APPLE__
+       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 _WIN32
+       // 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 restoreFontResources()
+{
+#ifdef _WIN32
+       // 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
diff --git a/src/support/fontutils.h b/src/support/fontutils.h
new file mode 100644 (file)
index 0000000..1e5a468
--- /dev/null
@@ -0,0 +1,33 @@
+// -*- 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.
+ * FIXME: only MAC and WIN32 for now but it would be nice to convince
+ * fontconfig to do the same for linux.
+ */
+
+#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 addFontResources();
+
+/// Restore original font resources, must be called after Application
+/// is destroyed.
+void restoreFontResources();
+
+} // namespace support
+} // namespace lyx
+
+#endif