fixed segv in ruby module
[swftools.git] / lib / ruby / gfx.c
index 958ce40..641388f 100644 (file)
@@ -215,6 +215,9 @@ static VALUE image_rescale(VALUE cls, VALUE _width, VALUE _height)
     Get_Image(image2,v_image2)
     image2->doc = image->doc;
     image2->image = gfximage_rescale(image->image, width, height);
+    if(!image2->image) {
+       rb_raise(rb_eArgError, "Can't rescale to size %dx%d", width, height);
+    }
     return v_image2;
 }
 static VALUE image_save_jpeg(VALUE cls, VALUE _filename, VALUE quality)
@@ -347,6 +350,23 @@ static VALUE font_glyphs(VALUE cls)
     return font->glyph_array;
 }
 
+static VALUE font_kerning(VALUE cls)
+{
+    Get_Font(font,cls);
+    gfxkerning_t*kerning = font->font->kerning;
+    int kerning_size = font->font->kerning_size;
+    volatile VALUE a = rb_ary_new2(kerning_size);
+    int t;
+    for(t=0;t<kerning_size;t++) {
+       volatile VALUE tuple = rb_ary_new2(3);
+       rb_ary_store(tuple, 0, INT2FIX(kerning[t].c1));
+       rb_ary_store(tuple, 1, INT2FIX(kerning[t].c2));
+       rb_ary_store(tuple, 2, INT2FIX(kerning[t].advance));
+       rb_ary_store(a, t, tuple);
+    }
+    return a;
+}
+
 // ------------------------ gfx device --------------------------------------
 
 typedef struct device_internal {
@@ -666,6 +686,8 @@ void Init_gfx()
     rb_define_method(Font, "ascent", font_ascent, 0);
     rb_define_method(Font, "descent", font_descent, 0);
     rb_define_method(Font, "glyphs", font_glyphs, 0);
+    rb_define_method(Font, "kerning", font_kerning, 0);
+    rb_define_method(Font, "get_kerning_table", font_kerning, 0);
     
     Device = rb_define_class_under(GFX, "Device", rb_cObject);
     rb_define_method(Device, "startpage", noop, -1);