From 3af77eabd8b818629bc86e8bd7e29da2cdb621ff Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 9 Feb 2016 15:15:53 +0000 Subject: Can free pango font desc as soon as it's set. --- gtk/font_pango.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/gtk/font_pango.c b/gtk/font_pango.c index 53b443c5d..b28d8836f 100644 --- a/gtk/font_pango.c +++ b/gtk/font_pango.c @@ -94,12 +94,12 @@ bool nsfont_width(const plot_font_style_t *fstyle, desc = nsfont_style_to_description(fstyle); pango_layout_set_font_description(nsfont_pango_layout, desc); + pango_font_description_free(desc); + pango_layout_set_text(nsfont_pango_layout, string, length); pango_layout_get_pixel_size(nsfont_pango_layout, width, 0); - pango_font_description_free(desc); - /* LOG("fstyle: %p string:\"%.*s\", length: %u, width: %dpx", fstyle, length, string, length, *width); */ @@ -132,6 +132,8 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, desc = nsfont_style_to_description(fstyle); pango_layout_set_font_description(nsfont_pango_layout, desc); + pango_font_description_free(desc); + pango_layout_set_text(nsfont_pango_layout, string, length); if (pango_layout_xy_to_index(nsfont_pango_layout, x * PANGO_SCALE, @@ -140,8 +142,6 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, pango_layout_index_to_pos(nsfont_pango_layout, index, &pos); - pango_font_description_free(desc); - *char_offset = index; *actual_x = PANGO_PIXELS(pos.x); @@ -182,10 +182,13 @@ bool nsfont_split(const plot_font_style_t *fstyle, PangoLayout *layout; PangoLayoutLine *line; - desc = nsfont_style_to_description(fstyle); context = gdk_pango_context_get(); layout = pango_layout_new(context); + + desc = nsfont_style_to_description(fstyle); pango_layout_set_font_description(layout, desc); + pango_font_description_free(desc); + pango_layout_set_text(layout, string, length); /* Limit width of layout to the available width */ @@ -207,7 +210,6 @@ bool nsfont_split(const plot_font_style_t *fstyle, g_object_unref(layout); g_object_unref(context); - pango_font_description_free(desc); *char_offset = index; /* Obtain the pixel offset of the split character */ @@ -238,20 +240,20 @@ bool nsfont_paint(int x, int y, const char *string, size_t length, if (length == 0) return true; - desc = nsfont_style_to_description(fstyle); - layout = pango_cairo_create_layout(current_cr); + desc = nsfont_style_to_description(fstyle); pango_layout_set_font_description(layout, desc); + pango_font_description_free(desc); + pango_layout_set_text(layout, string, length); + line = pango_layout_get_line_readonly(layout, 0); - cairo_move_to(current_cr, x, y); nsgtk_set_colour(fstyle->foreground); pango_cairo_show_layout_line(current_cr, line); g_object_unref(layout); - pango_font_description_free(desc); return true; } -- cgit v1.2.3