added ttf support to ruby module
[swftools.git] / lib / ruby / gfx.c
index edca2e3..d392ed0 100644 (file)
@@ -3,12 +3,14 @@
 #include "../gfxsource.h"
 #include "../gfxtools.h"
 #include "../gfximage.h"
+#include "../gfxfont.h"
 #include "../devices/pdf.h"
 #include "../readers/swf.h"
 #include "../readers/image.h"
 #include "../pdf/pdf.h"
 #include "../mem.h"
 #include "../types.h"
+#include "../log.h"
 
 #define RUBY_GFX_VERSION  "0.9.0"
 
@@ -87,7 +89,7 @@ static VALUE doc_get_page(VALUE cls, VALUE _nr)
     page->doc = doc;
     if(!page->page) {
        rb_raise(rb_eArgError, "No page %d in document", nr);
-       return;
+       return Qnil;
     }
     return v;
 }
@@ -220,6 +222,18 @@ static VALUE image_rescale(VALUE cls, VALUE _width, VALUE _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;t<size;t++) {
+       if(data->a!=255) 
+           return Qtrue;
+    }
+    return Qfalse;
+}
 static VALUE image_save_jpeg(VALUE cls, VALUE _filename, VALUE quality)
 {
     Get_Image(image,cls)
@@ -350,6 +364,15 @@ static VALUE font_glyphs(VALUE cls)
     return font->glyph_array;
 }
 
+static VALUE font_save_ttf(VALUE cls, VALUE _filename)
+{
+    Get_Font(font,cls);
+    Check_Type(_filename, T_STRING);
+    const char*filename = StringValuePtr(_filename);
+    gfxfont_save(font->font, filename);
+    return Qnil;
+}
+
 static VALUE font_kerning(VALUE cls)
 {
     Get_Font(font,cls);
@@ -484,6 +507,10 @@ static VALUE convert_font(gfxfont_t*font)
     }
     return v2;
 }
+static VALUE convert_gradient(gfxgradient_t*gradient)
+{
+    return Qnil; //TODO
+}
 #define HEAD \
     device_internal_t*i = (device_internal_t*)dev->internal; \
     VALUE v = i->v;
@@ -704,6 +731,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);
@@ -718,6 +746,7 @@ void Init_gfx()
     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);
+    rb_define_method(Font, "save_ttf", font_save_ttf, 1);
     
     Device = rb_define_class_under(GFX, "Device", rb_cObject);
     rb_define_method(Device, "startpage", noop, -1);