summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-09-26 20:41:19 -0400
committerMatthias Clasen <mclasen@redhat.com>2022-09-26 20:46:00 -0400
commite27ac590d44e87adac235c1b63429dc5f832f782 (patch)
tree4d473b24ef7c97d57ff89f9751c58baf30ff6696
parentf47e506bb0f692a4e2c6e498f2433cf781acb4eb (diff)
downloadpango-no-font-fixes.tar.gz
Add a test for no-fontsno-font-fixes
Test that the layout is made up entirely of unknown glyphs if we have no font. The main point of this test is to ensure that we don't crash if analysis->font is NULL.
-rw-r--r--tests/meson.build1
-rw-r--r--tests/nofonts/fonts.conf71
-rw-r--r--tests/test-no-fonts.c109
3 files changed, 181 insertions, 0 deletions
diff --git a/tests/meson.build b/tests/meson.build
index e75b8e2f..8b4bfa38 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -63,6 +63,7 @@ if cairo_dep.found()
tests += [
[ 'test-layout', [ 'test-layout.c', 'test-common.c' ], [ libpangocairo_dep, libpangoft2_dep ] ],
[ 'test-fonts', [ 'test-fonts.c', 'test-common.c' ], [ libpangocairo_dep, libpangoft2_dep ] ],
+ [ 'test-no-fonts', [ 'test-no-fonts.c' ], [ libpangocairo_dep, libpangoft2_dep ] ],
]
endif
endif
diff --git a/tests/nofonts/fonts.conf b/tests/nofonts/fonts.conf
new file mode 100644
index 00000000..15685421
--- /dev/null
+++ b/tests/nofonts/fonts.conf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
+<fontconfig>
+ <cachedir>/tmp/cache</cachedir>
+
+ <match target="font">
+ <test name="outline" compare="eq">
+ <bool>false</bool>
+ </test>
+ <edit name="pixelsizefixupfactor" mode="assign">
+ <divide>
+ <name target="pattern">pixelsize</name>
+ <name target="font">pixelsize</name>
+ </divide>
+ </edit>
+ </match>
+
+ <match target="font">
+ <test name="outline" compare="eq">
+ <bool>false</bool>
+ </test>
+ <test name="pixelsizefixupfactor" compare="not_eq">
+ <double>1.0</double>
+ </test>
+ <edit name="matrix" mode="assign">
+ <times>
+ <name>matrix</name>
+ <matrix>
+ <name>pixelsizefixupfactor</name> <double>0</double>
+ <double>0</double> <name>pixelsizefixupfactor</name>
+ </matrix>
+ </times>
+ </edit>
+ <edit name="size" mode="assign">
+ <divide>
+ <name>size</name>
+ <name>pixelsizefixupfactor</name>
+ </divide>
+ </edit>
+ </match>
+
+ <alias binding="same">
+ <family>Noto Color Emoji</family>
+ <default><family>emoji</family></default>
+ </alias>
+
+ <match>
+ <test name="lang">
+ <string>und-zsye</string>
+ </test>
+ <test qual="all" name="family" compare="not_eq">
+ <string>emoji</string>
+ </test>
+ <edit name="family" mode="append" binding="strong">
+ <string>emoji</string>
+ </edit>
+ </match>
+
+ <alias binding="same">
+ <family>emoji</family>
+ <prefer>
+ <family>Noto Color Emoji</family>
+ </prefer>
+ </alias>
+
+ <alias>
+ <family>monospace</family>
+ <prefer><family>DejaVu Sans Mono</family></prefer>
+ </alias>
+
+</fontconfig>
diff --git a/tests/test-no-fonts.c b/tests/test-no-fonts.c
new file mode 100644
index 00000000..c057874d
--- /dev/null
+++ b/tests/test-no-fonts.c
@@ -0,0 +1,109 @@
+/* Pango
+ * test-no-fonts.c: Check that lack of fonts is survivable
+ *
+ * Copyright (C) 2022 Red Hat, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include <string.h>
+#include <locale.h>
+
+#ifndef G_OS_WIN32
+#include <unistd.h>
+#endif
+
+#include "config.h"
+#include <pango/pangocairo.h>
+#include <pango/pangocairo-fc.h>
+#include <pango/pangofc-fontmap.h>
+#include "test-common.h"
+
+
+static void
+install_fonts (const char *dir)
+{
+ FcConfig *config;
+ PangoFontMap *map;
+ char *path;
+ gsize len;
+ char *conf;
+
+ map = g_object_new (PANGO_TYPE_CAIRO_FC_FONT_MAP, NULL);
+
+ config = FcConfigCreate ();
+
+ path = g_build_filename (dir, "fonts.conf", NULL);
+ g_file_get_contents (path, &conf, &len, NULL);
+
+ if (!FcConfigParseAndLoadFromMemory (config, (const FcChar8 *) conf, TRUE))
+ g_error ("Failed to parse fontconfig configuration");
+
+ g_free (conf);
+ g_free (path);
+
+ FcConfigAppFontAddDir (config, (const FcChar8 *) dir);
+ pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (map), config);
+ FcConfigDestroy (config);
+
+ pango_cairo_font_map_set_default (PANGO_CAIRO_FONT_MAP (map));
+
+ g_object_unref (map);
+}
+
+static void
+test_nofonts (void)
+{
+ PangoContext *context;
+ const char *text;
+ PangoLayout *layout;
+ int missing;
+
+ context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+ layout = pango_layout_new (context);
+
+ text = "Schlaf, Kindlein schlaf! "
+ "Der Vater hüt' die Schaf, "
+ "die Mutter schúttelt's Bäumelein, "
+ "da fällt herab ein Träumelein. "
+ "Schlaf, Kindlein schlaf!";
+
+ pango_layout_set_text (layout, text, -1);
+ missing = pango_layout_get_unknown_glyphs_count (layout);
+ g_assert_cmpint (missing, ==, g_utf8_strlen (text, -1));
+
+ g_object_unref (layout);
+ g_object_unref (context);
+}
+
+int
+main (int argc, char *argv[])
+{
+ char *path;
+
+ setlocale (LC_ALL, "");
+
+ g_test_init (&argc, &argv, NULL);
+
+ path = g_test_build_filename (G_TEST_DIST, "nofonts", NULL);
+ install_fonts (path);
+ g_free (path);
+
+ g_test_add_func ("/layout/nofonts", test_nofonts);
+
+ return g_test_run ();
+}