1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-10-31 19:36:16 +00:00

Merge pull request #300 from dulsi/master

Add optional fontconfig support.
This commit is contained in:
Zeno Rogue 2023-05-15 19:16:18 +02:00 committed by GitHub
commit c03e9cfeb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 2 deletions

View File

@ -102,6 +102,10 @@ ifeq (${TOOLCHAIN},mingw)
CXXFLAGS_EARLY += -Wno-invalid-offsetof CXXFLAGS_EARLY += -Wno-invalid-offsetof
endif endif
ifeq (${FONTCONFIG},1)
CXXFLAGS_EARLY += -DFONTCONFIG `pkg-config --cflags fontconfig`
LDFLAGS_EARLY += `pkg-config --libs fontconfig`
endif
## We have now finished OS-specific and TOOLCHAIN-specific computations. ## We have now finished OS-specific and TOOLCHAIN-specific computations.
## Begin customization points for user-specifiable HYPERROGUE_USE_XXX macros. ## Begin customization points for user-specifiable HYPERROGUE_USE_XXX macros.

View File

@ -6,6 +6,10 @@
*/ */
#include "hyper.h" #include "hyper.h"
#ifdef FONTCONFIG
#include <fontconfig/fontconfig.h>
#endif
namespace hr { namespace hr {
#if HDR #if HDR
@ -216,12 +220,43 @@ EX void present_screen() {
#if CAP_SDLTTF #if CAP_SDLTTF
EX string fontpath = ISWEB ? "sans-serif" : HYPERFONTPATH "DejaVuSans-Bold.ttf"; string fontdefault = "DejaVuSans-Bold.ttf";
EX string fontpath = ISWEB ? "sans-serif" : string(HYPERFONTPATH) + fontdefault;
string findfont() {
string answer = fontpath;
#ifdef FONTCONFIG
if ((answer.length() < fontdefault.length()) || (0 != answer.compare(answer.length() - fontdefault.length(), fontdefault.length(), fontdefault))) {
return answer;
}
FcPattern *pat;
FcResult result;
if (!FcInit()) {
return answer;
}
pat = FcNameParse((FcChar8 *)fontdefault.c_str());
FcConfigSubstitute(0, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
FcPattern *match;
match = FcFontMatch(0, pat, &result);
if (match) {
FcChar8 *file;
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch) {
answer = (const char *)file;
}
FcPatternDestroy(match);
}
FcPatternDestroy(pat);
FcFini();
#endif
return answer;
}
void loadfont(int siz) { void loadfont(int siz) {
fix_font_size(siz); fix_font_size(siz);
if(!font[siz]) { if(!font[siz]) {
font[siz] = TTF_OpenFont(fontpath.c_str(), siz); font[siz] = TTF_OpenFont(findfont().c_str(), siz);
// Destination set by ./configure (in the GitHub repository) // Destination set by ./configure (in the GitHub repository)
#ifdef FONTDESTDIR #ifdef FONTDESTDIR
if (font[siz] == NULL) { if (font[siz] == NULL) {