diff options
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | docs/pango-sections.txt | 1 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | pango/pango-attributes.h | 7 | ||||
-rw-r--r-- | pango/pango-color.c | 89 | ||||
-rw-r--r-- | pango/pango-layout.c | 1 | ||||
-rw-r--r-- | pango/pango-markup.c | 6 | ||||
-rw-r--r-- | pango/pango-ot-private.h | 2 | ||||
-rw-r--r-- | pango/pango-ot-tag.c | 4 | ||||
-rw-r--r-- | pango/pango-utils-internal.h | 4 | ||||
-rw-r--r-- | pango/pangofc-shape.c | 4 | ||||
-rw-r--r-- | tests/test-break.c | 14 | ||||
-rw-r--r-- | tests/test-common.c | 12 | ||||
-rw-r--r-- | tests/test-itemize.c | 3 | ||||
-rw-r--r-- | tests/test-layout.c | 3 | ||||
-rw-r--r-- | tests/testboundaries_ucd.c | 3 | ||||
-rw-r--r-- | tests/testcolor.c | 114 | ||||
-rw-r--r-- | tests/testmisc.c | 20 |
18 files changed, 204 insertions, 92 deletions
@@ -1,3 +1,10 @@ +Overview of changes in 1.45.4 +============================= +- Fix build on Windows +- Fix a pidgin crash +- fc: Always reject unsupported font formats +- coretext: Fix cairo scaling + Overview of changes in 1.45.3 ============================= - Fix pango_attr_list_change diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt index 4648816b..04b6b442 100644 --- a/docs/pango-sections.txt +++ b/docs/pango-sections.txt @@ -423,6 +423,7 @@ PangoShowFlags pango_attr_show_new PangoColor pango_color_parse +pango_color_parse_with_alpha pango_color_copy pango_color_free pango_color_to_string diff --git a/meson.build b/meson.build index c0b228ea..57704c6e 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('pango', 'c', 'cpp', - version: '1.45.3', + version: '1.45.5', license: 'LGPLv2.1+', default_options: [ 'buildtype=debugoptimized', diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index 6f6622ab..dd38aee2 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -65,7 +65,12 @@ PANGO_AVAILABLE_IN_ALL void pango_color_free (PangoColor *color); PANGO_AVAILABLE_IN_ALL gboolean pango_color_parse (PangoColor *color, - const char *spec); + const char *spec); +PANGO_AVAILABLE_IN_1_46 +gboolean pango_color_parse_with_alpha + (PangoColor *color, + guint16 *alpha, + const char *spec); PANGO_AVAILABLE_IN_1_16 gchar *pango_color_to_string(const PangoColor *color); diff --git a/pango/pango-color.c b/pango/pango-color.c index 3c37c3d0..9c044810 100644 --- a/pango/pango-color.c +++ b/pango/pango-color.c @@ -207,20 +207,40 @@ hex (const char *spec, } -/* Like pango_color_parse, but allow strings of the form +/** + * pango_color_parse_with_alpha: + * @color: (nullable): a #PangoColor structure in which to store the + * result, or %NULL + * @alpha: (nullable): return location for alpha, or %NULL + * @spec: a string specifying the new color + * + * Fill in the fields of a color from a string specification. The + * string can either one of a large set of standard names. (Taken + * from the CSS <ulink url="http://dev.w3.org/csswg/css-color/#named-colors">specification</ulink>), or it can be a hexadecimal + * value in the + * form '#rgb' '#rrggbb' '#rrrgggbbb' or '#rrrrggggbbbb' where + * 'r', 'g' and 'b' are hex digits of the red, green, and blue + * components of the color, respectively. (White in the four + * forms is '#fff' '#ffffff' '#fffffffff' and '#ffffffffffff') + * + * Additionally, parse strings of the form * '#rgba', '#rrggbbaa', '#rrrrggggbbbbaaaa', - * if alpha is not NULL. If no alpha component is found - * in the string, *alpha is set to 0. + * if @alpha is not %NULL, and set @alpha to the value specified + * by the hex digits for 'a'. If no alpha component is found + * in @spec, @alpha is set to 0xffff (for a solid color). + * + * Return value: %TRUE if parsing of the specifier succeeded, + * otherwise false. */ gboolean -_pango_color_parse_with_alpha (PangoColor *color, - guint16 *alpha, - const char *spec) +pango_color_parse_with_alpha (PangoColor *color, + guint16 *alpha, + const char *spec) { g_return_val_if_fail (spec != NULL, FALSE); if (alpha) - *alpha = 0; + *alpha = 0xffff; if (spec[0] == '#') { @@ -248,52 +268,53 @@ _pango_color_parse_with_alpha (PangoColor *color, has_alpha = TRUE; break; default: - return FALSE; + return FALSE; } if (!hex (spec, len, &r) || - !hex (spec + len, len, &g) || - !hex (spec + len * 2, len, &b) || + !hex (spec + len, len, &g) || + !hex (spec + len * 2, len, &b) || (has_alpha && !hex (spec + len * 3, len, &a))) - return FALSE; + return FALSE; if (color) - { - int bits = len * 4; - r <<= 16 - bits; - g <<= 16 - bits; - b <<= 16 - bits; - while (bits < 16) - { - r |= (r >> bits); - g |= (g >> bits); - b |= (b >> bits); - bits *= 2; - } - color->red = r; - color->green = g; - color->blue = b; - } + { + int bits = len * 4; + r <<= 16 - bits; + g <<= 16 - bits; + b <<= 16 - bits; + while (bits < 16) + { + r |= (r >> bits); + g |= (g >> bits); + b |= (b >> bits); + bits *= 2; + } + color->red = r; + color->green = g; + color->blue = b; + } if (alpha && has_alpha) { - int bits = len * 4; + int bits = len * 4; a <<= 16 - bits; - while (bits < 16) - { + while (bits < 16) + { a |= (a >> bits); - bits *= 2; - } + bits *= 2; + } *alpha = a; } } else { if (!find_color (spec, color)) - return FALSE; + return FALSE; } return TRUE; } + /** * pango_color_parse: * @color: (nullable): a #PangoColor structure in which to store the @@ -316,5 +337,5 @@ gboolean pango_color_parse (PangoColor *color, const char *spec) { - return _pango_color_parse_with_alpha (color, NULL, spec); + return pango_color_parse_with_alpha (color, NULL, spec); } diff --git a/pango/pango-layout.c b/pango/pango-layout.c index b07c8487..92d858b2 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -1173,6 +1173,7 @@ pango_layout_set_text (PangoLayout *layout, g_warning ("Invalid UTF-8 string passed to pango_layout_set_text()"); layout->n_chars = pango_utf8_strlen (layout->text, -1); + layout->length = strlen (layout->text); layout_changed (layout); diff --git a/pango/pango-markup.c b/pango/pango-markup.c index a67e10fd..b74c1ad4 100644 --- a/pango/pango-markup.c +++ b/pango/pango-markup.c @@ -1199,7 +1199,7 @@ span_parse_color (const char *attr_name, int line_number, GError **error) { - if (!_pango_color_parse_with_alpha (color, alpha, attr_val)) + if (!pango_color_parse_with_alpha (color, alpha, attr_val)) { g_set_error (error, G_MARKUP_ERROR, @@ -1622,7 +1622,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED, goto error; add_attribute (tag, pango_attr_foreground_new (color.red, color.green, color.blue)); - if (alpha != 0) + if (alpha != 0xffff) add_attribute (tag, pango_attr_foreground_alpha_new (alpha)); } @@ -1635,7 +1635,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED, goto error; add_attribute (tag, pango_attr_background_new (color.red, color.green, color.blue)); - if (alpha != 0) + if (alpha != 0xffff) add_attribute (tag, pango_attr_background_alpha_new (alpha)); } diff --git a/pango/pango-ot-private.h b/pango/pango-ot-private.h index 0d803ec1..d9d86644 100644 --- a/pango/pango-ot-private.h +++ b/pango/pango-ot-private.h @@ -22,12 +22,12 @@ #ifndef __PANGO_OT_PRIVATE_H__ #define __PANGO_OT_PRIVATE_H__ +#include <glib.h> #include <glib-object.h> #include <pango/pango-ot.h> #include <hb-ot.h> #include <hb-ft.h> -#include <hb-glib.h> #include "pangofc-private.h" diff --git a/pango/pango-ot-tag.c b/pango/pango-ot-tag.c index c4f337e8..5f50b77c 100644 --- a/pango/pango-ot-tag.c +++ b/pango/pango-ot-tag.c @@ -49,7 +49,7 @@ pango_ot_tag_from_script (PangoScript script) unsigned int count = 1; hb_tag_t tags[1]; - hb_ot_tags_from_script_and_language (hb_glib_script_to_script ((GUnicodeScript)script), + hb_ot_tags_from_script_and_language ((hb_script_t) g_unicode_script_to_iso15924 ((GUnicodeScript) script), HB_LANGUAGE_INVALID, &count, tags, @@ -84,7 +84,7 @@ pango_ot_tag_from_script (PangoScript script) PangoScript pango_ot_tag_to_script (PangoOTTag script_tag) { - return (PangoScript) hb_glib_script_from_script (hb_ot_tag_to_script ((hb_tag_t) script_tag)); + return (PangoScript) g_unicode_script_from_iso15924 (hb_ot_tag_to_script ((hb_tag_t) script_tag)); } diff --git a/pango/pango-utils-internal.h b/pango/pango-utils-internal.h index 56340215..0bc355e0 100644 --- a/pango/pango-utils-internal.h +++ b/pango/pango-utils-internal.h @@ -43,10 +43,6 @@ gboolean pango_parse_flags (GType type, char *_pango_trim_string (const char *str); -gboolean _pango_color_parse_with_alpha (PangoColor *color, - guint16 *alpha, - const char *spec); - G_END_DECLS diff --git a/pango/pangofc-shape.c b/pango/pangofc-shape.c index 9fe193f6..b6f74ca1 100644 --- a/pango/pangofc-shape.c +++ b/pango/pangofc-shape.c @@ -29,7 +29,7 @@ #include "pangohb-private.h" #include "pango-impl-utils.h" -#include <hb-glib.h> +#include <glib.h> /* cache a single hb_buffer_t */ static hb_buffer_t *cached_buffer = NULL; /* MT-safe */ @@ -359,7 +359,7 @@ pango_hb_shape (PangoFont *font, /* setup buffer */ hb_buffer_set_direction (hb_buffer, hb_direction); - hb_buffer_set_script (hb_buffer, hb_glib_script_to_script (analysis->script)); + hb_buffer_set_script (hb_buffer, (hb_script_t) g_unicode_script_to_iso15924 (analysis->script)); hb_buffer_set_language (hb_buffer, hb_language_from_string (pango_language_to_string (analysis->language), -1)); hb_buffer_set_cluster_level (hb_buffer, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS); hb_buffer_set_flags (hb_buffer, hb_buffer_flags); diff --git a/tests/test-break.c b/tests/test-break.c index df9b78e2..6f4019e1 100644 --- a/tests/test-break.c +++ b/tests/test-break.c @@ -34,7 +34,7 @@ static PangoContext *context; -static void +static gboolean test_file (const gchar *filename, GString *string) { gchar *contents; @@ -73,9 +73,13 @@ test_file (const gchar *filename, GString *string) if (pango_layout_get_unknown_glyphs_count (layout) > 0) { +#if 0 + // See https://github.com/mesonbuild/meson/issues/7515 char *msg = g_strdup_printf ("Missing glyphs - skipping %s. Maybe fonts are missing?", filename); g_test_skip (msg); g_free (msg); +#endif + return FALSE; } pango_layout_get_log_attrs (layout, &attrs, &len); @@ -222,6 +226,8 @@ test_file (const gchar *filename, GString *string) g_free (attrs); g_free (contents); pango_attr_list_unref (attributes); + + return TRUE; } static gchar * @@ -253,9 +259,12 @@ test_break (gconstpointer d) setlocale (LC_ALL, "en_US.utf8"); if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL) { +#if 0 + // See https://github.com/mesonbuild/meson/issues/7515 char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping break %s", filename); g_test_skip (msg); g_free (msg); +#endif return; } @@ -263,7 +272,8 @@ test_break (gconstpointer d) dump = g_string_sized_new (0); - test_file (filename, dump); + if (!test_file (filename, dump)) + return; diff = diff_with_file (expected_file, dump->str, dump->len, &error); g_assert_no_error (error); diff --git a/tests/test-common.c b/tests/test-common.c index 786973f1..60ecb7e1 100644 --- a/tests/test-common.c +++ b/tests/test-common.c @@ -125,14 +125,22 @@ print_attribute (PangoAttribute *attr, GString *string) g_string_append_printf (string, "%d", ((PangoAttrInt *)attr)->value); break; case PANGO_ATTR_FONT_DESC: - g_string_append_printf (string, "%s", pango_font_description_to_string (((PangoAttrFontDesc *)attr)->desc)); + { + char *text = pango_font_description_to_string (((PangoAttrFontDesc *)attr)->desc); + g_string_append_printf (string, "%s", text); + g_free (text); + } break; case PANGO_ATTR_FOREGROUND: case PANGO_ATTR_BACKGROUND: case PANGO_ATTR_UNDERLINE_COLOR: case PANGO_ATTR_OVERLINE_COLOR: case PANGO_ATTR_STRIKETHROUGH_COLOR: - g_string_append_printf (string, "%s", pango_color_to_string (&((PangoAttrColor *)attr)->color)); + { + char *text = pango_color_to_string (&((PangoAttrColor *)attr)->color); + g_string_append_printf (string, "%s", text); + g_free (text); + } break; case PANGO_ATTR_SHAPE: g_string_append_printf (string, "shape"); diff --git a/tests/test-itemize.c b/tests/test-itemize.c index 3c58e18f..cd145e40 100644 --- a/tests/test-itemize.c +++ b/tests/test-itemize.c @@ -241,9 +241,12 @@ test_itemize (gconstpointer d) setlocale (LC_ALL, "en_US.utf8"); if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL) { +#if 0 + // See https://github.com/mesonbuild/meson/issues/7515 char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping itemization %s", filename); g_test_skip (msg); g_free (msg); +#endif return; } diff --git a/tests/test-layout.c b/tests/test-layout.c index 52617ce6..58ab46eb 100644 --- a/tests/test-layout.c +++ b/tests/test-layout.c @@ -308,9 +308,12 @@ test_layout (gconstpointer d) setlocale (LC_ALL, "en_US.utf8"); if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL) { +#if 0 + // See https://github.com/mesonbuild/meson/issues/7515 char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping layout %s", filename); g_test_skip (msg); g_free (msg); +#endif return; } diff --git a/tests/testboundaries_ucd.c b/tests/testboundaries_ucd.c index f77abdcd..1f0276e6 100644 --- a/tests/testboundaries_ucd.c +++ b/tests/testboundaries_ucd.c @@ -232,7 +232,9 @@ do_test (const gchar *filename, channel = g_io_channel_new_file (filename, "r", &error); if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { +#if 0 g_test_skip ("Test file not found"); +#endif return; } @@ -298,6 +300,7 @@ do_test (const gchar *filename, } g_free (string); g_free (expected_attrs); + g_free (line); i++; } diff --git a/tests/testcolor.c b/tests/testcolor.c index 36f2dbf3..62bbe4bf 100644 --- a/tests/testcolor.c +++ b/tests/testcolor.c @@ -25,57 +25,92 @@ typedef struct _ColorSpec { const gchar *spec; gboolean valid; + int color_or_alpha; guint16 red; guint16 green; guint16 blue; + guint16 alpha; } ColorSpec; -static gboolean test_one_color (ColorSpec *spec) +#define COLOR 1 +#define ALPHA 2 +#define BOTH 3 + +static void +test_one_color (ColorSpec *spec) { PangoColor color; gboolean accepted; + guint16 alpha; - accepted = pango_color_parse (&color, spec->spec); + if (spec->color_or_alpha & COLOR) + { + accepted = pango_color_parse (&color, spec->spec); - if (accepted == spec->valid && - (!accepted || - (color.red == spec->red && - color.green == spec->green && - color.blue == spec->blue))) - return TRUE; - else - return FALSE; -} + if (!spec->valid) + { + g_assert_false (accepted); + } + else + { + g_assert_true (accepted); + g_assert_cmpuint (color.red, ==, spec->red); + g_assert_cmpuint (color.green, ==, spec->green); + g_assert_cmpuint (color.blue, ==, spec->blue); + } + } + if (spec->color_or_alpha & ALPHA) + { + accepted = pango_color_parse_with_alpha (&color, &alpha, spec->spec); + + if (!spec->valid) + { + g_assert_false (accepted); + } + else + { + g_assert_true (accepted); + g_assert_cmpuint (color.red, ==, spec->red); + g_assert_cmpuint (color.green, ==, spec->green); + g_assert_cmpuint (color.blue, ==, spec->blue); + g_assert_cmpuint (alpha, ==, spec->alpha); + } + } +} ColorSpec specs [] = { - { "#abc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aabbcc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aaabbbccc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#100100100", 1, 0x1001, 0x1001, 0x1001 }, - { "#aaaabbbbcccc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#fff", 1, 0xffff, 0xffff, 0xffff }, - { "#ffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#fffffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#ffffffffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#AAAABBBBCCCC", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aa bb cc ", 0, 0, 0, 0 }, - { "#aa bb ccc", 0, 0, 0, 0 }, - { "#ab", 0, 0, 0, 0 }, - { "#aabb", 0, 0, 0, 0 }, - { "#aaabb", 0, 0, 0, 0 }, - { "aaabb", 0, 0, 0, 0 }, - { "", 0, 0, 0, 0 }, - { "#", 0, 0, 0, 0 }, - { "##fff", 0, 0, 0, 0 }, - { "#0000ff+", 0, 0, 0, 0 }, - { "#0000f+", 0, 0, 0, 0 }, - { "#0x00x10x2", 0, 0, 0, 0 }, - { NULL, 0, 0, 0, 0 } + { "#abc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aabbcc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aaabbbccc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#100100100", 1, BOTH, 0x1001, 0x1001, 0x1001, 0xffff }, + { "#aaaabbbbcccc", 1, COLOR, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#fff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#ffffff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#fffffffff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#ffffffffffff", 1, COLOR, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000000000", 1, COLOR, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#AAAABBBBCCCC", 1, COLOR, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aa bb cc ", 0, BOTH, 0, 0, 0, 0 }, + { "#aa bb ccc", 0, BOTH, 0, 0, 0, 0 }, + { "#ab", 0, BOTH, 0, 0, 0, 0 }, + { "#aabb", 0, COLOR, 0, 0, 0, 0 }, + { "#aaabb", 0, BOTH, 0, 0, 0, 0 }, + { "aaabb", 0, BOTH, 0, 0, 0, 0 }, + { "", 0, BOTH, 0, 0, 0, 0 }, + { "#", 0, BOTH, 0, 0, 0, 0 }, + { "##fff", 0, BOTH, 0, 0, 0, 0 }, + { "#0000ff+", 0, BOTH, 0, 0, 0, 0 }, + { "#0000f+", 0, BOTH, 0, 0, 0, 0 }, + { "#0x00x10x2", 0, BOTH, 0, 0, 0, 0 }, + { "#abcd", 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { "#aabbccdd", 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { "#aaaabbbbccccdddd", + 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { NULL, 0, BOTH, 0, 0, 0, 0 } }; static void @@ -84,8 +119,7 @@ test_color (void) ColorSpec *spec; for (spec = specs; spec->spec; spec++) - g_assert (test_one_color (spec)); - + test_one_color (spec); } int diff --git a/tests/testmisc.c b/tests/testmisc.c index f5583cab..9f1f24da 100644 --- a/tests/testmisc.c +++ b/tests/testmisc.c @@ -54,6 +54,25 @@ test_itemize_empty_crash (void) g_object_unref (context); } +/* Test that pango_layout_set_text (layout, "short", 200) + * does not lead to a crash. (pidgin does this) + */ +static void +test_short_string_crash (void) +{ + PangoContext *context; + PangoLayout *layout; + int width, height; + + context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); + layout = pango_layout_new (context); + pango_layout_set_text (layout, "short text", 200); + pango_layout_get_pixel_size (layout, &width, &height); + + g_object_unref (layout); + g_object_unref (context); +} + int main (int argc, char *argv[]) { @@ -61,6 +80,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/short-string-crash", test_short_string_crash); return g_test_run (); } |