[librsvg] rsvt-text: Make rsvg_text_create_layout() create the PangoContext itself



commit e4baae8523cff847307db62dee800fc7fda54c1d
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Dec 14 07:50:52 2017 -0600

    rsvt-text: Make rsvg_text_create_layout() create the PangoContext itself
    
    This makes life easier on its callers.

 rsvg-text.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
---
diff --git a/rsvg-text.c b/rsvg-text.c
index 40fc959..07a1b29 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -550,9 +550,10 @@ rsvg_new_tref (const char *element_name, RsvgNode *parent)
 }
 
 static PangoLayout *
-rsvg_text_create_layout (RsvgDrawingCtx * ctx, const char *text, PangoContext * context)
+rsvg_text_create_layout (RsvgDrawingCtx *ctx, const char *text)
 {
     RsvgState *state;
+    PangoContext *context;
     PangoFontDescription *font_desc;
     PangoLayout *layout;
     PangoAttrList *attr_list;
@@ -561,6 +562,8 @@ rsvg_text_create_layout (RsvgDrawingCtx * ctx, const char *text, PangoContext *
 
     state = rsvg_current_state (ctx);
 
+    context = ctx->render->get_pango_context (ctx);
+
     if (state->lang)
         pango_context_set_language (context, pango_language_from_string (state->lang));
 
@@ -620,13 +623,14 @@ rsvg_text_create_layout (RsvgDrawingCtx * ctx, const char *text, PangoContext *
     pango_layout_set_alignment (layout, (state->text_dir == PANGO_DIRECTION_LTR) ?
                                 PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT);
 
+    g_object_unref (context);
+
     return layout;
 }
 
 static void
 rsvg_text_render_text (RsvgDrawingCtx * ctx, const char *text, gdouble * x, gdouble * y)
 {
-    PangoContext *context;
     PangoLayout *layout;
     PangoLayoutIter *iter;
     RsvgState *state;
@@ -639,8 +643,7 @@ rsvg_text_render_text (RsvgDrawingCtx * ctx, const char *text, gdouble * x, gdou
     if (state->font_size.length == 0)
         return;
 
-    context = ctx->render->get_pango_context (ctx);
-    layout = rsvg_text_create_layout (ctx, text, context);
+    layout = rsvg_text_create_layout (ctx, text);
     pango_layout_get_size (layout, &w, &h);
     iter = pango_layout_get_iter (layout);
     offset = pango_layout_iter_get_baseline (iter) / (double) PANGO_SCALE;
@@ -660,26 +663,21 @@ rsvg_text_render_text (RsvgDrawingCtx * ctx, const char *text, gdouble * x, gdou
         *x += w / (double)PANGO_SCALE;
 
     g_object_unref (layout);
-    g_object_unref (context);
 }
 
 static gdouble
 measure_text (RsvgDrawingCtx * ctx, const char *text)
 {
-    PangoContext *context;
     PangoLayout *layout;
     gint width;
     gdouble scaled_width;
 
-    context = ctx->render->get_pango_context (ctx);
-
-    layout = rsvg_text_create_layout (ctx, text, context);
+    layout = rsvg_text_create_layout (ctx, text);
 
     pango_layout_get_size (layout, &width, NULL);
     scaled_width = width / (double)PANGO_SCALE;
 
     g_object_unref (layout);
-    g_object_unref (context);
 
     return scaled_width;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]