From a6fd4076267be5aabe8adc7da56105e520371476 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 1 Feb 2013 14:58:43 +1100 Subject: [PATCH] print: Use cairo_save/cairo_restore to manage temporary cairo changes The print_weight_data function was making several cairo_translate calls and then doing some final cairo_translate calls with the goal of manually undoing any changes to cairo's state. Obviously, this is fragile. Cairo provides save/restore calls which solve this problem in a robust way. Switch to using these instead. Signed-off-by: Carl Worth Signed-off-by: Dirk Hohndel --- print.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/print.c b/print.c index 222bf8d43..50147f78a 100644 --- a/print.c +++ b/print.c @@ -290,6 +290,8 @@ static void print_weight_data (struct dive *dive, cairo_t *cr, int maxwidth, int char buffer[80]; PangoLayout *layout; + cairo_save(cr); + layout = pango_cairo_create_layout(cr); pango_layout_set_height(layout,maxheight); pango_layout_set_width(layout, maxwidth); @@ -339,10 +341,9 @@ static void print_weight_data (struct dive *dive, cairo_t *cr, int maxwidth, int unit_weight); pango_layout_set_text(layout, buffer, -1); pango_cairo_show_layout(cr, layout); - /* undo translations */ - cairo_translate (cr, 0, -(weightsystemcounter * height) / (4 * (double) PANGO_SCALE)); - cairo_translate (cr, 0, -height / (3 * (double) PANGO_SCALE)); g_object_unref (layout); + + cairo_restore(cr); } /* Print the dive OTUs */