X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fruby%2Fgfx.c;h=9c3af378f5aa8c6a616024b357de21a440215f76;hb=1500155bf5c3f465d865aeec6ede12f33dcdb8a5;hp=958ce405e21dddea5a2b64f6b0c2ec523cf97834;hpb=8e7a42a2c252dcad56aa9e05bd4025c16c558e2c;p=swftools.git diff --git a/lib/ruby/gfx.c b/lib/ruby/gfx.c index 958ce40..9c3af37 100644 --- a/lib/ruby/gfx.c +++ b/lib/ruby/gfx.c @@ -215,8 +215,23 @@ 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_has_alpha(VALUE cls) +{ + Get_Image(image,cls) + int size = image->image->width * image->image->height; + gfxcolor_t*data = image->image->data; + int t; + for(t=0;ta!=255) + return Qtrue; + } + return Qfalse; +} static VALUE image_save_jpeg(VALUE cls, VALUE _filename, VALUE quality) { Get_Image(image,cls) @@ -347,6 +362,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;tdoc->prepare(doc->doc, &dev); + return cls; +} + + // ---------------------- global functions ---------------------------------- VALUE gfx_setparameter(VALUE module, VALUE _key, VALUE _value) @@ -647,6 +708,7 @@ void Init_gfx() rb_define_method(Document, "initialize", doc_initialize, 1); rb_define_method(Document, "page", doc_get_page, 1); rb_define_method(Document, "each_page", doc_each_page, 0); + rb_define_method(Document, "prepare", doc_prepare, 1); Bitmap = rb_define_class_under(GFX, "Bitmap", rb_cObject); rb_define_method(Bitmap, "save_jpeg", image_save_jpeg, 2); @@ -654,6 +716,7 @@ void Init_gfx() rb_define_method(Bitmap, "width", image_width, 0); rb_define_method(Bitmap, "height", image_height, 0); rb_define_method(Bitmap, "rescale", image_rescale, 2); + rb_define_method(Bitmap, "has_alpha", image_has_alpha, 0); Glyph = rb_define_class_under(GFX, "Glyph", rb_cObject); rb_define_method(Glyph, "polygon", glyph_polygon, 0); @@ -666,6 +729,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);