From 98af928b7dc65ed0bcd2680eaba43c32ef5f5b77 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 6 Nov 2020 22:29:28 -0500 Subject: tests: Don't free attributes prematurely test-shape was using one of its attribute lists after dropping the reference on it. Don't do that. (cherry-picked from commit 17d8202d) --- tests/test-shape.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-shape.c b/tests/test-shape.c index c2488dbf..feca154e 100644 --- a/tests/test-shape.c +++ b/tests/test-shape.c @@ -185,8 +185,6 @@ test_file (const gchar *filename, GString *string) pango_attr_list_unref (itemize_attrs); pango_attr_list_unref (shape_attrs); - pango_attr_list_unref (attrs); - for (l = items; l; l = l->next) { PangoItem *item = l->data; @@ -281,6 +279,8 @@ test_file (const gchar *filename, GString *string) g_list_free_full (items, (GDestroyNotify)pango_item_free); g_free (contents); g_free (text); + + pango_attr_list_unref (attrs); } static gchar * -- cgit v1.2.1 From 75950565d2a6e4d098849df60997ebfbf221e2a2 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Thu, 14 Jan 2021 20:37:05 -0800 Subject: Fix the length checking Closes #526 (cherry-picked from commit 0a816b49) --- pango/pango-context.c | 2 +- tests/testmisc.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pango/pango-context.c b/pango/pango-context.c index 1fcdf366..a3d7e6c4 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -1572,7 +1572,7 @@ pango_itemize_with_base_dir (PangoContext *context, g_return_val_if_fail (length >= 0, NULL); g_return_val_if_fail (length == 0 || text != NULL, NULL); - if (length == 0 || g_utf8_strlen (text, length) == 0) + if (length == 0 || g_utf8_strlen (text + start_index, length) == 0) return NULL; itemize_state_init (&state, context, text, base_dir, start_index, length, diff --git a/tests/testmisc.c b/tests/testmisc.c index 2f6c148b..48f60ee9 100644 --- a/tests/testmisc.c +++ b/tests/testmisc.c @@ -54,6 +54,19 @@ test_itemize_empty_crash (void) g_object_unref (context); } +static void +test_itemize_utf8 (void) +{ + PangoContext *context; + GList *result = NULL; + + context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); + result = pango_itemize_with_base_dir (context, PANGO_DIRECTION_LTR, "\xc3\xa1\na", 3, 1, NULL, NULL); + g_assert (result != NULL); + + g_object_unref (context); +} + /* Test that pango_layout_set_text (layout, "short", 200) * does not lead to a crash. (pidgin does this) */ @@ -94,6 +107,7 @@ main (int argc, char *argv[]) g_test_add_func ("/layout/shape-tab-crash", test_shape_tab_crash); g_test_add_func ("/layout/itemize-empty-crash", test_itemize_empty_crash); + g_test_add_func ("/layout/itemize-utf8", test_itemize_utf8); g_test_add_func ("/layout/short-string-crash", test_short_string_crash); g_test_add_func ("/language/emoji-crash", test_language_emoji_crash); -- cgit v1.2.1 From cdfade7c9c864486f83220e2acff29b7f0553722 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 14 Jan 2020 16:15:17 +0800 Subject: Translate origin point for vertical layout The origin point for vertical layout needs to be translated for cairo rendering from the horizontal origin to the vertical origin. (cherry-picked from commit 4c6f0b3c) --- pango/pangofc-shape.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pango/pangofc-shape.c b/pango/pangofc-shape.c index b6f74ca1..16d5d84d 100644 --- a/pango/pangofc-shape.c +++ b/pango/pangofc-shape.c @@ -409,9 +409,12 @@ pango_hb_shape (PangoFont *font, for (i = 0; i < num_glyphs; i++) { /* 90 degrees rotation counter-clockwise. */ - infos[i].geometry.width = hb_position->y_advance; - infos[i].geometry.x_offset = hb_position->y_offset; - infos[i].geometry.y_offset = - hb_position->x_offset; + hb_position_t x_origin = 0, y_origin = 0; + hb_font_get_glyph_v_origin + (hb_font, infos[i].glyph, &x_origin, &y_origin); + infos[i].geometry.width = - hb_position->y_advance; + infos[i].geometry.x_offset = - hb_position->y_offset - y_origin; + infos[i].geometry.y_offset = - hb_position->x_offset - x_origin; hb_position++; } else /* horizontal */ -- cgit v1.2.1 From 634621b09e232bf51a9c89c177743dbc851e543a Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 17 Mar 2021 14:37:13 +0100 Subject: Fix placement of marks in upright vertical text. (cherry-picked from commit 3396cc20) --- pango/pangofc-fontmap.c | 5 ++--- pango/pangofc-shape.c | 7 ++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index 341b2d6c..35187c7c 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -1614,7 +1614,6 @@ pango_fc_make_pattern (const PangoFontDescription *description, int slant; double weight; PangoGravity gravity; - FcBool vertical; char **families; int i; int width; @@ -1625,7 +1624,6 @@ pango_fc_make_pattern (const PangoFontDescription *description, width = pango_fc_convert_width_to_fc (pango_font_description_get_stretch (description)); gravity = pango_font_description_get_gravity (description); - vertical = PANGO_GRAVITY_IS_VERTICAL (gravity) ? FcTrue : FcFalse; /* The reason for passing in FC_SIZE as well as FC_PIXEL_SIZE is * to work around a bug in libgnomeprint where it doesn't look @@ -1634,13 +1632,14 @@ pango_fc_make_pattern (const PangoFontDescription *description, * Putting FC_SIZE in here slightly reduces the efficiency * of caching of patterns and fonts when working with multiple different * dpi values. + * + * Do not pass FC_VERTICAL_LAYOUT true as HarfBuzz shaping assumes false. */ pattern = FcPatternBuild (NULL, PANGO_FC_VERSION, FcTypeInteger, pango_version(), FC_WEIGHT, FcTypeDouble, weight, FC_SLANT, FcTypeInteger, slant, FC_WIDTH, FcTypeInteger, width, - FC_VERTICAL_LAYOUT, FcTypeBool, vertical, #ifdef FC_VARIABLE FC_VARIABLE, FcTypeBool, FcDontCare, #endif diff --git a/pango/pangofc-shape.c b/pango/pangofc-shape.c index 16d5d84d..5c716b24 100644 --- a/pango/pangofc-shape.c +++ b/pango/pangofc-shape.c @@ -409,12 +409,9 @@ pango_hb_shape (PangoFont *font, for (i = 0; i < num_glyphs; i++) { /* 90 degrees rotation counter-clockwise. */ - hb_position_t x_origin = 0, y_origin = 0; - hb_font_get_glyph_v_origin - (hb_font, infos[i].glyph, &x_origin, &y_origin); infos[i].geometry.width = - hb_position->y_advance; - infos[i].geometry.x_offset = - hb_position->y_offset - y_origin; - infos[i].geometry.y_offset = - hb_position->x_offset - x_origin; + infos[i].geometry.x_offset = - hb_position->y_offset; + infos[i].geometry.y_offset = - hb_position->x_offset; hb_position++; } else /* horizontal */ -- cgit v1.2.1 From 1355ed7416fc9119bac36e8937b900d908b6bf93 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 24 Jan 2021 11:15:01 -0500 Subject: Fix pango_font_describe for Emoji fonts We are using the size from the FcPattern. For scalable bitmap fonts, this has been scaled to match the requested pixel size. To make a font description that can be turned back into a FcPattern and roundtrip successfully, we need to undo that scaling. Thankfully, fontconfig leaves the pixelsizefixupfactor in the pattern, so it is easy to do. Fixes: #530 (cherry-picked from commit bc973fdb) --- pango/pangofc-fontmap.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index 35187c7c..3c31409e 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -2438,7 +2438,24 @@ pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_siz pango_font_description_set_variant (desc, PANGO_VARIANT_NORMAL); if (include_size && FcPatternGetDouble (pattern, FC_SIZE, 0, &size) == FcResultMatch) - pango_font_description_set_size (desc, size * PANGO_SCALE); + { + FcMatrix *fc_matrix; + double scale_factor = 1; + + if (FcPatternGetMatrix (pattern, FC_MATRIX, 0, &fc_matrix) == FcResultMatch) + { + PangoMatrix mat = PANGO_MATRIX_INIT; + + mat.xx = fc_matrix->xx; + mat.xy = fc_matrix->xy; + mat.yx = fc_matrix->yx; + mat.yy = fc_matrix->yy; + + scale_factor = pango_matrix_get_font_scale_factor (&mat); + } + + pango_font_description_set_size (desc, scale_factor * size * PANGO_SCALE); + } /* gravity is a bit different. we don't want to set it if it was not set on * the pattern */ -- cgit v1.2.1 From ea64ab44d0e89f9e0e656a360c5c14a0f13cd28d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 24 Jan 2021 11:02:21 -0500 Subject: tests: Add tests for pango_font_describe Test that round-tripping through pango_font_describe works. This is currently broken for scalable bitmap fonts, such as color Emoji fonts. We skip the test on OS X where we are most likely missing the fonts. (cherry-picked from commit 49b1f80a834) --- tests/meson.build | 2 ++ tests/test-font.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/tests/meson.build b/tests/meson.build index 6e10e2b7..6f08c240 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -8,6 +8,8 @@ endif if host_system == 'windows' test_cflags += '-DHAVE_WIN32' +elif host_system == 'darwin' + test_cflags += '-DHAVE_CARBON' endif test_env = environment() diff --git a/tests/test-font.c b/tests/test-font.c index 486504f9..88e3cdc9 100644 --- a/tests/test-font.c +++ b/tests/test-font.c @@ -240,7 +240,74 @@ test_enumerate (void) g_object_unref (font); pango_font_description_free (desc); g_free (faces); - g_free (families); + g_free (families); + g_object_unref (context); +} + +static void +test_roundtrip_plain (void) +{ + PangoFontMap *fontmap; + PangoContext *context; + PangoFontDescription *desc, *desc2; + PangoFont *font; + +#ifdef HAVE_CARBON + /* We probably don't have the right fonts */ + g_test_skip ("Skipping font-dependent tests on OS X"); + return; +#endif + + fontmap = pango_cairo_font_map_get_default (); + context = pango_font_map_create_context (fontmap); + + desc = pango_font_description_from_string ("Cantarell 11"); + + font = pango_context_load_font (context, desc); + desc2 = pango_font_describe (font); + + g_assert (pango_font_description_equal (desc2, desc)); + + pango_font_description_free (desc2); + g_object_unref (font); + pango_font_description_free (desc); + g_object_unref (context); +} + +static void +test_roundtrip_emoji (void) +{ + PangoFontMap *fontmap; + PangoContext *context; + PangoFontDescription *desc, *desc2; + PangoFont *font; + +#ifdef HAVE_CARBON + /* We probably don't have the right fonts */ + g_test_skip ("Skipping font-dependent tests on OS X"); + return; +#endif + + fontmap = pango_cairo_font_map_get_default (); + context = pango_font_map_create_context (fontmap); + + /* This is how pango_itemize creates the emoji font desc */ + desc = pango_font_description_from_string ("Cantarell 11"); + pango_font_description_set_family_static (desc, "emoji"); + + font = pango_context_load_font (context, desc); + desc2 = pango_font_describe (font); + + /* We can't expect the family name to match, since we go in with + * a generic family + */ + pango_font_description_unset_fields (desc, PANGO_FONT_MASK_FAMILY); + pango_font_description_unset_fields (desc2, PANGO_FONT_MASK_FAMILY); + g_assert (pango_font_description_equal (desc2, desc)); + + pango_font_description_free (desc2); + g_object_unref (font); + pango_font_description_free (desc); g_object_unref (context); g_object_unref (fontmap); } @@ -261,6 +328,8 @@ main (int argc, char *argv[]) g_test_add_func ("/pango/fontdescription/variation", test_variation); g_test_add_func ("/pango/font/extents", test_extents); g_test_add_func ("/pango/font/enumerate", test_enumerate); + g_test_add_func ("/pango/font/roundtrip/plain", test_roundtrip_plain); + g_test_add_func ("/pango/font/roundtrip/emoji", test_roundtrip_emoji); return g_test_run (); } -- cgit v1.2.1 From d59071e02bbc3e6732cf8176e41ef2cc3adb1849 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 2 Mar 2021 20:58:15 -0500 Subject: markup: Fix two bugs The docs state that all chars marked with the accel marker get an underline. But we were only underlining the first in each text chunk. Second, if an underline appears at the end of a text chunk, or at the end of the text, we would just eat it, which is unexpected. (cherry-picked from commit 8d1ea2ae) --- pango/pango-markup.c | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/pango/pango-markup.c b/pango/pango-markup.c index b74c1ad4..d0b47016 100644 --- a/pango/pango-markup.c +++ b/pango/pango-markup.c @@ -677,8 +677,21 @@ text_handler (GMarkupParseContext *context G_GNUC_UNUSED, /* The underline should go underneath the char * we're setting as the next range_start */ - uline_index = md->index; - uline_len = g_utf8_next_char (p) - p; + if (md->attr_list != NULL) + { + /* Add the underline indicating the accelerator */ + PangoAttribute *attr; + + attr = pango_attr_underline_new (PANGO_UNDERLINE_LOW); + + uline_index = md->index; + uline_len = g_utf8_next_char (p) - p; + + attr->start_index = uline_index; + attr->end_index = uline_index + uline_len; + + pango_attr_list_change (md->attr_list, attr); + } /* set next range_start to include this char */ range_start = p; @@ -693,35 +706,12 @@ text_handler (GMarkupParseContext *context G_GNUC_UNUSED, } p = g_utf8_next_char (p); - } - - if (range_end) - { - g_string_append_len (md->text, - range_start, - range_end - range_start); - md->index += range_end - range_start; - } - else - { - g_string_append_len (md->text, - range_start, - end - range_start); - md->index += end - range_start; - } - - if (md->attr_list != NULL && uline_index >= 0) - { - /* Add the underline indicating the accelerator */ - PangoAttribute *attr; - - attr = pango_attr_underline_new (PANGO_UNDERLINE_LOW); - - attr->start_index = uline_index; - attr->end_index = uline_index + uline_len; + } - pango_attr_list_change (md->attr_list, attr); - } + g_string_append_len (md->text, + range_start, + end - range_start); + md->index += end - range_start; } } -- cgit v1.2.1 From 00e222ab045f0956c16621aaadab4c76248f9bdb Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 17 Mar 2021 22:49:38 -0400 Subject: Improve letterspacing with marks harfbuzz puts marks into their own clusters, so we need to work a little harder to keep non-spacing marks placed over their base character. Fixes: #541 (cherry-picked from commit fdc432bc) --- pango/pango-glyph-item.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pango/pango-glyph-item.c b/pango/pango-glyph-item.c index 326ae37f..e38de730 100644 --- a/pango/pango-glyph-item.c +++ b/pango/pango-glyph-item.c @@ -753,7 +753,16 @@ pango_glyph_item_letter_space (PangoGlyphItem *glyph_item, have_cluster = pango_glyph_item_iter_next_cluster (&iter)) { if (!log_attrs[iter.start_char].is_cursor_position) - continue; + { + if (glyphs[iter.start_glyph].geometry.width == 0) + { + if (iter.start_glyph < iter.end_glyph) /* LTR */ + glyphs[iter.start_glyph].geometry.x_offset -= space_right; + else + glyphs[iter.start_glyph].geometry.x_offset += space_left; + } + continue; + } if (iter.start_glyph < iter.end_glyph) /* LTR */ { -- cgit v1.2.1