From cdbfb35067968b6c6bdb5f0479665c4f12929978 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 14 Jan 2024 16:58:05 -0500 Subject: [PATCH] rendernode-tool: Make test fonts available We are likely to use the tool with node files from out testsuite, which may now refer to custom test fonts, so make them available in the same way as in the node editor. If in doubt, you can set GTK_SOURCE_DIR to make the tool find the fonts. --- tools/gtk-rendernode-tool.c | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/gtk-rendernode-tool.c b/tools/gtk-rendernode-tool.c index 26c9d11656..6fe3717ee7 100644 --- a/tools/gtk-rendernode-tool.c +++ b/tools/gtk-rendernode-tool.c @@ -29,6 +29,10 @@ #include #include "gtk-rendernode-tool.h" +#ifdef HAVE_PANGOFT +#include +#endif + static void G_GNUC_NORETURN usage (void) { @@ -88,6 +92,41 @@ log_writer_func (GLogLevelFlags level, return G_LOG_WRITER_HANDLED; } +static void +maybe_add_test_fonts (void) +{ +#ifdef HAVE_PANGOFT + const char *subdir = "testsuite/gsk/fonts"; + const char *source_dir; + char *dir; + + source_dir = g_getenv ("GTK_SOURCE_DIR"); + + if (source_dir) + { + char *abs_source_dir = g_canonicalize_filename (source_dir, NULL); + dir = g_canonicalize_filename (subdir, abs_source_dir); + g_free (abs_source_dir); + } + else + { + char *current_dir = g_get_current_dir (); + dir = g_canonicalize_filename (subdir, current_dir); + g_free (current_dir); + } + + if (g_file_test (dir, G_FILE_TEST_EXISTS)) + { + FcConfig *config; + + config = FcConfigGetCurrent (); + FcConfigAppFontAddDir (config, (const FcChar8 *) dir); + } + + g_free (dir); +#endif +} + int main (int argc, const char *argv[]) { @@ -108,6 +147,8 @@ main (int argc, const char *argv[]) argv++; argc--; + maybe_add_test_fonts (); + if (strcmp (argv[0], "show") == 0) do_show (&argc, &argv); else if (strcmp (argv[0], "render") == 0)