From cf4524603c54f3f52df8cd3de91b7c4e2cf83182 Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Wed, 31 Dec 2008 11:47:16 +0000 Subject: [PATCH] * Add code for grabbing fonts.conf from within a bundle (thanks jfs!) * Set BUILD_DARWIN on libass when building on Darwin. Originally committed to SVN as r2589. --- libass/Makefile.am | 4 ++++ libass/ass_fontconfig.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/libass/Makefile.am b/libass/Makefile.am index ba7d9946a..bb290e5e5 100644 --- a/libass/Makefile.am +++ b/libass/Makefile.am @@ -2,6 +2,10 @@ noinst_LIBRARIES = libass_aegisub.a AM_CPPFLAGS = @FREETYPE_CFLAGS@ -DCONFIG_ICONV -DCONFIG_FONTCONFIG @FONTCONFIG_CFLAGS@ @ICONV_CFLAGS@ +if BUILD_DARWIN +AM_CPPFLAGS += -DBUILD_DARWIN +endif + libass_aegisub_a_SOURCES = \ ass.c \ ass_bitmap.c \ diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c index 9a7bddecc..173093bca 100644 --- a/libass/ass_fontconfig.c +++ b/libass/ass_fontconfig.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include FT_FREETYPE_H @@ -37,6 +38,10 @@ #include "ass_library.h" #include "ass_fontconfig.h" +#ifdef BUILD_DARWIN +#include "../aegisub/libosxutil/libosxutil.h" +#endif + #ifdef CONFIG_FONTCONFIG #include #include @@ -402,6 +407,10 @@ fc_instance_t* fontconfig_init(ass_library_t* library, FT_Library ftlibrary, con int rc; fc_instance_t* priv = calloc(1, sizeof(fc_instance_t)); const char* dir = library->fonts_dir; +#ifdef BUILD_DARWIN + char config_path[MAXPATHLEN]; + char *config_dir; +#endif int i; if (!fc) { @@ -410,11 +419,25 @@ fc_instance_t* fontconfig_init(ass_library_t* library, FT_Library ftlibrary, con goto exit; } +#ifdef BUILD_DARWIN + config_dir = OSX_GetBundleResourcesDirectory(); + snprintf(config_path, MAXPATHLEN, "%s/etc/fonts/fonts.conf", config_dir); + free(config_dir); + priv->config = FcConfigCreate(); + rc = FcConfigParseAndLoad(priv->config, config_path, FcTrue); + FcConfigBuildFonts(priv->config); + FcConfigSetCurrent(priv->config); + + if (!rc) { +#else rc = FcInit(); assert(rc); priv->config = FcConfigGetCurrent(); + if (!priv->config) { +#endif + mp_msg(MSGT_ASS, MSGL_FATAL, MSGTR_LIBASS_FcInitLoadConfigAndFontsFailed); goto exit; }