mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-31 19:33:34 +00:00
(svn r7196) -Feature: use fontconfig so one can set the font family name in openttd.cfg instead of the full path to the font.
This commit is contained in:
parent
f2cda44d2e
commit
bd129cf6bf
15
Makefile
15
Makefile
@ -241,6 +241,12 @@ $(error WITH_FREETYPE can't be used when FREETYPE_CONFIG is not set. Edit Makefi
|
|||||||
endif
|
endif
|
||||||
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
|
# Compiler configuration
|
||||||
@ -508,6 +514,15 @@ CFLAGS += $(CCFLAGS_FREETYPE)
|
|||||||
LIBS += $(LDFLAGS_FREETYPE)
|
LIBS += $(LDFLAGS_FREETYPE)
|
||||||
endif
|
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
|
# iconv is enabled defaultly on OSX >= 10.3
|
||||||
ifdef OSX
|
ifdef OSX
|
||||||
ifndef JAGUAR
|
ifndef JAGUAR
|
||||||
|
70
configure
vendored
70
configure
vendored
@ -10,39 +10,41 @@ function showhelp() {
|
|||||||
echo " $0 --your_options"
|
echo " $0 --your_options"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Params:"
|
echo "Params:"
|
||||||
echo " --debug Create debug-release [no]"
|
echo " --debug Create debug-release [no]"
|
||||||
echo " --profile Create profile-release [no]"
|
echo " --profile Create profile-release [no]"
|
||||||
echo " --dedicated Make a dedicated build [no]"
|
echo " --dedicated Make a dedicated build [no]"
|
||||||
echo " --revision Set the revision of the compilation [detected]"
|
echo " --revision Set the revision of the compilation [detected]"
|
||||||
echo " --target-cc Sets the target-compiler [\$CC]"
|
echo " --target-cc Sets the target-compiler [\$CC]"
|
||||||
echo " --target-cxx Sets the C++ target-compiler []"
|
echo " --target-cxx Sets the C++ target-compiler []"
|
||||||
echo " --host-cc Sets the host-compiler [\$CC]"
|
echo " --host-cc Sets the host-compiler [\$CC]"
|
||||||
echo " --host-cxx Sets the C++ host-compiler []"
|
echo " --host-cxx Sets the C++ host-compiler []"
|
||||||
echo " --os Sets the OS. Listens to: [detected]"
|
echo " --os Sets the OS. Listens to: [detected]"
|
||||||
echo " UNIX, OSX, FREEBSD, MORPHOS"
|
echo " UNIX, OSX, FREEBSD, MORPHOS"
|
||||||
echo " BEOS, SUNOS, CYGWIN, MINGW"
|
echo " BEOS, SUNOS, CYGWIN, MINGW"
|
||||||
echo " --windres Sets the windres (Windows) [windres]"
|
echo " --windres Sets the windres (Windows) [windres]"
|
||||||
echo " --force-le Force LE platform [no]"
|
echo " --force-le Force LE platform [no]"
|
||||||
echo " --force-be Force BE platform [no]"
|
echo " --force-be Force BE platform [no]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Params that can be used with --with or --without"
|
echo "Params that can be used with --with or --without"
|
||||||
echo " (e.g.: --without-static disables static (default))"
|
echo " (e.g.: --without-static disables static (default))"
|
||||||
echo " static Do you want a static build? [no]"
|
echo " static Do you want a static build? [no]"
|
||||||
echo " directmusic Do you want direct-music? [no]"
|
echo " directmusic Do you want direct-music? [no]"
|
||||||
echo " zlib Do you want zlib-support? [yes]"
|
echo " zlib Do you want zlib-support? [yes]"
|
||||||
echo " sdl Do you want SDL-support? [yes]"
|
echo " sdl Do you want SDL-support? [yes]"
|
||||||
echo " png Do you want PNG-support? [yes]"
|
echo " png Do you want PNG-support? [yes]"
|
||||||
echo " iconv Do you want iconv-support? [no]"
|
echo " iconv Do you want iconv-support? [no]"
|
||||||
echo " network Do you want network-support? [yes]"
|
echo " network Do you want network-support? [yes]"
|
||||||
echo " cocoa Do you want cocoa-support? (MacOSX) [no]"
|
echo " cocoa Do you want cocoa-support? (MacOSX) [no]"
|
||||||
echo " freetype Do you want freetype-support? [yes]"
|
echo " freetype Do you want freetype-support? [yes]"
|
||||||
|
echo " fontconfig Do you want fontconfig-support? [yes]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Params used to configure external libs:"
|
echo "Params used to configure external libs:"
|
||||||
echo " --static-zlib-path Set the path to your static zlib []"
|
echo " --static-zlib-path Set the path to your static zlib []"
|
||||||
echo " --sdl-config Where is your sdl-config [sdl-config]"
|
echo " --sdl-config Where is your sdl-config [sdl-config]"
|
||||||
echo " --libpng-config Where is your libpng-config [libpng-config]"
|
echo " --libpng-config Where is your libpng-config [libpng-config]"
|
||||||
echo " --freetype-config Where is your freetype-config [freetype-config]"
|
echo " --freetype-config Where is your freetype-config [freetype-config]"
|
||||||
echo " --with-iconv Set the path to your iconv headers []"
|
echo " --fontconfig-config Where is your fontconfig-config [pkg-config fontconfig]"
|
||||||
|
echo " --with-iconv Set the path to your iconv headers []"
|
||||||
echo " "
|
echo " "
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,6 +191,12 @@ do
|
|||||||
--without-freetype)
|
--without-freetype)
|
||||||
PARAM="$PARAM WITH_FREETYPE="
|
PARAM="$PARAM WITH_FREETYPE="
|
||||||
;;
|
;;
|
||||||
|
--with-fontconfig)
|
||||||
|
PARAM="$PARAM WITH_FONTCONFIG=1"
|
||||||
|
;;
|
||||||
|
--without-fontconfig)
|
||||||
|
PARAM="$PARAM WITH_FONTCONFIG="
|
||||||
|
;;
|
||||||
--static-zlib-path=*)
|
--static-zlib-path=*)
|
||||||
handle STATIC_ZLIB_PATH "$n"
|
handle STATIC_ZLIB_PATH "$n"
|
||||||
;;
|
;;
|
||||||
@ -213,6 +221,12 @@ do
|
|||||||
--freetype-config)
|
--freetype-config)
|
||||||
ITEM="FREETYPE_CONFIG"
|
ITEM="FREETYPE_CONFIG"
|
||||||
;;
|
;;
|
||||||
|
--fontconfig-config=*)
|
||||||
|
handle FONTCONFIG_CONFIG "$n"
|
||||||
|
;;
|
||||||
|
--fontconfig-config)
|
||||||
|
ITEM="FONTCONFIG_CONFIG"
|
||||||
|
;;
|
||||||
|
|
||||||
--*=*)
|
--*=*)
|
||||||
echo -n "Unknown switch "
|
echo -n "Unknown switch "
|
||||||
|
73
fontcache.c
73
fontcache.c
@ -18,6 +18,10 @@
|
|||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
#include FT_GLYPH_H
|
#include FT_GLYPH_H
|
||||||
|
|
||||||
|
#ifdef WITH_FONTCONFIG
|
||||||
|
#include <fontconfig/fontconfig.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static FT_Library _library = NULL;
|
static FT_Library _library = NULL;
|
||||||
static FT_Face _face_small = NULL;
|
static FT_Face _face_small = NULL;
|
||||||
static FT_Face _face_medium = 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)
|
static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *type)
|
||||||
{
|
{
|
||||||
FT_Error error;
|
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;
|
if (strlen(font_name) == 0) return;
|
||||||
|
|
||||||
error = FT_New_Face(_library, font_name, 0, face);
|
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) {
|
if (error == FT_Err_Ok) {
|
||||||
/* Attempt to select the unicode character map */
|
/* Attempt to select the unicode character map */
|
||||||
error = FT_Select_Charmap(*face, ft_encoding_unicode);
|
error = FT_Select_Charmap(*face, ft_encoding_unicode);
|
||||||
|
@ -74,6 +74,7 @@ $(MAKE_CONFIG):
|
|||||||
$(call CONFIG_LINE,STATIC_ZLIB_PATH:=$(STATIC_ZLIB_PATH))
|
$(call CONFIG_LINE,STATIC_ZLIB_PATH:=$(STATIC_ZLIB_PATH))
|
||||||
$(call CONFIG_LINE,WITH_COCOA:=$(WITH_COCOA))
|
$(call CONFIG_LINE,WITH_COCOA:=$(WITH_COCOA))
|
||||||
$(call CONFIG_LINE,WITH_FREETYPE:=$(WITH_FREETYPE))
|
$(call CONFIG_LINE,WITH_FREETYPE:=$(WITH_FREETYPE))
|
||||||
|
$(call CONFIG_LINE,WITH_FONTCONFIG:=$(WITH_FONTCONFIG))
|
||||||
$(call CONFIG_LINE,)
|
$(call CONFIG_LINE,)
|
||||||
|
|
||||||
$(call CONFIG_LINE,\# OS flags)
|
$(call CONFIG_LINE,\# OS flags)
|
||||||
@ -102,6 +103,7 @@ $(MAKE_CONFIG):
|
|||||||
$(call CONFIG_LINE,SDL_CONFIG:=$(SDL_CONFIG))
|
$(call CONFIG_LINE,SDL_CONFIG:=$(SDL_CONFIG))
|
||||||
$(call CONFIG_LINE,LIBPNG_CONFIG:=$(LIBPNG_CONFIG))
|
$(call CONFIG_LINE,LIBPNG_CONFIG:=$(LIBPNG_CONFIG))
|
||||||
$(call CONFIG_LINE,FREETYPE_CONFIG:=$(FREETYPE_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,BEOS_NET_SERVER:=$(BEOS_NET_SERVER))
|
||||||
$(call CONFIG_LINE,CONFIG_INCLUDED:=yes)
|
$(call CONFIG_LINE,CONFIG_INCLUDED:=yes)
|
||||||
$(call CONFIG_LINE,PATH_SET:=$(PATH_SET))
|
$(call CONFIG_LINE,PATH_SET:=$(PATH_SET))
|
||||||
|
@ -69,6 +69,9 @@ LIBPNG_CONFIG :=libpng-config
|
|||||||
# set freetype-config to the default value
|
# set freetype-config to the default value
|
||||||
FREETYPE_CONFIG:=freetype-config
|
FREETYPE_CONFIG:=freetype-config
|
||||||
|
|
||||||
|
# set pkg-config to the default value
|
||||||
|
FONTCONFIG_CONFIG:=pkg-config fontconfig
|
||||||
|
|
||||||
# Networking, enabled by default
|
# Networking, enabled by default
|
||||||
WITH_NETWORK:=1
|
WITH_NETWORK:=1
|
||||||
|
|
||||||
@ -81,6 +84,9 @@ WITH_PNG:=$(shell $(LIBPNG_CONFIG) --version 2>/dev/null)
|
|||||||
# Freetype detection
|
# Freetype detection
|
||||||
WITH_FREETYPE:=$(shell $(FREETYPE_CONFIG) --ftversion 2>/dev/null)
|
WITH_FREETYPE:=$(shell $(FREETYPE_CONFIG) --ftversion 2>/dev/null)
|
||||||
|
|
||||||
|
# fontconfig detection
|
||||||
|
WITH_FONTCONFIG:=$(shell $(FONTCONFIG_CONFIG) --modversion 2>/dev/null)
|
||||||
|
|
||||||
ifdef WITH_PNG
|
ifdef WITH_PNG
|
||||||
# LibPNG depends on Zlib
|
# LibPNG depends on Zlib
|
||||||
WITH_ZLIB:=1
|
WITH_ZLIB:=1
|
||||||
|
Loading…
Reference in New Issue
Block a user