From: Enrico Forestieri Date: Thu, 11 Jan 2007 21:22:18 +0000 (+0000) Subject: Log: X-Git-Tag: 1.6.10~11219 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=fc3a2761dec40aeb573deb9370e80697f2c66ae0;p=features.git Log: Move OS dependent code where it belongs. * src/lyx_cb.C: Remove unused include * src/support/os.h * src/support/os_unix.C * src/support/os_win32.C * src/support/os_cygwin.C: Move here the code from fontutils.[Ch] * src/support/os_cygwin.C (external_path, external_path_list): don't differentiate anymore on Qt/X11 or Qt/Win builds. * src/support/environment.C (setEnvPath): get rid of the #ifdef for cygwin. * src/lyx_main.C (LyX::exec): addFontResources and restoreFontResources are now in the os namespace. * src/support/Makefile.am * src/client/Makefile.am * src/tex2lyx/Makefile.am * development/scons/scons_manifest.py: Updated * src/support/fontutils.[Ch]: Removed git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16655 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index d51e08c390..7bc6f83e83 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -102,7 +102,6 @@ src_support_header_files = Split(''' filefilterlist.h filename.h filetools.h - fontutils.h forkedcall.h forkedcallqueue.h forkedcontr.h @@ -142,7 +141,6 @@ src_support_files = Split(''' filefilterlist.C filename.C filetools.C - fontutils.C forkedcall.C forkedcallqueue.C forkedcontr.C diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 6331ddfb4b..e3f2d95aa1 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -16,7 +16,7 @@ BOOST_LIBS = $(BOOST_REGEX) $(BOOST_FILESYSTEM) lyxclient_LDADD = \ $(top_builddir)/src/support/libsupport.la \ - $(BOOST_LIBS) $(LIBICONV) $(INTLLIBS) $(SOCKET_LIBS) + $(BOOST_LIBS) $(LIBICONV) $(INTLLIBS) @LIBS@ $(SOCKET_LIBS) lyxclient_SOURCES = \ boost.C \ diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 14cca99832..a60882ba5e 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -38,7 +38,6 @@ #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" diff --git a/src/lyx_main.C b/src/lyx_main.C index add424f8b0..56605bf9b0 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -50,7 +50,6 @@ #include "support/environment.h" #include "support/filetools.h" -#include "support/fontutils.h" #include "support/lyxlib.h" #include "support/convert.h" #include "support/os.h" @@ -366,7 +365,7 @@ int LyX::exec(int & argc, char * argv[]) } // Force adding of font path _before_ Application is initialized - support::addFontResources(); + support::os::addFontResources(); // Let the frontend parse and remove all arguments that it knows pimpl_->application_.reset(createApplication(argc, argv)); @@ -403,7 +402,7 @@ int LyX::exec(int & argc, char * argv[]) prepareExit(); // Restore original font resources after Application is destroyed. - support::restoreFontResources(); + support::os::restoreFontResources(); return exit_status; } diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 9bb4815e72..3ad9d9fc5f 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -41,8 +41,6 @@ libsupport_la_SOURCES = \ filename.h \ filetools.C \ filetools.h \ - fontutils.C \ - fontutils.h \ forkedcall.C \ forkedcall.h \ forkedcallqueue.C \ diff --git a/src/support/environment.C b/src/support/environment.C index 616025cf2a..c1a5710978 100644 --- a/src/support/environment.C +++ b/src/support/environment.C @@ -95,14 +95,7 @@ void setEnvPath(string const & name, vector const & env) for (; it != end; ++it) { if (it != begin) ss << separator; -#if defined(__CYGWIN__) || defined(__CYGWIN32__) - // On cygwin, os::external_path returns either posix or - // pseudo-win style paths, but here we always need posix style. - // This fixes bug 2344. - ss << os::internal_path(*it); -#else ss << os::external_path(*it); -#endif } setEnv(name, ss.str()); } diff --git a/src/support/fontutils.C b/src/support/fontutils.C deleted file mode 100644 index 96c92fd8e7..0000000000 --- a/src/support/fontutils.C +++ /dev/null @@ -1,113 +0,0 @@ -/** - * \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 - -#include "fontutils.h" - -#include "support/filetools.h" -#include "support/lstrings.h" -#include "support/systemcall.h" - -#ifdef __APPLE__ -#include "debug.h" -#include -using std::endl; -#endif - -#if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING)) -#include "windows.h" -#ifdef max -#undef max -#endif -#ifdef min -#undef min -#endif -#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", "esint10"}; -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 - -#if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING)) - // 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() -{ -#if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING)) - // 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 deleted file mode 100644 index 1e5a4680fc..0000000000 --- a/src/support/fontutils.h +++ /dev/null @@ -1,33 +0,0 @@ -// -*- 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 diff --git a/src/support/os.h b/src/support/os.h index 90cf569da2..d4b103f106 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -102,6 +102,19 @@ bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode = VIEW); */ bool autoOpenFile(std::string const & filename, auto_open_mode const mode = VIEW); +/** General font utilities. + * FIXME: only MAC and WIN32 for now but it would be nice to convince + * fontconfig to do the same for linux. + */ + +/// 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 os } // namespace support } // namespace lyx diff --git a/src/support/os_cygwin.C b/src/support/os_cygwin.C index fafbaccf5c..d281294ab7 100644 --- a/src/support/os_cygwin.C +++ b/src/support/os_cygwin.C @@ -32,6 +32,19 @@ using std::string; using lyx::support::contains; +#ifdef X_DISPLAY_MISSING +#include "support/filetools.h" +#include "support/package.h" +#include "support/path.h" +using lyx::support::addName; +using lyx::support::addPath; +using lyx::support::package; + +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 support { @@ -188,11 +201,7 @@ string::size_type common_path(string const & p1, string const & p2) string external_path(string const & p) { -#ifdef X_DISPLAY_MISSING - return convert_path(p, PathStyle(windows)); -#else return convert_path(p, PathStyle(posix)); -#endif } @@ -204,11 +213,7 @@ string internal_path(string const & p) string external_path_list(string const & p) { -#ifdef X_DISPLAY_MISSING - return convert_path_list(p, PathStyle(windows)); -#else return convert_path_list(p, PathStyle(posix)); -#endif } @@ -310,6 +315,37 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) } +void addFontResources() +{ +#ifdef X_DISPLAY_MISSING + // 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 = convert_path( + addName(fonts_dir, win_fonts_truetype[i] + ".ttf"), + PathStyle(windows)); + AddFontResource(font_current.c_str()); + } +#endif +} + + +void restoreFontResources() +{ +#ifdef X_DISPLAY_MISSING + // 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 = convert_path( + addName(fonts_dir, win_fonts_truetype[i] + ".ttf"), + PathStyle(windows)); + RemoveFontResource(font_current.c_str()); + } +#endif +} + } // namespace os } // namespace support } // namespace lyx diff --git a/src/support/os_unix.C b/src/support/os_unix.C index 03efbdd3b0..aff294b7b4 100644 --- a/src/support/os_unix.C +++ b/src/support/os_unix.C @@ -15,7 +15,10 @@ #include "support/os.h" #ifdef __APPLE__ +#include "debug.h" #include +#include +using std::endl; #endif using std::string; @@ -192,6 +195,42 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) #endif } + +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 +} + + +void restoreFontResources() +{} + } // namespace os } // namespace support } // namespace lyx diff --git a/src/support/os_win32.C b/src/support/os_win32.C index c6624eadc4..468e8491c2 100644 --- a/src/support/os_win32.C +++ b/src/support/os_win32.C @@ -18,6 +18,8 @@ #include "support/os_win32.h" #include "support/lstrings.h" #include "support/filetools.h" +#include "support/package.h" +#include "support/path.h" #include "debug.h" @@ -68,6 +70,13 @@ using std::string; using lyx::support::runCommand; using lyx::support::split; +using lyx::support::addName; +using lyx::support::addPath; +using lyx::support::package; + +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); namespace lyx { @@ -406,6 +415,31 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) } +void addFontResources() +{ + // 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(external_path(font_current).c_str()); + } +} + + +void restoreFontResources() +{ + // 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(external_path(font_current).c_str()); + } +} + } // namespace os } // namespace support } // namespace lyx diff --git a/src/tex2lyx/Makefile.am b/src/tex2lyx/Makefile.am index 980f4ca1ee..ddbc173689 100644 --- a/src/tex2lyx/Makefile.am +++ b/src/tex2lyx/Makefile.am @@ -56,7 +56,7 @@ tex2lyx_SOURCES = \ tex2lyx_LDADD = \ $(top_builddir)/src/support/libsupport.la \ - $(BOOST_LIBS) $(LIBICONV) $(COMPRESSIONLIB) + $(BOOST_LIBS) $(LIBICONV) @LIBS@ $(COMPRESSIONLIB) $(LINKED_FILES) : @rm -f $@ ; \