[pango/pango2: 13/178] Add some more markup tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 13/178] Add some more markup tests
- Date: Wed, 22 Jun 2022 20:10:10 +0000 (UTC)
commit 1fc7d0bd85708b8e9a55f92ee1fbee5795e43814
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Feb 20 08:22:16 2022 -0600
Add some more markup tests
tests/markups/convenience.expected | 107 +++++++++++++
tests/markups/convenience.markup | 12 ++
tests/markups/custom.expected | 147 +++++++++++++++++
tests/markups/custom.markup | 20 +++
tests/testhbfont.c | 314 -------------------------------------
5 files changed, 286 insertions(+), 314 deletions(-)
---
diff --git a/tests/markups/convenience.expected b/tests/markups/convenience.expected
new file mode 100644
index 000000000..70215ba5d
--- /dev/null
+++ b/tests/markups/convenience.expected
@@ -0,0 +1,107 @@
+
+
+be bold
+be big
+be small
+go mono
+be italic
+strike out
+underline it
+thisiswild
+
+
+
+
+---
+
+range 0 1
+range 1 2
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 2 9
+1 79 font-desc "Cantarell 20"
+1 79 language en
+2 9 weight bold
+range 9 10
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 10 16
+1 79 font-desc "Cantarell 20"
+1 79 language en
+10 16 size 24576
+range 16 17
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 17 25
+1 79 font-desc "Cantarell 20"
+1 79 language en
+17 25 size 17066
+range 25 26
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 26 33
+1 79 font-desc "Cantarell 20"
+1 79 language en
+26 33 family "Monospace"
+range 33 34
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 34 43
+1 79 font-desc "Cantarell 20"
+1 79 language en
+34 43 style italic
+range 43 44
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 44 54
+1 79 font-desc "Cantarell 20"
+1 79 language en
+44 54 strikethrough single
+range 54 55
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 55 67
+1 79 font-desc "Cantarell 20"
+1 79 language en
+55 67 underline single
+range 67 72
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 72 74
+1 79 font-desc "Cantarell 20"
+1 79 language en
+72 74 font-scale subscript
+72 74 baseline-shift subscript
+range 74 78
+1 79 font-desc "Cantarell 20"
+1 79 language en
+74 78 font-scale superscript
+74 78 baseline-shift superscript
+range 78 79
+1 79 font-desc "Cantarell 20"
+1 79 language en
+range 79 2147483647
+
+
+---
+
+[0:1] (null) Normal
+[1:2] en Cantarell 20
+[2:9] en Cantarell Bold 20
+[9:10] en Cantarell 20
+[10:16] en Cantarell 24
+[16:17] en Cantarell 20
+[17:25] en Cantarell 16.666015625
+[25:26] en Cantarell 20
+[26:33] en Monospace 20
+[33:34] en Cantarell 20
+[34:43] en Cantarell Italic 20
+[43:44] en Cantarell 20
+[44:54] en Cantarell 20
+[54:55] en Cantarell 20
+[55:67] en Cantarell 20
+[67:72] en Cantarell 20
+[72:74] en Cantarell 20
+[74:78] en Cantarell 20
+[78:79] en Cantarell 20
+[79:2147483647] (null) Cantarell 20
diff --git a/tests/markups/convenience.markup b/tests/markups/convenience.markup
new file mode 100644
index 000000000..f019aa2ba
--- /dev/null
+++ b/tests/markups/convenience.markup
@@ -0,0 +1,12 @@
+<markup>
+<span font="Cantarell 20" lang="en">
+<b>be bold</b>
+<big>be big</big>
+<small>be small</small>
+<tt>go mono</tt>
+<i>be italic</i>
+<s>strike out</s>
+<u>underline it</u>
+this<sub>is</sub><sup>wild</sup>
+</span>
+</markup>
diff --git a/tests/markups/custom.expected b/tests/markups/custom.expected
new file mode 100644
index 000000000..e82d33248
--- /dev/null
+++ b/tests/markups/custom.expected
@@ -0,0 +1,147 @@
+
+
+ noto
+ size
+ style
+ weight
+ variant
+ stretch
+ red
+ red
+ not red
+ word
+ this is a sentence.
+ this is a paragraph.
+ smaller
+ larger
+ xx
+ double
+
+
+
+
+---
+
+range 0 1
+range 1 4
+1 160 font-desc "Cantarell 20"
+range 4 8
+1 160 font-desc "Cantarell 20"
+4 8 family "Noto Sans"
+range 8 11
+1 160 font-desc "Cantarell 20"
+range 11 15
+1 160 font-desc "Cantarell 20"
+11 15 size 30
+range 15 18
+1 160 font-desc "Cantarell 20"
+range 18 23
+1 160 font-desc "Cantarell 20"
+18 23 style italic
+range 23 26
+1 160 font-desc "Cantarell 20"
+range 26 32
+1 160 font-desc "Cantarell 20"
+26 32 weight 738
+range 32 35
+1 160 font-desc "Cantarell 20"
+range 35 42
+1 160 font-desc "Cantarell 20"
+35 42 variant small-caps
+range 42 45
+1 160 font-desc "Cantarell 20"
+range 45 52
+1 160 font-desc "Cantarell 20"
+45 52 stretch ultra-expanded
+range 52 55
+1 160 font-desc "Cantarell 20"
+range 55 58
+1 160 font-desc "Cantarell 20"
+55 58 foreground #ffff00000000ffff
+range 58 61
+1 160 font-desc "Cantarell 20"
+range 61 64
+1 160 font-desc "Cantarell 20"
+61 64 foreground #ffff00000000ffff
+range 64 67
+1 160 font-desc "Cantarell 20"
+range 67 74
+1 160 font-desc "Cantarell 20"
+67 74 background #0000aaaabbbbcccc
+range 74 77
+1 160 font-desc "Cantarell 20"
+range 77 81
+1 160 font-desc "Cantarell 20"
+77 81 word true
+range 81 84
+1 160 font-desc "Cantarell 20"
+range 84 103
+1 160 font-desc "Cantarell 20"
+84 103 sentence true
+range 103 106
+1 160 font-desc "Cantarell 20"
+range 106 126
+1 160 font-desc "Cantarell 20"
+106 126 sentence true
+range 126 129
+1 160 font-desc "Cantarell 20"
+range 129 136
+1 160 font-desc "Cantarell 20"
+129 136 size 17066
+range 136 139
+1 160 font-desc "Cantarell 20"
+range 139 145
+1 160 font-desc "Cantarell 20"
+139 145 size 24576
+range 145 148
+1 160 font-desc "Cantarell 20"
+range 148 150
+1 160 font-desc "Cantarell 20"
+148 150 scale 1.728000
+range 150 153
+1 160 font-desc "Cantarell 20"
+range 153 159
+1 160 font-desc "Cantarell 20"
+153 159 scale 2.000000
+range 159 160
+1 160 font-desc "Cantarell 20"
+range 160 2147483647
+
+
+---
+
+[0:1] (null) Normal
+[1:4] (null) Cantarell 20
+[4:8] (null) Noto Sans 20
+[8:11] (null) Cantarell 20
+[11:15] (null) Cantarell 0.029296875
+[15:18] (null) Cantarell 20
+[18:23] (null) Cantarell Italic 20
+[23:26] (null) Cantarell 20
+[26:32] (null) Cantarell weight=738 20
+[32:35] (null) Cantarell 20
+[35:42] (null) Cantarell Small-Caps 20
+[42:45] (null) Cantarell 20
+[45:52] (null) Cantarell Ultra-Expanded 20
+[52:55] (null) Cantarell 20
+[55:58] (null) Cantarell 20
+[58:61] (null) Cantarell 20
+[61:64] (null) Cantarell 20
+[64:67] (null) Cantarell 20
+[67:74] (null) Cantarell 20
+[74:77] (null) Cantarell 20
+[77:81] (null) Cantarell 20
+[81:84] (null) Cantarell 20
+[84:103] (null) Cantarell 20
+[103:106] (null) Cantarell 20
+[106:126] (null) Cantarell 20
+[126:129] (null) Cantarell 20
+[129:136] (null) Cantarell 16.666015625
+[136:139] (null) Cantarell 20
+[139:145] (null) Cantarell 24
+[145:148] (null) Cantarell 20
+[148:150] (null) Cantarell 34.5595703125
+[150:153] (null) Cantarell 20
+[153:159] (null) Cantarell 40
+[159:160] (null) Cantarell 20
+[160:2147483647] (null) Cantarell 20
diff --git a/tests/markups/custom.markup b/tests/markups/custom.markup
new file mode 100644
index 000000000..6556e3edf
--- /dev/null
+++ b/tests/markups/custom.markup
@@ -0,0 +1,20 @@
+<markup>
+<span font="Cantarell 20">
+ <span font_family="Noto Sans">noto</span>
+ <span font_size="30">size</span>
+ <span font_style="italic">style</span>
+ <span font_weight="738">weight</span>
+ <span font_variant="small-caps">variant</span>
+ <span font_stretch="ultra-expanded">stretch</span>
+ <span color="red">red</span>
+ <span fgcolor="#ff0000ff">red</span>
+ <span bgcolor="#00aabbcc">not red</span>
+ <span segment="word">word</span>
+ <span segment="sentence">this is a sentence.</span>
+ <span segment="paragraph">this is a paragraph.</span>
+ <span size="smaller">smaller</span>
+ <span size="larger">larger</span>
+ <span size="xx-large">xx</span>
+ <span size="200%">double</span>
+</span>
+</markup>
diff --git a/tests/testhbfont.c b/tests/testhbfont.c
index 6b6860a95..907492235 100644
--- a/tests/testhbfont.c
+++ b/tests/testhbfont.c
@@ -24,8 +24,6 @@
#include <gio/gio.h>
#include <pango/pangocairo.h>
#include <pango/pangofc-hbfontmap.h>
-#include <pango/pangofc-fontmap.h>
-#include <pango/pangofc-font.h>
#include <hb-ot.h>
@@ -540,294 +538,6 @@ test_hbfontmap_language (void)
pango_font_description_free (desc);
}
-static const char *
-get_font_file (PangoFont *font)
-{
- if (PANGO_IS_HB_FONT (font))
- {
- PangoFontFace *face = pango_font_get_face (font);
-
- return pango_hb_face_get_file (PANGO_HB_FACE (face));
- }
- else if (PANGO_IS_FC_FONT (font))
- {
- FcPattern *pattern = pango_fc_font_get_pattern (PANGO_FC_FONT (font));
- const char *file;
-
- FcPatternGetString (pattern, FC_FILE, 0, (FcChar8 **)&file);
-
- return file;
- }
- else
- return "Unknown";
-}
-
-typedef struct
-{
- FcConfig *config;
- PangoFontMap *fcfontmap;
- PangoFontMap *hbfontmap;
-} FontMapCompareFixture;
-
-static void
-fontmap_compare_fixture_set_up (FontMapCompareFixture *fixture,
- gconstpointer data)
-{
- char *path, *conf;
- FcConfig *config;
- PangoFontMap *fcfontmap, *hbfontmap;
-
- path = g_test_build_filename (G_TEST_DIST, "fonts", NULL);
- if (!g_path_is_absolute (path))
- {
- char *dir = g_build_filename (g_get_current_dir (), path, NULL);
- g_free (path);
- path = dir;
- }
-
- config = FcConfigCreate ();
-
- conf = g_build_filename (path, "fonts.conf", NULL);
- if (!FcConfigParseAndLoad (config, (const FcChar8 *) conf, TRUE))
- g_error ("Failed to parse fontconfig configuration from %s", conf);
-
- FcConfigAppFontAddDir (config, (const FcChar8 *) path);
-
- fcfontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
- pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (fcfontmap), config);
-
- hbfontmap = PANGO_FONT_MAP (pango_fc_hb_font_map_new ());
- pango_fc_hb_font_map_set_config (PANGO_FC_HB_FONT_MAP (hbfontmap), config);
-
- g_free (conf);
- g_free (path);
-
- fixture->config = config;
- fixture->fcfontmap = fcfontmap;
- fixture->hbfontmap = hbfontmap;
-}
-
-static void
-fontmap_compare_fixture_tear_down (FontMapCompareFixture *fixture,
- gconstpointer data)
-{
- g_object_unref (fixture->hbfontmap);
- g_object_unref (fixture->fcfontmap);
- FcConfigDestroy (fixture->config);
-}
-
-/* Check that we have the same families (we know
- * generics are different, so skip those)
- */
-
-static int
-compare_family_name (gconstpointer a,
- gconstpointer b)
-{
- return g_ascii_strcasecmp (*(const char **)a, *(const char **)b);
-}
-
-static gboolean
-is_generic_family (PangoFontFamily *fam)
-{
- return g_str_equal (G_OBJECT_TYPE_NAME (fam), "PangoGenericFamily");
-}
-
-static gboolean
-is_generic_family_name (const char *family)
-{
- return g_strv_contains ((const char *[]){ "Sans", "Serif", "Monospace", "System-ui", NULL}, family);
-}
-
-static const char * const *
-collect_nongeneric_families (PangoFontMap *map)
-{
- GPtrArray *array = g_ptr_array_new ();
-
- for (int i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (map)); i++)
- {
- PangoFontFamily *fam = g_list_model_get_item (G_LIST_MODEL (map), i);
- const char *name = pango_font_family_get_name (fam);
-
- if (!(is_generic_family (fam) || is_generic_family_name (name)))
- g_ptr_array_add (array, (gpointer)name);
-
- g_object_unref (fam);
- }
-
- g_ptr_array_sort (array, compare_family_name);
-
- g_ptr_array_add (array, NULL);
-
- return (const char * const *)g_ptr_array_free (array, FALSE);
-}
-
-static void
-test_hbfontmap_compare_families (FontMapCompareFixture *fixture,
- gconstpointer data)
-{
- const char * const *fcfamilies;
- const char * const *hbfamilies;
-
- fcfamilies = collect_nongeneric_families (fixture->fcfontmap);
- hbfamilies = collect_nongeneric_families (fixture->hbfontmap);
- g_assert_true (g_strv_equal (fcfamilies, hbfamilies));
- g_free ((gpointer)fcfamilies);
- g_free ((gpointer)hbfamilies);
-}
-
-static gboolean
-languages_equal (PangoLanguage **l1,
- PangoLanguage **l2)
-{
- int i;
-
- if (!l1 || !l2)
- return l1 == l2;
-
- for (i = 0; l1[i] && l2[i]; i++)
- if (l1[i] != l2[i])
- return FALSE;
-
- if (l1[i] || l2[i])
- return FALSE;
-
- return TRUE;
-}
-
-static void
-test_hbfontmap_compare_languages (FontMapCompareFixture *fixture,
- gconstpointer data)
-{
- const char *family_name = data;
- PangoContext *context;
- PangoFontDescription *description;
- PangoFont *fcfont, *hbfont;
- PangoLanguage **fclanguages;
- PangoLanguage **hblanguages;
-
- context = pango_font_map_create_context (fixture->fcfontmap);
-
- description = pango_font_description_new ();
- pango_font_description_set_family (description, family_name);
- pango_font_description_set_size (description, 12 * PANGO_SCALE);
-
- fcfont = pango_font_map_load_font (fixture->fcfontmap, context, description);
- hbfont = pango_font_map_load_font (fixture->hbfontmap, context, description);
-
- fclanguages = pango_font_get_languages (fcfont);
- hblanguages = pango_font_get_languages (hbfont);
-
- g_assert_nonnull (fclanguages);
- g_assert_nonnull (hblanguages);
- g_assert_true (languages_equal (fclanguages, hblanguages));
-
- g_object_unref (hbfont);
- g_object_unref (fcfont);
-
- pango_font_description_free (description);
-
- g_object_unref (context);
-}
-
-/* Compare the faces we get. We already know that hbfontmap adds
- * the variable font as an extra family, so skip those.
- */
-static int
-compare_face_name (gconstpointer a,
- gconstpointer b)
-{
- return strcmp (*(const char **)a, *(const char **)b);
-}
-
-static const char * const *
-collect_nonvariable_faces (PangoFontFamily *fam)
-{
- GPtrArray *array = g_ptr_array_new ();
-
- for (int i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (fam)); i++)
- {
- PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (fam), i);
- const char *name = pango_font_face_get_face_name (face);
-
- if (!pango_font_face_is_variable (face))
- g_ptr_array_add (array, (gpointer)name);
-
- g_object_unref (face);
- }
-
- g_ptr_array_sort (array, compare_face_name);
-
- g_ptr_array_add (array, NULL);
-
- return (const char * const *)g_ptr_array_free (array, FALSE);
-}
-
-static void
-test_hbfontmap_compare_faces (FontMapCompareFixture *fixture,
- gconstpointer data)
-{
- const char *family_name = data;
- PangoFontFamily *fcfamily, *hbfamily;
- const char * const *fcfaces;
- const char * const *hbfaces;
-
- fcfamily = pango_font_map_get_family (fixture->fcfontmap, family_name);
- hbfamily = pango_font_map_get_family (fixture->hbfontmap, family_name);
-
- fcfaces = collect_nonvariable_faces (fcfamily);
- hbfaces = collect_nonvariable_faces (hbfamily);
- if (!g_strv_equal (fcfaces, hbfaces))
- g_print ("%s\n%s\n", g_strjoinv (", ", (char **)fcfaces), g_strjoinv (", ", (char **)hbfaces));
- g_assert_true (g_strv_equal (fcfaces, hbfaces));
- g_free ((gpointer)fcfaces);
- g_free ((gpointer)hbfaces);
-}
-
-static void
-test_hbfontmap_compare_match (FontMapCompareFixture *fixture,
- gconstpointer data)
-{
- PangoContext *context;
- const char *tests[] = {
- "Amiri Bold 12",
- "Cantarell 12",
- "Sans 11",
- "sans-serif 11",
- "emoji 12",
- "emoji 12",
- "Cantarell Italic 11",
- "Sans Bold 11",
- };
-
- context = pango_font_map_create_context (fixture->fcfontmap);
- pango_context_set_language (context, pango_language_from_string ("en"));
-
-
- for (int i = 0; i < G_N_ELEMENTS (tests); i++)
- {
- PangoFontDescription *description;
- PangoFont *fcfont, *hbfont;
-
- description = pango_font_description_from_string (tests[i]);
-
- fcfont = pango_font_map_load_font (fixture->fcfontmap, context, description);
- hbfont = pango_font_map_load_font (fixture->hbfontmap, context, description);
-
- if (strcmp (get_font_file (fcfont), get_font_file (hbfont)) != 0)
- g_print ("test %s\n", tests[i]);
-
- g_assert_cmpstr (get_font_file (fcfont), ==, get_font_file (hbfont));
-
- g_object_unref (hbfont);
- g_object_unref (fcfont);
-
- pango_font_description_free (description);
- }
-
- g_object_unref (context);
-}
-
int
main (int argc, char *argv[])
{
@@ -842,30 +552,6 @@ main (int argc, char *argv[])
g_test_add_func ("/hbfont/load", test_hbfont_load);
g_test_add_func ("/hbfont/load/variation", test_hbfont_load_variation);
g_test_add_func ("/hbfontmap/language", test_hbfontmap_language);
- g_test_add ("/hbfontmap/families", FontMapCompareFixture, NULL,
- fontmap_compare_fixture_set_up,
- test_hbfontmap_compare_families,
- fontmap_compare_fixture_tear_down);
- g_test_add ("/hbfontmap/faces/Amiri", FontMapCompareFixture, "Amiri",
- fontmap_compare_fixture_set_up,
- test_hbfontmap_compare_faces,
- fontmap_compare_fixture_tear_down);
- g_test_add ("/hbfontmap/faces/Cantarell", FontMapCompareFixture, "Cantarell",
- fontmap_compare_fixture_set_up,
- test_hbfontmap_compare_faces,
- fontmap_compare_fixture_tear_down);
- g_test_add ("/hbfontmap/languages/Amiri", FontMapCompareFixture, "Amiri",
- fontmap_compare_fixture_set_up,
- test_hbfontmap_compare_languages,
- fontmap_compare_fixture_tear_down);
- g_test_add ("/hbfontmap/languages/Cantarell", FontMapCompareFixture, "Cantarell",
- fontmap_compare_fixture_set_up,
- test_hbfontmap_compare_languages,
- fontmap_compare_fixture_tear_down);
- g_test_add ("/hbfontmap/compare/match", FontMapCompareFixture, NULL,
- fontmap_compare_fixture_set_up,
- test_hbfontmap_compare_match,
- fontmap_compare_fixture_tear_down);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]