"uifont" option: tell us what we wanted & what we got
The requested font & actual font loaded will be echo'd to STDOUT when specifying the `uifont` option. This uses Pango library directly (I was unable to convice SDL2_Pango.h to actually notice that pango.h was #include'd before it, and expose its SDLPango_GetPangoFontDescription() function!). This is okay, since we want to also add a "--uifont list" option (or similar), that will list all of the available fonts, if a user wishes to query them. (And similar code will be added to tuxpaint-config to make the setting available as a pull-down, rather than (or as well as) a freeform type-in field.)
This commit is contained in:
parent
64eeec1a98
commit
1b6ee72e87
5 changed files with 133 additions and 24 deletions
37
Makefile
37
Makefile
|
|
@ -4,7 +4,7 @@
|
||||||
# Various contributors (see AUTHORS.txt)
|
# Various contributors (see AUTHORS.txt)
|
||||||
# https://tuxpaint.org/
|
# https://tuxpaint.org/
|
||||||
|
|
||||||
# June 14, 2002 - May 28, 2023
|
# June 14, 2002 - May 31, 2023
|
||||||
|
|
||||||
|
|
||||||
# The version number, for release:
|
# The version number, for release:
|
||||||
|
|
@ -294,11 +294,16 @@ SDL_LIBS+=$(call linktest,libpng,$(PNG),)
|
||||||
SDL_MIXER_LIB:=$(call linktest,SDL2_mixer,-lSDL2_mixer,$(SDL_LIBS))
|
SDL_MIXER_LIB:=$(call linktest,SDL2_mixer,-lSDL2_mixer,$(SDL_LIBS))
|
||||||
NOSOUNDFLAG:=$(if $(SDL_MIXER_LIB),,-DNOSOUND$(warning -lSDL2_Mixer failed, no sound for you!))
|
NOSOUNDFLAG:=$(if $(SDL_MIXER_LIB),,-DNOSOUND$(warning -lSDL2_Mixer failed, no sound for you!))
|
||||||
|
|
||||||
# SDL Pango is needed to render complex scripts like Thai and Arabic
|
# SDL2_Pango is used to render text (and is needed for complex scripts like Thai and Arabic)
|
||||||
SDL2_PANGO_LIB:=$(call linktest,SDL2_Pango,-lSDL2_Pango,$(SDL_LIBS))
|
SDL2_PANGO_LIB:=$(call linktest,SDL2_Pango,-lSDL2_Pango,$(SDL_LIBS))
|
||||||
SDL2_PANGO_CFLAGS:=$(shell $(PKG_CONFIG) --cflags SDL2_Pango)
|
SDL2_PANGO_CFLAGS:=$(shell $(PKG_CONFIG) --cflags SDL2_Pango)
|
||||||
|
|
||||||
SDL_LIBS+=$(SDL_MIXER_LIB) $(SDL2_PANGO_LIB)
|
# Pango itself is needed for direct and indirect access to some Pango functions
|
||||||
|
PANGO_LIB:=$(call linktest,pango,-lpango,$(SDL_LIBS))
|
||||||
|
PANGO_LIB+=$(call linktest,pangoft2,-lpangoft2,$(SDL_LIBS))
|
||||||
|
PANGO_CFLAGS:=$(shell $(PKG_CONFIG) --cflags pango)
|
||||||
|
|
||||||
|
SDL_LIBS+=$(SDL_MIXER_LIB) $(SDL2_PANGO_LIB) $(PANGO_LIB)
|
||||||
|
|
||||||
SDL_CFLAGS:=$(shell $(PKG_CONFIG) $(SDL_PCNAME) --cflags)
|
SDL_CFLAGS:=$(shell $(PKG_CONFIG) $(SDL_PCNAME) --cflags)
|
||||||
|
|
||||||
|
|
@ -323,16 +328,17 @@ PNG_CFLAGS:=$(shell $(PKG_CONFIG) libpng --cflags)
|
||||||
ifeq ($(hack),1)
|
ifeq ($(hack),1)
|
||||||
hack:
|
hack:
|
||||||
@echo 'SDL2_PANGO_LIB is' $(SDL2_PANGO_LIB)
|
@echo 'SDL2_PANGO_LIB is' $(SDL2_PANGO_LIB)
|
||||||
@echo 'SDL_MIXER_LIB is' $(SDL_MIXER_LIB)
|
@echo 'PANGO_LIB is' $(PANGO_LIB)
|
||||||
@echo 'SVG_LIB is' $(SVG_LIB)
|
@echo 'SDL_MIXER_LIB is' $(SDL_MIXER_LIB)
|
||||||
@echo 'SDL_LIBS is' $(SDL_LIBS)
|
@echo 'SVG_LIB is' $(SVG_LIB)
|
||||||
@echo 'SDL_CFLAGS is' $(SDL_CFLAGS)
|
@echo 'SDL_LIBS is' $(SDL_LIBS)
|
||||||
@echo 'SVG_CFLAGS is' $(SVG_CFLAGS)
|
@echo 'SDL_CFLAGS is' $(SDL_CFLAGS)
|
||||||
@echo 'PAPER_LIB is' $(PAPER_LIB)
|
@echo 'SVG_CFLAGS is' $(SVG_CFLAGS)
|
||||||
@echo 'PNG is' $(PNG)
|
@echo 'PAPER_LIB is' $(PAPER_LIB)
|
||||||
@echo 'LDFLAGS is' $(LDFLAGS)
|
@echo 'PNG is' $(PNG)
|
||||||
@echo 'CFLAGS is' $(CFLAGS)
|
@echo 'LDFLAGS is' $(LDFLAGS)
|
||||||
@echo 'CPPFLAGS is' $(CPPFLAGS)
|
@echo 'CFLAGS is' $(CFLAGS)
|
||||||
|
@echo 'CPPFLAGS is' $(CPPFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# The entire set of CFLAGS:
|
# The entire set of CFLAGS:
|
||||||
|
|
@ -346,7 +352,8 @@ CFLAGS:=$(CPPFLAGS) $(OPTFLAGS) -W -Wall -fno-common -ffloat-store \
|
||||||
-Waggregate-return \
|
-Waggregate-return \
|
||||||
-Wstrict-prototypes -Wmissing-prototypes \
|
-Wstrict-prototypes -Wmissing-prototypes \
|
||||||
$(shell src/test-option.sh -Wstrict-aliasing=2) \
|
$(shell src/test-option.sh -Wstrict-aliasing=2) \
|
||||||
$(SDL2_PANGO_CFLAGS) \
|
$(PANGO_CFLAGS) \
|
||||||
|
$(SDL2_PANGO_CFLAGS) \
|
||||||
$(ARCH_CFLAGS)
|
$(ARCH_CFLAGS)
|
||||||
|
|
||||||
DEFS:=-DVER_DATE=\"$(VER_DATE)\" -DVER_VERSION=\"$(VER_VERSION)\" \
|
DEFS:=-DVER_DATE=\"$(VER_DATE)\" -DVER_VERSION=\"$(VER_VERSION)\" \
|
||||||
|
|
@ -1260,7 +1267,7 @@ obj/fonts.o: src/fonts.c src/fonts.h src/dirwalk.h src/progressbar.h \
|
||||||
src/get_fname.h src/debug.h
|
src/get_fname.h src/debug.h
|
||||||
@echo
|
@echo
|
||||||
@echo "...Compiling font support..."
|
@echo "...Compiling font support..."
|
||||||
@$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) $(ARCH_DEFS) \
|
$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) $(ARCH_DEFS) \
|
||||||
-c src/fonts.c -o obj/fonts.o
|
-c src/fonts.c -o obj/fonts.o
|
||||||
|
|
||||||
obj/dirwalk.o: src/dirwalk.c src/dirwalk.h src/progressbar.h src/fonts.h \
|
obj/dirwalk.o: src/dirwalk.c src/dirwalk.h src/progressbar.h src/fonts.h \
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ Copyright (c) 2002-2023
|
||||||
Various contributors (see below, and AUTHORS.txt)
|
Various contributors (see below, and AUTHORS.txt)
|
||||||
https://tuxpaint.org/
|
https://tuxpaint.org/
|
||||||
|
|
||||||
2023.May.31 (0.9.31)
|
2023.June.1 (0.9.31)
|
||||||
* New Magic Tools:
|
* New Magic Tools:
|
||||||
----------------
|
----------------
|
||||||
* Loops - Draw loop-the-loops.
|
* Loops - Draw loop-the-loops.
|
||||||
|
|
@ -69,6 +69,7 @@ https://tuxpaint.org/
|
||||||
|
|
||||||
* WIP Ability to specify a font for Tux Paint's UI (button labels,
|
* WIP Ability to specify a font for Tux Paint's UI (button labels,
|
||||||
dialog boxes, Tux tip text at the bottom).
|
dialog boxes, Tux tip text at the bottom).
|
||||||
|
+ The requested font & actual font loaded will be echo'd to STDOUT
|
||||||
+ TODO Provide a way to list available fonts ("--uifont list"?)
|
+ TODO Provide a way to list available fonts ("--uifont list"?)
|
||||||
+ TODO List fonts in a pull-down menu in Tux Paint Config.?
|
+ TODO List fonts in a pull-down menu in Tux Paint Config.?
|
||||||
Closes https://sourceforge.net/p/tuxpaint/feature-requests/146/
|
Closes https://sourceforge.net/p/tuxpaint/feature-requests/146/
|
||||||
|
|
|
||||||
97
src/fonts.c
97
src/fonts.c
|
|
@ -19,7 +19,7 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
|
|
||||||
Last modified: April 30, 2023
|
Last modified: June 1, 2023
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -38,9 +38,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The following section renames global variables defined in SDL_Pango.h to avoid errors during linking.
|
The following section renames global variables defined in SDL2_Pango.h to avoid errors during linking.
|
||||||
It is okay to rename these variables because they are constants.
|
It is okay to rename these variables because they are constants.
|
||||||
SDL_Pang.h is included by fonts.h.
|
SDL2_Pango.h is included by fonts.h.
|
||||||
*/
|
*/
|
||||||
#define _MATRIX_WHITE_BACK _MATRIX_WHITE_BACK2
|
#define _MATRIX_WHITE_BACK _MATRIX_WHITE_BACK2
|
||||||
#define MATRIX_WHITE_BACK MATRIX_WHITE_BACK2
|
#define MATRIX_WHITE_BACK MATRIX_WHITE_BACK2
|
||||||
|
|
@ -119,12 +119,22 @@ static const char *problemFontExtensions[] = {
|
||||||
SDL_Thread *font_thread;
|
SDL_Thread *font_thread;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "pango/pango.h"
|
||||||
|
#include "pango/pangoft2.h"
|
||||||
|
#if !defined(__PANGO_H__)
|
||||||
|
#error "---------------------------------------------------"
|
||||||
|
#error "If you installed pango from a package, be sure"
|
||||||
|
#error "to get the development package, as well!"
|
||||||
|
#error "(e.g., 'libpango1.0-dev.rpm')"
|
||||||
|
#error "---------------------------------------------------"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "SDL2_Pango.h"
|
#include "SDL2_Pango.h"
|
||||||
#if !defined(SDL_PANGO_H)
|
#if !defined(SDL_PANGO_H)
|
||||||
#error "---------------------------------------------------"
|
#error "---------------------------------------------------"
|
||||||
#error "If you installed SDL_Pango from a package, be sure"
|
#error "If you installed SDL2_Pango from a package, be sure"
|
||||||
#error "to get the development package, as well!"
|
#error "to get the development package, as well!"
|
||||||
#error "(e.g., 'libsdl-pango1-dev.rpm')"
|
#error "(e.g., 'SDL2_Pango-2.1.5-dev.rpm')"
|
||||||
#error "---------------------------------------------------"
|
#error "---------------------------------------------------"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -1668,3 +1678,80 @@ void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color
|
||||||
|
|
||||||
memcpy(pango_color, pc, 16);
|
memcpy(pango_color, pc, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a font description, do the very bare minimum to
|
||||||
|
* have Pango library try to load it, then retrieve the description
|
||||||
|
* of the font that was _actually_ loaded.
|
||||||
|
* (e.g., "tuxpaint --uifont bookman" finds and uses "URW Bookman"
|
||||||
|
* on my system -bjk 2023.06.01)
|
||||||
|
*/
|
||||||
|
char * ask_pango_for_font(char * pangodesc)
|
||||||
|
{
|
||||||
|
PangoFontMap * font_map;
|
||||||
|
PangoContext * context;
|
||||||
|
PangoFontDescription * font_desc;
|
||||||
|
PangoFont *font;
|
||||||
|
PangoFontDescription * pfd;
|
||||||
|
char * descr;
|
||||||
|
|
||||||
|
font_map = pango_ft2_font_map_new();
|
||||||
|
if (font_map == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "pango_ft2_font_map_new() failed\n");
|
||||||
|
fflush(stderr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
context = pango_font_map_create_context(font_map);
|
||||||
|
if (context == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "pango_font_map_create_context() failed\n");
|
||||||
|
fflush(stderr);
|
||||||
|
g_object_unref(font_map);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
font_desc = pango_font_description_from_string(pangodesc);
|
||||||
|
if (font_desc == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "pango_font_description_from_string() failed\n");
|
||||||
|
fflush(stderr);
|
||||||
|
g_object_unref(font_map);
|
||||||
|
g_object_unref(context);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
font = pango_font_map_load_font(font_map, context, font_desc);
|
||||||
|
if (font == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "pango_font_map_load_font() failed\n");
|
||||||
|
fflush(stderr);
|
||||||
|
g_object_unref(font_map);
|
||||||
|
g_object_unref(context);
|
||||||
|
pango_font_description_free(font_desc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pfd = pango_font_describe(font);
|
||||||
|
if (pfd == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "pango_font_describe() failed\n");
|
||||||
|
fflush(stderr);
|
||||||
|
g_object_unref(font_map);
|
||||||
|
g_object_unref(context);
|
||||||
|
pango_font_description_free(font_desc);
|
||||||
|
g_object_unref(font);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
descr = strdup(pango_font_description_get_family(pfd));
|
||||||
|
|
||||||
|
g_object_unref(font_map);
|
||||||
|
g_object_unref(context);
|
||||||
|
pango_font_description_free(font_desc);
|
||||||
|
g_object_unref(font);
|
||||||
|
/* N.B. Not free'ing `pfd`: The data is owned by the instance */
|
||||||
|
|
||||||
|
return descr;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
|
|
||||||
Last updated: May 29, 2023
|
Last updated: May 31, 2023
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FONTS_H
|
#ifndef FONTS_H
|
||||||
|
|
@ -164,5 +164,6 @@ void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color
|
||||||
|
|
||||||
int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture,
|
int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture,
|
||||||
SDL_Renderer * renderer, void *vp, const char *restrict const locale);
|
SDL_Renderer * renderer, void *vp, const char *restrict const locale);
|
||||||
|
char * ask_pango_for_font(char * pangodesc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -27879,15 +27879,28 @@ static void setup_config(char *argv[])
|
||||||
|
|
||||||
if (tmpcfg.tp_ui_font)
|
if (tmpcfg.tp_ui_font)
|
||||||
{
|
{
|
||||||
|
char * tmp_str;
|
||||||
|
|
||||||
if (strcmp(tmpcfg.tp_ui_font, "default") == 0)
|
if (strcmp(tmpcfg.tp_ui_font, "default") == 0)
|
||||||
{
|
{
|
||||||
printf/*DEBUG_PRINTF*/("UI font will be default: %s\n", PANGO_DEFAULT_FONT);
|
printf/*DEBUG_PRINTF*/("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT);
|
||||||
tp_ui_font = strdup(PANGO_DEFAULT_FONT);
|
tp_ui_font = strdup(PANGO_DEFAULT_FONT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tp_ui_font = strdup(tmpcfg.tp_ui_font);
|
tp_ui_font = strdup(tmpcfg.tp_ui_font);
|
||||||
printf/*DEBUG_PRINTF*/("UI font will be: %s\n", tp_ui_font);
|
printf/*DEBUG_PRINTF*/("Requested UI font described by \"%s\"\n", tp_ui_font);
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp_str = ask_pango_for_font(tp_ui_font);
|
||||||
|
if (tmp_str != NULL)
|
||||||
|
{
|
||||||
|
printf("Actual UI font will be \"%s\"\n", tmp_str);
|
||||||
|
free(tmp_str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Error asking pango for actual font!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue