X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fruby%2Fgfx.c;h=958ce405e21dddea5a2b64f6b0c2ec523cf97834;hb=8e7a42a2c252dcad56aa9e05bd4025c16c558e2c;hp=11addd21e04658489517bdb63c61ce918e3a7836;hpb=1503f016b8d04b374c0e2290d37a4f2f91e63688;p=swftools.git diff --git a/lib/ruby/gfx.c b/lib/ruby/gfx.c index 11addd2..958ce40 100644 --- a/lib/ruby/gfx.c +++ b/lib/ruby/gfx.c @@ -63,6 +63,9 @@ static VALUE doc_initialize(VALUE cls, VALUE _filename) const char*filename = StringValuePtr(_filename); doc->fontlist = gfxfontlist_create(); doc->doc = pdfdriver->open(pdfdriver, filename); + if(!doc->doc) { + rb_raise(rb_eIOError, "couldn't open %s", filename); + } return cls; } @@ -281,6 +284,16 @@ static VALUE glyph_advance(VALUE cls) return rb_float_new(glyph->font->font->glyphs[glyph->nr].advance); } +static VALUE glyph_bbox(VALUE cls) +{ + Get_Glyph(glyph,cls); + gfxbbox_t bbox = gfxline_getbbox(glyph->font->font->glyphs[glyph->nr].line); + return rb_ary_new3(4, rb_float_new(bbox.xmin), + rb_float_new(bbox.ymin), + rb_float_new(bbox.xmax), + rb_float_new(bbox.ymax)); +} + static VALUE glyph_unicode(VALUE cls) { Get_Glyph(glyph,cls); @@ -646,6 +659,7 @@ void Init_gfx() rb_define_method(Glyph, "polygon", glyph_polygon, 0); rb_define_method(Glyph, "unicode", glyph_unicode, 0); rb_define_method(Glyph, "advance", glyph_advance, 0); + rb_define_method(Glyph, "bbox", glyph_bbox, 0); Font = rb_define_class_under(GFX, "Font", rb_cObject); rb_define_method(Font, "name", font_name, 0);