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
This commit is contained in:
Enrico Forestieri 2007-01-11 21:22:18 +00:00
parent 8a91526dd6
commit fc3a2761de
13 changed files with 134 additions and 171 deletions

View File

@ -102,7 +102,6 @@ src_support_header_files = Split('''
filefilterlist.h filefilterlist.h
filename.h filename.h
filetools.h filetools.h
fontutils.h
forkedcall.h forkedcall.h
forkedcallqueue.h forkedcallqueue.h
forkedcontr.h forkedcontr.h
@ -142,7 +141,6 @@ src_support_files = Split('''
filefilterlist.C filefilterlist.C
filename.C filename.C
filetools.C filetools.C
fontutils.C
forkedcall.C forkedcall.C
forkedcallqueue.C forkedcallqueue.C
forkedcontr.C forkedcontr.C

View File

@ -16,7 +16,7 @@ BOOST_LIBS = $(BOOST_REGEX) $(BOOST_FILESYSTEM)
lyxclient_LDADD = \ lyxclient_LDADD = \
$(top_builddir)/src/support/libsupport.la \ $(top_builddir)/src/support/libsupport.la \
$(BOOST_LIBS) $(LIBICONV) $(INTLLIBS) $(SOCKET_LIBS) $(BOOST_LIBS) $(LIBICONV) $(INTLLIBS) @LIBS@ $(SOCKET_LIBS)
lyxclient_SOURCES = \ lyxclient_SOURCES = \
boost.C \ boost.C \

View File

@ -38,7 +38,6 @@
#include "support/filefilterlist.h" #include "support/filefilterlist.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/fontutils.h"
#include "support/forkedcall.h" #include "support/forkedcall.h"
#include "support/fs_extras.h" #include "support/fs_extras.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"

View File

@ -50,7 +50,6 @@
#include "support/environment.h" #include "support/environment.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/fontutils.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
#include "support/convert.h" #include "support/convert.h"
#include "support/os.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 // 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 // Let the frontend parse and remove all arguments that it knows
pimpl_->application_.reset(createApplication(argc, argv)); pimpl_->application_.reset(createApplication(argc, argv));
@ -403,7 +402,7 @@ int LyX::exec(int & argc, char * argv[])
prepareExit(); prepareExit();
// Restore original font resources after Application is destroyed. // Restore original font resources after Application is destroyed.
support::restoreFontResources(); support::os::restoreFontResources();
return exit_status; return exit_status;
} }

View File

@ -41,8 +41,6 @@ libsupport_la_SOURCES = \
filename.h \ filename.h \
filetools.C \ filetools.C \
filetools.h \ filetools.h \
fontutils.C \
fontutils.h \
forkedcall.C \ forkedcall.C \
forkedcall.h \ forkedcall.h \
forkedcallqueue.C \ forkedcallqueue.C \

View File

@ -95,14 +95,7 @@ void setEnvPath(string const & name, vector<string> const & env)
for (; it != end; ++it) { for (; it != end; ++it) {
if (it != begin) if (it != begin)
ss << separator; 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); ss << os::external_path(*it);
#endif
} }
setEnv(name, ss.str()); setEnv(name, ss.str());
} }

View File

@ -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 <config.h>
#include "fontutils.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
#ifdef __APPLE__
#include "debug.h"
#include <ApplicationServices/ApplicationServices.h>
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

View File

@ -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

View File

@ -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); 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 os
} // namespace support } // namespace support
} // namespace lyx } // namespace lyx

View File

@ -32,6 +32,19 @@ using std::string;
using lyx::support::contains; 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 lyx {
namespace support { namespace support {
@ -188,11 +201,7 @@ string::size_type common_path(string const & p1, string const & p2)
string external_path(string const & p) string external_path(string const & p)
{ {
#ifdef X_DISPLAY_MISSING
return convert_path(p, PathStyle(windows));
#else
return convert_path(p, PathStyle(posix)); return convert_path(p, PathStyle(posix));
#endif
} }
@ -204,11 +213,7 @@ string internal_path(string const & p)
string external_path_list(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)); 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 os
} // namespace support } // namespace support
} // namespace lyx } // namespace lyx

View File

@ -15,7 +15,10 @@
#include "support/os.h" #include "support/os.h"
#ifdef __APPLE__ #ifdef __APPLE__
#include "debug.h"
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>
using std::endl;
#endif #endif
using std::string; using std::string;
@ -192,6 +195,42 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode)
#endif #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 os
} // namespace support } // namespace support
} // namespace lyx } // namespace lyx

View File

@ -18,6 +18,8 @@
#include "support/os_win32.h" #include "support/os_win32.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/package.h"
#include "support/path.h"
#include "debug.h" #include "debug.h"
@ -68,6 +70,13 @@ using std::string;
using lyx::support::runCommand; using lyx::support::runCommand;
using lyx::support::split; 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 { 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 os
} // namespace support } // namespace support
} // namespace lyx } // namespace lyx

View File

@ -56,7 +56,7 @@ tex2lyx_SOURCES = \
tex2lyx_LDADD = \ tex2lyx_LDADD = \
$(top_builddir)/src/support/libsupport.la \ $(top_builddir)/src/support/libsupport.la \
$(BOOST_LIBS) $(LIBICONV) $(COMPRESSIONLIB) $(BOOST_LIBS) $(LIBICONV) @LIBS@ $(COMPRESSIONLIB)
$(LINKED_FILES) : $(LINKED_FILES) :
@rm -f $@ ; \ @rm -f $@ ; \