Pango loads Tux Paint-supplied fonts on macOS.

Previously Pango loaded system-supplied fonts instead, which could lead
to fonts not rendering in a human-readable text.  This change fixes
https://sourceforge.net/p/tuxpaint/bugs/265/
This commit is contained in:
Mark Kim 2022-12-02 22:56:29 -05:00
parent e00b6b4f4a
commit 3849480fd4
9 changed files with 178 additions and 6 deletions

View file

@ -189,7 +189,7 @@ FRIBIDI_LIB:=$(shell $(PKG_CONFIG) --libs fribidi)
FRIBIDI_CFLAGS:=$(shell $(PKG_CONFIG) --cflags fribidi)
windows_ARCH_LINKS:=-lgdi32 -lcomdlg32 $(PNG) -lz -lwinspool -lshlwapi $(FRIBIDI_LIB) -liconv -limagequant -mwindows
macos_ARCH_LINKS:=$(FRIBIDI_LIB) -limagequant -lSDLmain -Wl,-framework,AppKit -Wl,-framework,Cocoa
macos_ARCH_LINKS:=$(FRIBIDI_LIB) -limagequant -lSDLmain -Wl,-framework,AppKit -Wl,-framework,Cocoa $(shell $(PKG_CONFIG) --libs pangoft2)
ios_ARCH_LINKS=$(FRIBIDI_LIB) -limagequant -ljpeg -lbz2 $(shell $(PKG_CONFIG) --libs freetype2 libtiff-4 libwebp libffi harfbuzz libmpg123 ogg vorbisenc vorbisidec libxml-2.0 pangoft2 libpcre)
beos_ARCH_LINKS:=-lintl $(PNG) -lz -lbe -lnetwork -liconv $(FRIBIDI_LIB) $(PAPER_LIB) $(STDC_LIB) -limagequant
linux_ARCH_LINKS:=$(PAPER_LIB) $(FRIBIDI_LIB) -limagequant
@ -1108,7 +1108,7 @@ install-macbundle:
@install -d -m 755 $(BUNDLE)/Contents/lib
@install -m 755 tuxpaint $(BUNDLE)/Contents/MacOS
@install -m 644 macos/PkgInfo $(BUNDLE)/Contents
@VER_VERSION=$(VER_VERSION) macos/template.sh macos/Info.plist.shdoc > macos/Info.plist
@VER_VERSION=$(VER_VERSION)$(VER_FLAVOR) macos/template.sh macos/Info.plist.shdoc > macos/Info.plist
@install -m 644 macos/Info.plist $(BUNDLE)/Contents
@install -m 644 macos/tuxpaint.icns $(BUNDLE)/Contents/Resources
@macos/build-app.sh
@ -1120,7 +1120,7 @@ install-iosbundle:
@echo "...Installing iOS App Bundle Support Files..."
@install -m 755 tuxpaint $(BUNDLE)
@install -m 644 ios/PkgInfo $(BUNDLE)
@VER_VERSION=$(VER_VERSION) ios/template.sh ios/Info.plist.shdoc > ios/Info.plist
@VER_VERSION=$(VER_VERSION)$(VER_FLAVOR) ios/template.sh ios/Info.plist.shdoc > ios/Info.plist
@install -m 644 ios/Info.plist $(BUNDLE)
@install -m 644 ios/tuxpaint.icns $(BUNDLE)
@install -m 644 ios/tuxpaint.cfg $(BUNDLE)

View file

@ -180,6 +180,12 @@ http://www.tuxpaint.org/
the installer app
TOYAMA Shin-ichi <dolphin6k@wmail.plala.or.jp>
* Pango loads Tux Paint-supplied fonts on macOS.
Previously Pango loaded system-supplied fonts instead, which could lead
to fonts not rendering in a human-readable text. This change fixes
https://sourceforge.net/p/tuxpaint/bugs/265/
Mark Kim <markuskimius@gmail.com>
* Documentation updates:
---------------------
* New "Quickstart Guide" document added.

View file

@ -4,7 +4,7 @@ BUNDLE=TuxPaint.app
BINARY="$BUNDLE/Contents/MacOS/tuxpaint"
LIBS=`find $BUNDLE/Contents/Resources/lib -type f`
LIBDIR="$BUNDLE/Contents/lib"
CONF_FILES="/opt/local/etc/fonts/fonts.conf"
CONF_FILES="macos/fonts.conf"
CONFDIR="$BUNDLE/Contents/Resources/etc"

93
macos/fonts.conf Normal file
View file

@ -0,0 +1,93 @@
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
<its:translateRule translate="no" selector="/fontconfig/*[not(self::description)]"/>
</its:rules>
<description>Default configuration file</description>
<!--
Font directory list
-->
<dir prefix="cwd">Resources/share/tuxpaint/fonts</dir>
<dir prefix="cwd">Resources/share/tuxpaint/fonts/locale</dir>
<dir prefix="cwd">share/tuxpaint/fonts</dir>
<dir prefix="cwd">share/tuxpaint/fonts/locale</dir>
<dir>~/Library/Application Support/TuxPaint/fonts</dir>
<dir>~/Library/Application Support/TuxPaint/fonts/locale</dir>
<dir>/Library/Application Support/TuxPaint/fonts</dir>
<dir>/Library/Application Support/TuxPaint/fonts/locale</dir>
<!--
Accept deprecated 'mono' alias, replacing it with 'monospace'
-->
<match target="pattern">
<test qual="any" name="family">
<string>mono</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>monospace</string>
</edit>
</match>
<!--
Accept alternate 'sans serif' spelling, replacing it with 'sans-serif'
-->
<match target="pattern">
<test qual="any" name="family">
<string>sans serif</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>sans-serif</string>
</edit>
</match>
<!--
Accept deprecated 'sans' alias, replacing it with 'sans-serif'
-->
<match target="pattern">
<test qual="any" name="family">
<string>sans</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>sans-serif</string>
</edit>
</match>
<!--
Load local system customization file
-->
<!--
<include ignore_missing="yes">conf.d</include>
-->
<!--
Tux Paint uses DejaVu Sans as the default font but loads it as BitStream Vera font.
-->
<match target="pattern">
<test qual="any" name="family">
<string>BitStream Vera</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>DejaVu Sans</string>
</edit>
</match>
<!--
Font cache directory list
-->
<cachedir>/tmp/fontconfig</cachedir>
<cachedir prefix="xdg">fontconfig</cachedir>
<config>
<!--
Rescan configuration every 30 seconds when FcFontSetList is called
-->
<rescan>
<int>30</int>
</rescan>
</config>
</fontconfig>

View file

@ -1,6 +1,32 @@
//#define DEBUG
//#define VERBOSE
/*
Enable fontconfig debugging. The value of this variable, which must be a
string, but is interpreted as a number, and each bit within that value
controls different debugging messages. (from
https://www.freedesktop.org/software/fontconfig/fontconfig-user.html#DEBUG)
Name Value Meaning
---------------------------------------------------------
MATCH 1 Brief information about font matching
MATCHV 2 Extensive font matching information
EDIT 4 Monitor match/test/edit execution
FONTSET 8 Track loading of font information at startup
CACHE 16 Watch cache files being written
CACHEV 32 Extensive cache file writing information
PARSE 64 (no longer in use)
SCAN 128 Watch font files being scanned to build caches
SCANV 256 Verbose font file scanning information
MEMORY 512 Monitor fontconfig memory usage
CONFIG 1024 Monitor which config files are loaded
LANGSET 2048 Dump char sets used to construct lang values
MATCH2 4096 Display font-matching transformation in patterns
*/
#if defined(DEBUG) && defined(VERBOSE)
#define FC_DEBUG "1025"
#endif
/*
* Enable verbose logging if requested on platforms that support it.
*

View file

@ -286,6 +286,16 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
desc);
#endif
#ifdef __APPLE__
/*
* SDLPango_CreateContext_GivenFontDesc() defaults to ASCII character set
* (at least on the macOS) unless the CHARSET environment varaible is set.
* May also want to set on non-macOS platforms, also.
*/
mysetenv("CHARSET", "UTF-8");
#endif
tpf->pango_context = SDLPango_CreateContext_GivenFontDesc(desc);
if (tpf->pango_context == NULL)
{

View file

@ -1064,7 +1064,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
* @param name Variable to set
* @param value Value to set the variable to
*/
static void mysetenv(const char *name, const char *value)
void mysetenv(const char *name, const char *value)
{
#ifndef HAVE_SETENV
int len;

View file

@ -208,6 +208,7 @@ extern w_langs wished_langs[255];
int get_current_language(void);
int setup_i18n(const char *restrict lang, const char *restrict locale,
int *ptr_num_wished_languages) MUST_CHECK;
void mysetenv(const char *name, const char *value);
#ifdef NO_SDLPANGO
int smash_i18n(void) MUST_CHECK;

View file

@ -450,8 +450,12 @@ int iswprint(wchar_t wc)
#error "---------------------------------------------------"
#endif
#ifdef DEBUG
/* These are required to display pango debugging information later in this file */
#include <pango/pango.h>
#include <pango/pangoft2.h>
#endif
#endif /* !defined(NO_SDLPANGO) */
#ifndef NOSOUND
@ -30999,6 +31003,13 @@ int main(int argc, char *argv[])
putenv((char *) "FONTCONFIG_PATH=Resources/etc");
#endif
#if defined(FC_DEBUG)
/*
* Enable fontconfig debugging. See "debug.h"
*/
mysetenv("FC_DEBUG", FC_DEBUG);
#endif
#ifdef FORKED_FONTS
/* must start ASAP, but depends on locale which in turn needs the config */
#ifdef NO_SDLPANGO
@ -31044,6 +31055,31 @@ int main(int argc, char *argv[])
#endif
#if defined(DEBUG) && !defined(NO_SDLPANGO)
/* Confirm pango's character set */
if(1) {
const char* charset;
g_get_charset(&charset);
printf("pango charset: %s\n", charset);
}
/* Display fonts available to pango */
if(1) {
PangoFontMap* fontmap;
PangoFontFamily** families;
int n_families;
fontmap = pango_ft2_font_map_new();
pango_font_map_list_families(fontmap, &families, &n_families);
for(int i=0; i < n_families; i++) {
const char* family_name = pango_font_family_get_name(families[i]);
printf("pango ft2 fontmap[%d] = '%s'\n", i, family_name);
}
}
#endif
claim_to_be_ready();