diff options
-rw-r--r-- | Makefile | 15 | ||||
-rwxr-xr-x | configure | 70 | ||||
-rw-r--r-- | fontcache.c | 73 | ||||
-rw-r--r-- | makefiledir/Makefile.config_writer | 2 | ||||
-rw-r--r-- | makefiledir/Makefile.libdetection | 6 |
5 files changed, 138 insertions, 28 deletions
@@ -241,6 +241,12 @@ $(error WITH_FREETYPE can't be used when FREETYPE_CONFIG is not set. Edit Makefi endif endif +ifdef WITH_FONTCONFIG + ifndef FONTCONFIG_CONFIG +$(error WITH_FONTCONFIG can't be used when FONTOCNFIG_CONFIG is not set. Edit Makefile.config to correct this) + endif +endif + ############################################################################## # # Compiler configuration @@ -508,6 +514,15 @@ CFLAGS += $(CCFLAGS_FREETYPE) LIBS += $(LDFLAGS_FREETYPE) endif +# fontconfig config +ifdef WITH_FONTCONFIG +CDEFS += -DWITH_FONTCONFIG +CCFLAGS_FONTCONFIG := $(shell $(FONTCONFIG_CONFIG) --cflags) +LDFLAGS_FONTCONFIG := $(shell $(FONTCONFIG_CONFIG) --libs) +CFLAGS += $(CCFLAGS_FONTCONFIG) +LIBS += $(LDFLAGS_FONTCONFIG) +endif + # iconv is enabled defaultly on OSX >= 10.3 ifdef OSX ifndef JAGUAR @@ -10,39 +10,41 @@ function showhelp() { echo " $0 --your_options" echo "" echo "Params:" - echo " --debug Create debug-release [no]" - echo " --profile Create profile-release [no]" - echo " --dedicated Make a dedicated build [no]" - echo " --revision Set the revision of the compilation [detected]" - echo " --target-cc Sets the target-compiler [\$CC]" - echo " --target-cxx Sets the C++ target-compiler []" - echo " --host-cc Sets the host-compiler [\$CC]" - echo " --host-cxx Sets the C++ host-compiler []" - echo " --os Sets the OS. Listens to: [detected]" - echo " UNIX, OSX, FREEBSD, MORPHOS" - echo " BEOS, SUNOS, CYGWIN, MINGW" - echo " --windres Sets the windres (Windows) [windres]" - echo " --force-le Force LE platform [no]" - echo " --force-be Force BE platform [no]" + echo " --debug Create debug-release [no]" + echo " --profile Create profile-release [no]" + echo " --dedicated Make a dedicated build [no]" + echo " --revision Set the revision of the compilation [detected]" + echo " --target-cc Sets the target-compiler [\$CC]" + echo " --target-cxx Sets the C++ target-compiler []" + echo " --host-cc Sets the host-compiler [\$CC]" + echo " --host-cxx Sets the C++ host-compiler []" + echo " --os Sets the OS. Listens to: [detected]" + echo " UNIX, OSX, FREEBSD, MORPHOS" + echo " BEOS, SUNOS, CYGWIN, MINGW" + echo " --windres Sets the windres (Windows) [windres]" + echo " --force-le Force LE platform [no]" + echo " --force-be Force BE platform [no]" echo "" echo "Params that can be used with --with or --without" echo " (e.g.: --without-static disables static (default))" - echo " static Do you want a static build? [no]" - echo " directmusic Do you want direct-music? [no]" - echo " zlib Do you want zlib-support? [yes]" - echo " sdl Do you want SDL-support? [yes]" - echo " png Do you want PNG-support? [yes]" - echo " iconv Do you want iconv-support? [no]" - echo " network Do you want network-support? [yes]" - echo " cocoa Do you want cocoa-support? (MacOSX) [no]" - echo " freetype Do you want freetype-support? [yes]" + echo " static Do you want a static build? [no]" + echo " directmusic Do you want direct-music? [no]" + echo " zlib Do you want zlib-support? [yes]" + echo " sdl Do you want SDL-support? [yes]" + echo " png Do you want PNG-support? [yes]" + echo " iconv Do you want iconv-support? [no]" + echo " network Do you want network-support? [yes]" + echo " cocoa Do you want cocoa-support? (MacOSX) [no]" + echo " freetype Do you want freetype-support? [yes]" + echo " fontconfig Do you want fontconfig-support? [yes]" echo "" echo "Params used to configure external libs:" - echo " --static-zlib-path Set the path to your static zlib []" - echo " --sdl-config Where is your sdl-config [sdl-config]" - echo " --libpng-config Where is your libpng-config [libpng-config]" - echo " --freetype-config Where is your freetype-config [freetype-config]" - echo " --with-iconv Set the path to your iconv headers []" + echo " --static-zlib-path Set the path to your static zlib []" + echo " --sdl-config Where is your sdl-config [sdl-config]" + echo " --libpng-config Where is your libpng-config [libpng-config]" + echo " --freetype-config Where is your freetype-config [freetype-config]" + echo " --fontconfig-config Where is your fontconfig-config [pkg-config fontconfig]" + echo " --with-iconv Set the path to your iconv headers []" echo " " } @@ -189,6 +191,12 @@ do --without-freetype) PARAM="$PARAM WITH_FREETYPE=" ;; + --with-fontconfig) + PARAM="$PARAM WITH_FONTCONFIG=1" + ;; + --without-fontconfig) + PARAM="$PARAM WITH_FONTCONFIG=" + ;; --static-zlib-path=*) handle STATIC_ZLIB_PATH "$n" ;; @@ -213,6 +221,12 @@ do --freetype-config) ITEM="FREETYPE_CONFIG" ;; + --fontconfig-config=*) + handle FONTCONFIG_CONFIG "$n" + ;; + --fontconfig-config) + ITEM="FONTCONFIG_CONFIG" + ;; --*=*) echo -n "Unknown switch " diff --git a/fontcache.c b/fontcache.c index 4cfba83e8..7d4d76920 100644 --- a/fontcache.c +++ b/fontcache.c @@ -18,6 +18,10 @@ #include FT_FREETYPE_H #include FT_GLYPH_H +#ifdef WITH_FONTCONFIG +#include <fontconfig/fontconfig.h> +#endif + static FT_Library _library = NULL; static FT_Face _face_small = NULL; static FT_Face _face_medium = NULL; @@ -31,6 +35,12 @@ enum { }; +/** + * Loads the freetype font. + * First type to load the fontname as if it were a path. If that fails, + * try to resolve the filename of the font using fontconfig, where the + * format is 'font family name' or 'font family name, font style'. + */ static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *type) { FT_Error error; @@ -38,6 +48,69 @@ static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *t if (strlen(font_name) == 0) return; error = FT_New_Face(_library, font_name, 0, face); +#ifdef WITH_FONTCONFIG + /* Failed to load the font, so try it with fontconfig */ + if (error != FT_Err_Ok) { + if (!FcInit()) { + ShowInfoF("Unable to load font configuration"); + } else { + FcPattern *match; + FcPattern *pat; + FcFontSet *fs; + FcResult result; + char *font_style; + char *font_family; + + /* Split & strip the font's style */ + font_family = strdup(font_name); + font_style = strchr(font_family, ','); + if (font_style != NULL) { + font_style[0] = '\0'; + font_style++; + while (*font_style == ' ' || *font_style == '\t') font_style++; + } + + /* Resolve the name and populate the information structure */ + pat = FcNameParse((FcChar8*)font_family); + if (font_style != NULL) FcPatternAddString(pat, FC_STYLE, (FcChar8*)font_style); + FcConfigSubstitute(0, pat, FcMatchPattern); + FcDefaultSubstitute(pat); + fs = FcFontSetCreate(); + match = FcFontMatch(0, pat, &result); + + if (fs != NULL && match != NULL) { + int i; + FcChar8 *family; + FcChar8 *style; + FcChar8 *file; + FcFontSetAdd(fs, match); + + for (i = 0; error != FT_Err_Ok && i < fs->nfont; i++) { + /* Try the new filename */ + if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, &file) == FcResultMatch && + FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch && + FcPatternGetString(fs->fonts[i], FC_STYLE, 0, &style) == FcResultMatch) { + + /* The correct style? */ + if (font_style != NULL && strcasecmp(font_style, (char*)style) != 0) continue; + + /* Font config takes the best shot, which, if the family name is spelled + * wrongly a 'random' font, so check whether the family name is the + * same as the supplied name */ + if (strcasecmp(font_family, (char*)family) == 0) { + error = FT_New_Face(_library, (char *)file, 0, face); + } + } + } + } + + free(font_family); + FcPatternDestroy(pat); + FcFontSetDestroy(fs); + FcFini(); + } + } +#endif if (error == FT_Err_Ok) { /* Attempt to select the unicode character map */ error = FT_Select_Charmap(*face, ft_encoding_unicode); diff --git a/makefiledir/Makefile.config_writer b/makefiledir/Makefile.config_writer index fad5c78f2..49b54e4f8 100644 --- a/makefiledir/Makefile.config_writer +++ b/makefiledir/Makefile.config_writer @@ -74,6 +74,7 @@ $(MAKE_CONFIG): $(call CONFIG_LINE,STATIC_ZLIB_PATH:=$(STATIC_ZLIB_PATH)) $(call CONFIG_LINE,WITH_COCOA:=$(WITH_COCOA)) $(call CONFIG_LINE,WITH_FREETYPE:=$(WITH_FREETYPE)) + $(call CONFIG_LINE,WITH_FONTCONFIG:=$(WITH_FONTCONFIG)) $(call CONFIG_LINE,) $(call CONFIG_LINE,\# OS flags) @@ -102,6 +103,7 @@ $(MAKE_CONFIG): $(call CONFIG_LINE,SDL_CONFIG:=$(SDL_CONFIG)) $(call CONFIG_LINE,LIBPNG_CONFIG:=$(LIBPNG_CONFIG)) $(call CONFIG_LINE,FREETYPE_CONFIG:=$(FREETYPE_CONFIG)) + $(call CONFIG_LINE,FONTCONFIG_CONFIG:=$(FONTCONFIG_CONFIG)) $(call CONFIG_LINE,BEOS_NET_SERVER:=$(BEOS_NET_SERVER)) $(call CONFIG_LINE,CONFIG_INCLUDED:=yes) $(call CONFIG_LINE,PATH_SET:=$(PATH_SET)) diff --git a/makefiledir/Makefile.libdetection b/makefiledir/Makefile.libdetection index a5160a309..eb38ffd47 100644 --- a/makefiledir/Makefile.libdetection +++ b/makefiledir/Makefile.libdetection @@ -69,6 +69,9 @@ LIBPNG_CONFIG :=libpng-config # set freetype-config to the default value FREETYPE_CONFIG:=freetype-config +# set pkg-config to the default value +FONTCONFIG_CONFIG:=pkg-config fontconfig + # Networking, enabled by default WITH_NETWORK:=1 @@ -81,6 +84,9 @@ WITH_PNG:=$(shell $(LIBPNG_CONFIG) --version 2>/dev/null) # Freetype detection WITH_FREETYPE:=$(shell $(FREETYPE_CONFIG) --ftversion 2>/dev/null) +# fontconfig detection +WITH_FONTCONFIG:=$(shell $(FONTCONFIG_CONFIG) --modversion 2>/dev/null) + ifdef WITH_PNG # LibPNG depends on Zlib WITH_ZLIB:=1 |