diff options
-rw-r--r-- | .gitlab-ci.yml | 11 | ||||
-rw-r--r-- | .gitlab-ci/list-msys2.sh | 5 | ||||
-rw-r--r-- | .gitlab-ci/render-msys2.sh | 5 | ||||
-rw-r--r-- | .gitlab-ci/test-msys2.sh | 3 | ||||
-rw-r--r-- | pango/pango-context.c | 1 | ||||
-rw-r--r-- | pango/pango-layout.c | 8 | ||||
-rw-r--r-- | pango/pangocairo-win32font.c | 7 | ||||
-rw-r--r-- | tests/layouts/valid-5.expected | 48 | ||||
-rw-r--r-- | tests/layouts/valid-5.markup | 3 | ||||
-rw-r--r-- | tests/test-font.c | 50 | ||||
-rw-r--r-- | utils/pango-list.c | 99 | ||||
-rw-r--r-- | utils/viewer-render.c | 10 |
12 files changed, 203 insertions, 47 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1a558544..a33020b5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,12 +24,17 @@ gnome-runtime-linux: script: - meson _build - ninja -C _build - - cd _build; meson test --suite pango + - meson test -C_build --suite pango + - _build/tests/test-font -p /pango/font/metrics --verbose + - _build/utils/pango-view --no-display --output _build/hello.png utils/HELLO.txt + - _build/utils/pango-list --verbose > _build/fontlist.txt artifacts: name: "%CI_JOB_NAME%-%CI_COMMIT_REF_NAME%" when: always paths: - _build/meson-logs + - _build/hello.png + - _build/fontlist.txt msys2-mingw64: stage: build @@ -41,8 +46,12 @@ msys2-mingw64: script: - C:\msys64\usr\bin\pacman --noconfirm -Syyuu - C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/test-msys2.sh" + - C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/render-msys2.sh" + - C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/list-msys2.sh" artifacts: name: "%CI_JOB_NAME%-%CI_COMMIT_REF_NAME%" when: always paths: - _build/meson-logs + - _build/hello.png + - _build/fontlist.txt diff --git a/.gitlab-ci/list-msys2.sh b/.gitlab-ci/list-msys2.sh new file mode 100644 index 00000000..e93e8e44 --- /dev/null +++ b/.gitlab-ci/list-msys2.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +PATH=_build/pango:$PATH _build/utils/pango-list --verbose --metrics > _build/fontlist.txt diff --git a/.gitlab-ci/render-msys2.sh b/.gitlab-ci/render-msys2.sh new file mode 100644 index 00000000..f81f0c60 --- /dev/null +++ b/.gitlab-ci/render-msys2.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +PATH=_build/pango:$PATH _build/utils/pango-view --no-display --output _build/hello.png utils/HELLO.txt diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh index 1338f9c6..7f513c77 100644 --- a/.gitlab-ci/test-msys2.sh +++ b/.gitlab-ci/test-msys2.sh @@ -19,7 +19,8 @@ pacman --noconfirm -S --needed \ mingw-w64-$MSYS2_ARCH-libthai \ mingw-w64-$MSYS2_ARCH-cairo \ mingw-w64-$MSYS2_ARCH-meson \ - mingw-w64-$MSYS2_ARCH-toolchain + mingw-w64-$MSYS2_ARCH-toolchain \ + mingw-w64-$MSYS2_ARCH-cantarell-fonts meson --buildtype debug _build cd _build diff --git a/pango/pango-context.c b/pango/pango-context.c index 6a5dcfdd..ca4c33b6 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -1762,6 +1762,7 @@ update_metrics_from_items (PangoFontMetrics *metrics, /* metrics will already be initialized from the first font in the fontset */ metrics->ascent = MAX (metrics->ascent, raw_metrics->ascent); metrics->descent = MAX (metrics->descent, raw_metrics->descent); + metrics->height = MAX (metrics->height, raw_metrics->height); pango_font_metrics_unref (raw_metrics); } diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 27d6bfe5..21897e29 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -4251,10 +4251,7 @@ pango_layout_check_lines (PangoLayout *layout) iter); if (no_break_attrs) - { - apply_no_break_attributes (state.items, no_break_attrs); - pango_attr_list_unref (no_break_attrs); - } + apply_no_break_attributes (state.items, no_break_attrs); get_items_log_attrs (start, delimiter_index + delim_len, @@ -4309,6 +4306,9 @@ pango_layout_check_lines (PangoLayout *layout) pango_attr_iterator_destroy (iter); pango_attr_list_unref (attrs); + if (no_break_attrs) + pango_attr_list_unref (no_break_attrs); + if (no_shape_attrs) { apply_no_shape_attributes (layout, no_shape_attrs); diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c index 2a8e9edf..9f4f5c14 100644 --- a/pango/pangocairo-win32font.c +++ b/pango/pangocairo-win32font.c @@ -86,7 +86,6 @@ pango_cairo_win32_font_create_base_metrics_for_context (PangoCairoFont *font, PangoFontMetrics *metrics; cairo_scaled_font_t *scaled_font; cairo_font_extents_t font_extents; - double height; metrics = pango_font_metrics_new (); @@ -101,11 +100,11 @@ pango_cairo_win32_font_create_base_metrics_for_context (PangoCairoFont *font, /* FIXME: Should get the real settings for these from the TrueType * font file. */ - height = metrics->ascent + metrics->descent; - metrics->underline_thickness = height / 14; + metrics->height = metrics->ascent + metrics->descent; + metrics->underline_thickness = metrics->height / 14; metrics->underline_position = - metrics->underline_thickness; metrics->strikethrough_thickness = metrics->underline_thickness; - metrics->strikethrough_position = height / 4; + metrics->strikethrough_position = metrics->height / 4; pango_quantize_line_geometry (&metrics->underline_thickness, &metrics->underline_position); diff --git a/tests/layouts/valid-5.expected b/tests/layouts/valid-5.expected new file mode 100644 index 00000000..5c6fa749 --- /dev/null +++ b/tests/layouts/valid-5.expected @@ -0,0 +1,48 @@ +A test with multiple paragraphs and with no-break attributes, which might trigger a crash. +If it doesn't the fix has worked. + +--- parameters + +wrapped: 1 +ellipsized: 0 +lines: 7 +width: 194560 + +--- attributes + +range 0 21 +range 21 31 +[21,31]font-features=tnum=1 +range 31 2147483647 + +--- lines + +i=1, index=0, paragraph-start=1, dir=ltr 'A test with multiple ' +i=2, index=21, paragraph-start=0, dir=ltr 'paragraphs and with no-' +i=3, index=44, paragraph-start=0, dir=ltr 'break attributes, which ' +i=4, index=68, paragraph-start=0, dir=ltr 'might trigger a crash. +' +i=5, index=91, paragraph-start=1, dir=ltr 'If it doesn't the fix has ' +i=6, index=117, paragraph-start=0, dir=ltr 'worked. +' +i=7, index=125, paragraph-start=1, dir=ltr '' + +--- runs + +i=1, index=0, chars=21, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'A test with multiple ' +[21,31]font-features=tnum=1 +i=2, index=21, no run, line end +i=3, index=21, chars=23, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'paragraphs and with no-' +[21,31]font-features=tnum=1 +i=4, index=44, no run, line end +i=5, index=44, chars=24, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'break attributes, which ' +[21,31]font-features=tnum=1 +i=6, index=68, no run, line end +i=7, index=68, chars=22, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'might trigger a crash.' +[21,31]font-features=tnum=1 +i=8, index=90, no run, line end +i=9, index=91, chars=26, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'If it doesn't the fix has ' +i=10, index=117, no run, line end +i=11, index=117, chars=7, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, 'worked.' +i=12, index=124, no run, line end +i=13, index=125, no run, line end diff --git a/tests/layouts/valid-5.markup b/tests/layouts/valid-5.markup new file mode 100644 index 00000000..2b2023ad --- /dev/null +++ b/tests/layouts/valid-5.markup @@ -0,0 +1,3 @@ +width=190 +A test with multiple <span font_features="tnum=1">paragraphs</span> and with no-break attributes, which might trigger a crash. +If it doesn't the fix has worked. diff --git a/tests/test-font.c b/tests/test-font.c index 76d00420..cea7356c 100644 --- a/tests/test-font.c +++ b/tests/test-font.c @@ -25,6 +25,8 @@ #include <pango/pangocairo.h> +static PangoContext *context; + static void test_parse (void) { @@ -114,6 +116,49 @@ test_variation (void) pango_font_description_free (desc2); } +static void +test_metrics (void) +{ + PangoFontDescription *desc; + PangoFontMetrics *metrics; + char *str; + + + if (strcmp (G_OBJECT_TYPE_NAME (pango_context_get_font_map (context)), "PangoCairoWin32FontMap") == 0) + desc = pango_font_description_from_string ("Verdana 11"); + else + desc = pango_font_description_from_string ("Cantarell 11"); + + str = pango_font_description_to_string (desc); + + metrics = pango_context_get_metrics (context, desc, pango_language_get_default ()); + + g_test_message ("%s metrics\n" + "\tascent %d\n" + "\tdescent %d\n" + "\theight %d\n" + "\tchar width %d\n" + "\tdigit width %d\n" + "\tunderline position %d\n" + "\tunderline thickness %d\n" + "\tstrikethrough position %d\n" + "\tstrikethrough thickness %d\n", + str, + pango_font_metrics_get_ascent (metrics), + pango_font_metrics_get_descent (metrics), + pango_font_metrics_get_height (metrics), + pango_font_metrics_get_approximate_char_width (metrics), + pango_font_metrics_get_approximate_digit_width (metrics), + pango_font_metrics_get_underline_position (metrics), + pango_font_metrics_get_underline_thickness (metrics), + pango_font_metrics_get_strikethrough_position (metrics), + pango_font_metrics_get_strikethrough_thickness (metrics)); + + pango_font_metrics_unref (metrics); + g_free (str); + pango_font_description_free (desc); +} + int main (int argc, char *argv[]) { @@ -122,9 +167,12 @@ main (int argc, char *argv[]) g_test_init (&argc, &argv, NULL); + context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); + + g_test_add_func ("/pango/font/metrics", test_metrics); g_test_add_func ("/pango/fontdescription/parse", test_parse); g_test_add_func ("/pango/fontdescription/roundtrip", test_roundtrip); g_test_add_func ("/pango/fontdescription/variation", test_variation); - + return g_test_run (); } diff --git a/utils/pango-list.c b/utils/pango-list.c index 642b09fc..7440e18b 100644 --- a/utils/pango-list.c +++ b/utils/pango-list.c @@ -23,20 +23,49 @@ #include "config.h" #include <pango/pangocairo.h> #include <glib/gstdio.h> +#include <stdlib.h> int main (int argc, char **argv) { + gboolean opt_verbose = FALSE; + gboolean opt_metrics = FALSE; + GOptionEntry entries[] = { + {"verbose", 0, 0, G_OPTION_ARG_NONE, &opt_verbose, "Print verbose information", NULL }, + {"metrics", 0, 0, G_OPTION_ARG_NONE, &opt_metrics, "Print font metrics", NULL }, + { NULL, } + }; + GOptionContext *context; + PangoContext *ctx; PangoFontMap *fontmap; PangoFontFamily **families; int n_families; - int i, j, k; + int i, j; + int width; + GError *error = NULL; g_set_prgname ("pango-list"); + context = g_option_context_new (""); + g_option_context_add_main_entries (context, entries, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + if (error != NULL) + g_error ("%s", error->message); + else + g_error ("Option parse error"); + exit (1); + } + + g_option_context_free (context); + /* Use PangoCairo to get default fontmap so it works on every platform. */ fontmap = pango_cairo_font_map_get_default (); + ctx = pango_font_map_create_context (fontmap); + + if (opt_verbose) + g_print ("Using %s\n\n", G_OBJECT_TYPE_NAME (fontmap)); pango_font_map_list_families (fontmap, &families, &n_families); for (i = 0; i < n_families; i++) @@ -64,42 +93,48 @@ main (int argc, g_print ("%s %s\n", family_name, kind); pango_font_family_list_faces (families[i], &faces, &n_faces); + + width = 0; + for (j = 0; j < n_faces; j++) + { + const char *face_name = pango_font_face_get_face_name (faces[j]); + gboolean is_synth = pango_font_face_is_synthesized (faces[j]); + const char *synth_str = is_synth ? "*" : ""; + width = MAX (width, strlen (synth_str) + strlen (face_name)); + } + for (j = 0; j < n_faces; j++) { const char *face_name = pango_font_face_get_face_name (faces[j]); gboolean is_synth = pango_font_face_is_synthesized (faces[j]); const char *synth_str = is_synth ? "*" : ""; - g_print (" %s%s\n", synth_str, face_name); - - if (0) - { - int *sizes; - int n_sizes; - pango_font_face_list_sizes (faces[j], &sizes, &n_sizes); - if (n_sizes) - { - g_print (" {"); - for (k = 0; k < n_sizes; k++) - { - if (k) - g_print (", "); - g_print ("%g", pango_units_to_double (sizes[k])); - } - g_print ("}\n"); - } - g_free (sizes); - } - - if (1) - { - PangoFontDescription *desc = pango_font_face_describe (faces[j]); - char *desc_str = pango_font_description_to_string (desc); - - g_print (" \"%s\"\n", desc_str); - - g_free (desc_str); - pango_font_description_free (desc); - } + PangoFontDescription *desc = pango_font_face_describe (faces[j]); + char *desc_str = pango_font_description_to_string (desc); + + g_print (" %s%s: %*s%s\n", synth_str, face_name, + width - (int)strlen (face_name) - (int)strlen (synth_str), "", desc_str); + + if (opt_metrics) + { + PangoFontMetrics *metrics; + + pango_font_description_set_absolute_size (desc, 10 * PANGO_SCALE); + metrics = pango_context_get_metrics (ctx, desc, pango_language_from_string ("en-us")); + g_print (" (a %d d %d h %d cw %d dw %d u %d %d s %d %d)\n", + pango_font_metrics_get_ascent (metrics), + pango_font_metrics_get_descent (metrics), + pango_font_metrics_get_height (metrics), + pango_font_metrics_get_approximate_char_width (metrics), + pango_font_metrics_get_approximate_digit_width (metrics), + pango_font_metrics_get_underline_position (metrics), + pango_font_metrics_get_underline_thickness (metrics), + pango_font_metrics_get_strikethrough_position (metrics), + pango_font_metrics_get_strikethrough_thickness (metrics)); + pango_font_metrics_unref (metrics); + } + + g_free (desc_str); + pango_font_description_free (desc); } g_free (faces); diff --git a/utils/viewer-render.c b/utils/viewer-render.c index 5a556cd8..8fd6cfaf 100644 --- a/utils/viewer-render.c +++ b/utils/viewer-render.c @@ -52,7 +52,7 @@ int opt_width = -1; int opt_height = -1; int opt_indent = 0; int opt_spacing = 0; -double opt_line_spacing = 0.0; +double opt_line_spacing = -1.0; gboolean opt_justify = 0; int opt_runs = 1; PangoAlignment opt_align = PANGO_ALIGN_LEFT; @@ -125,9 +125,11 @@ make_layout(PangoContext *context, pango_layout_set_indent (layout, (opt_indent * opt_dpi * PANGO_SCALE + 36) / 72); if (opt_spacing != 0) - pango_layout_set_spacing (layout, (opt_spacing * opt_dpi * PANGO_SCALE + 36) / 72); - - if (opt_line_spacing != 0.0) + { + pango_layout_set_spacing (layout, (opt_spacing * opt_dpi * PANGO_SCALE + 36) / 72); + pango_layout_set_line_spacing (layout, 0.0); + } + if (opt_line_spacing >= 0.0) pango_layout_set_line_spacing (layout, (float)opt_line_spacing); align = opt_align; |