[gjs: 26/45] [cairo] Fix leaks in showText/selectFontFace



commit 06ea08c0d07886486e0506938e2fd1f4b9147d34
Author: Johan Dahlin <johan gnome org>
Date:   Fri Feb 26 08:48:36 2010 -0300

    [cairo] Fix leaks in showText/selectFontFace
    
    Strings needs to be freed after usage, so we can't use
    the macros any more.

 doc/cairo.txt           |    1 -
 modules/cairo-context.c |   58 ++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 4 deletions(-)
---
diff --git a/doc/cairo.txt b/doc/cairo.txt
index 4594232..1aacc05 100644
--- a/doc/cairo.txt
+++ b/doc/cairo.txt
@@ -78,7 +78,6 @@ gjs> let pattern = new Cairo.SurfacePattern(surface);
 gjs> pattern.set_filter(Cairo.Filter.NEAREST);
 
 TODO:
-* string leaks in macros
 * reference counting
 * context: wrap the remaning methods
 * surface methods
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index e97faa3..51ca334 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -326,8 +326,6 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC0(restore, cairo_restore)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC1(rotate, cairo_rotate, "f", double, angle)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC0(save, cairo_save)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC2(scale, cairo_scale, "ff", double, sx, double, sy)
-_GJS_CAIRO_CONTEXT_DEFINE_FUNC3(selectFontFace, cairo_select_font_face, "sii", const char*, family,
-                                cairo_font_slant_t, slant, cairo_font_weight_t, weight)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC1(setAntiAlias, cairo_set_antialias, "i", cairo_antialias_t, antialias)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC1(setFillRule, cairo_set_fill_rule, "i", cairo_fill_rule_t, fill_rule)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC1(setFontSize, cairo_set_font_size, "f", double, size)
@@ -342,7 +340,6 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC3(setSourceRGB, cairo_set_source_rgb, "fff",
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC4(setSourceRGBA, cairo_set_source_rgba, "ffff",
                                 double, red, double, green, double, blue, double, alpha)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC0(showPage, cairo_show_page)
-_GJS_CAIRO_CONTEXT_DEFINE_FUNC1(showText, cairo_show_text, "s", const char*, utf8)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC0(stroke, cairo_stroke)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC0(strokePreserve, cairo_stroke_preserve)
 _GJS_CAIRO_CONTEXT_DEFINE_FUNC0AFFFF(strokeExtents, cairo_stroke_extents)
@@ -444,6 +441,7 @@ setSource_func(JSContext *context,
 
     return JS_TRUE;
 }
+
 static JSBool
 setSourceSurface_func(JSContext *context,
                       JSObject  *obj,
@@ -478,6 +476,60 @@ setSourceSurface_func(JSContext *context,
     return JS_TRUE;
 }
 
+static JSBool
+showText_func(JSContext *context,
+              JSObject  *obj,
+              uintN      argc,
+              jsval     *argv,
+              jsval     *retval)
+{
+    char *utf8;
+    cairo_t *cr;
+
+    if (!gjs_parse_args(context, "showText", "s", argc, argv,
+                        "utf8", &utf8))
+        return JS_FALSE;
+
+    cr = gjs_cairo_context_get_context(context, obj);
+
+    cairo_show_text(cr, utf8);
+    g_free(utf8);
+
+    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
+        return JS_FALSE;
+
+    return JS_TRUE;
+}
+
+static JSBool
+selectFontFace_func(JSContext *context,
+                    JSObject  *obj,
+                    uintN      argc,
+                    jsval     *argv,
+                    jsval     *retval)
+{
+    char *family;
+    cairo_font_slant_t slant;
+    cairo_font_weight_t weight;
+    cairo_t *cr;
+
+    if (!gjs_parse_args(context, "selectFontFace", "sii", argc, argv,
+                        "family", &family,
+                        "slang", &slant,
+                        "weight", &weight))
+        return JS_FALSE;
+
+    cr = gjs_cairo_context_get_context(context, obj);
+
+    cairo_select_font_face(cr, family, slant, weight);
+    g_free(family);
+
+    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
+        return JS_FALSE;
+
+    return JS_TRUE;
+}
+
 static JSFunctionSpec gjs_cairo_context_proto_funcs[] = {
     // appendPath
     { "arc", arc_func, 0, 0 },



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