2 #include "../../config.h"
3 #include "../gfxdevice.h"
4 #include "../gfxsource.h"
5 #include "../gfxtools.h"
6 #include "../gfximage.h"
7 #include "../gfxfont.h"
8 #include "../gfxfilter.h"
9 #include "../devices/pdf.h"
10 #include "../readers/swf.h"
11 #include "../readers/image.h"
12 #include "../pdf/pdf.h"
18 #define RUBY_GFX_VERSION "0.9.0"
21 static VALUE Font
, Glyph
, Bitmap
, Document
, DocumentPage
, PDFClass
, SWFClass
, ImageClass
, Device
;
24 typedef struct doc_internal
{
26 gfxsource_t
*driver
; // filled by alloc
28 gfxfontlist_t
*fontlist
;
31 typedef struct page_internal
{
36 typedef struct image_internal
{
41 typedef struct font_internal
{
47 typedef struct glyph_internal
{
52 static gfxsource_t
* pdfdriver
= 0;
53 static gfxsource_t
* imagedriver
= 0;
54 static gfxsource_t
* swfdriver
= 0;
56 #define Get_Doc(doc,cls) doc_internal_t*doc=0;Data_Get_Struct(cls, doc_internal_t, doc);
57 #define Get_Page(page,cls) page_internal_t*page=0;Data_Get_Struct(cls, page_internal_t, page);
59 static VALUE
doc_allocate(VALUE cls
, gfxsource_t
*driver
);
60 static VALUE
page_allocate(VALUE cls
);
62 // ------------------------ documents ---------------------------------------
64 static VALUE
doc_initialize(VALUE cls
, VALUE _filename
)
66 Check_Type(_filename
, T_STRING
);
68 const char*filename
= StringValuePtr(_filename
);
69 doc
->fontlist
= gfxfontlist_create();
70 doc
->doc
= pdfdriver
->open(pdfdriver
, filename
);
72 rb_raise(rb_eIOError
, "couldn't open %s", filename
);
77 static VALUE
doc_num_pages(VALUE cls
)
80 return INT2FIX(doc
->doc
->num_pages
);
83 static VALUE
doc_get_page(VALUE cls
, VALUE _nr
)
85 Check_Type(_nr
, T_FIXNUM
);
86 int nr
= FIX2INT(_nr
);
89 VALUE v
= page_allocate(DocumentPage
);
91 page
->page
= doc
->doc
->getpage(doc
->doc
, nr
);
94 rb_raise(rb_eArgError
, "No page %d in document", nr
);
100 static VALUE
doc_each_page(VALUE cls
)
104 for(t
=1;t
<=doc
->doc
->num_pages
;t
++) {
105 VALUE v
= page_allocate(DocumentPage
);
107 page
->page
= doc
->doc
->getpage(doc
->doc
, t
);
114 static void doc_mark(doc_internal_t
*doc
)
116 gfxfontlist_t
*l
= doc
->fontlist
;
119 rb_gc_mark((VALUE
)l
->user
);
124 static void doc_free(doc_internal_t
*doc
)
126 gfxfontlist_free(doc
->fontlist
, 0);
128 doc
->doc
->destroy(doc
->doc
);
134 static VALUE
doc_allocate(VALUE cls
, gfxsource_t
*driver
)
136 doc_internal_t
*doc
= 0;
137 VALUE v
= Data_Make_Struct(cls
, doc_internal_t
, doc_mark
, doc_free
, doc
);
139 memset(doc
, 0, sizeof(doc_internal_t
));
140 doc
->driver
= driver
;
144 static VALUE
pdf_allocate(VALUE cls
) {return doc_allocate(cls
, pdfdriver
);}
145 static VALUE
swf_allocate(VALUE cls
) {return doc_allocate(cls
, swfdriver
);}
146 static VALUE
imgdrv_allocate(VALUE cls
) {return doc_allocate(cls
, imagedriver
);}
148 // ------------------------ doc pages ---------------------------------------
150 static void page_free(page_internal_t
*page
)
154 page
->page
->destroy(page
->page
);
159 static void page_mark(page_internal_t
*page
)
161 rb_gc_mark(page
->doc
->self
);
163 static VALUE
page_allocate(VALUE cls
)
165 page_internal_t
*page
= 0;
166 VALUE v
= Data_Make_Struct(cls
, page_internal_t
, page_mark
, page_free
, page
);
167 memset(page
, 0, sizeof(page_internal_t
));
170 static VALUE
page_nr(VALUE cls
)
173 return INT2FIX(page
->page
->nr
);
175 static VALUE
page_width(VALUE cls
)
178 return INT2FIX(page
->page
->width
);
180 static VALUE
page_height(VALUE cls
)
183 return INT2FIX(page
->page
->height
);
186 // ------------------------ image -------------------------------------------
188 #define Get_Image(image,cls) image_internal_t*image=0;Data_Get_Struct(cls, image_internal_t, image);
190 static void image_free(image_internal_t
*image
)
194 static void image_mark(image_internal_t
*image
)
196 rb_gc_mark(image
->doc
->self
);
198 static VALUE
image_allocate(VALUE cls
)
200 image_internal_t
*image
= 0;
201 VALUE v
= Data_Make_Struct(cls
, image_internal_t
, image_mark
, image_free
, image
);
202 memset(image
, 0, sizeof(image_internal_t
));
205 static VALUE
image_width(VALUE cls
)
208 return INT2FIX(image
->image
->width
);
210 static VALUE
image_height(VALUE cls
)
213 return INT2FIX(image
->image
->height
);
215 static VALUE
image_rescale(VALUE cls
, VALUE _width
, VALUE _height
)
218 Check_Type(_width
, T_FIXNUM
);
219 Check_Type(_height
, T_FIXNUM
);
220 int width
= FIX2INT(_width
);
221 int height
= FIX2INT(_height
);
222 volatile VALUE v_image2
= image_allocate(Bitmap
);
223 Get_Image(image2
,v_image2
)
224 image2
->doc
= image
->doc
;
225 image2
->image
= gfximage_rescale(image
->image
, width
, height
);
227 rb_raise(rb_eArgError
, "Can't rescale to size %dx%d", width
, height
);
231 static VALUE
image_has_alpha(VALUE cls
)
234 int size
= image
->image
->width
* image
->image
->height
;
235 gfxcolor_t
*data
= image
->image
->data
;
237 for(t
=0;t
<size
;t
++) {
243 static VALUE
image_save_jpeg(VALUE cls
, VALUE _filename
, VALUE quality
)
246 Check_Type(_filename
, T_STRING
);
247 Check_Type(quality
, T_FIXNUM
);
248 const char*filename
= StringValuePtr(_filename
);
249 gfximage_save_jpeg(image
->image
, filename
, FIX2INT(quality
));
252 static VALUE
image_save_png(VALUE cls
, VALUE _filename
)
255 Check_Type(_filename
, T_STRING
);
256 const char*filename
= StringValuePtr(_filename
);
257 gfximage_save_png(image
->image
, filename
);
260 VALUE
convert_image(doc_internal_t
*doc
,gfximage_t
*_image
)
262 VALUE v
= image_allocate(Bitmap
);
264 image
->image
= _image
;
268 void invalidate_image(VALUE v
)
274 // ------------------------ glyphs ------------------------------------------
276 static VALUE
convert_line(gfxline_t
*line
);
278 #define Get_Glyph(glyph,cls) glyph_internal_t*glyph=0;Data_Get_Struct(cls, glyph_internal_t, glyph);
280 static void glyph_free(glyph_internal_t
*glyph
)
285 static void glyph_mark(glyph_internal_t
*glyph
)
287 rb_gc_mark(glyph
->font
->self
);
290 static VALUE
glyph_allocate(VALUE cls
)
292 glyph_internal_t
*glyph
= 0;
293 VALUE v
= Data_Make_Struct(cls
, glyph_internal_t
, glyph_mark
, glyph_free
, glyph
);
294 memset(glyph
, 0, sizeof(glyph_internal_t
));
298 static VALUE
glyph_polygon(VALUE cls
)
300 Get_Glyph(glyph
,cls
);
301 return convert_line(glyph
->font
->font
->glyphs
[glyph
->nr
].line
);
304 static VALUE
glyph_advance(VALUE cls
)
306 Get_Glyph(glyph
,cls
);
307 return rb_float_new(glyph
->font
->font
->glyphs
[glyph
->nr
].advance
);
310 static VALUE
glyph_bbox(VALUE cls
)
312 Get_Glyph(glyph
,cls
);
313 gfxbbox_t bbox
= gfxline_getbbox(glyph
->font
->font
->glyphs
[glyph
->nr
].line
);
314 return rb_ary_new3(4, rb_float_new(bbox
.xmin
),
315 rb_float_new(bbox
.ymin
),
316 rb_float_new(bbox
.xmax
),
317 rb_float_new(bbox
.ymax
));
320 static VALUE
glyph_unicode(VALUE cls
)
322 Get_Glyph(glyph
,cls
);
323 return INT2FIX(glyph
->font
->font
->glyphs
[glyph
->nr
].unicode
);
326 // ------------------------ font --------------------------------------------
328 #define Get_Font(font,cls) font_internal_t*font=0;Data_Get_Struct(cls, font_internal_t, font);
330 static void font_mark(font_internal_t
*font
)
332 rb_gc_mark(font
->glyph_array
);
335 static void font_free(font_internal_t
*font
)
340 static VALUE
font_allocate(VALUE cls
)
342 font_internal_t
*font
= 0;
343 VALUE v
= Data_Make_Struct(cls
, font_internal_t
, font_mark
, font_free
, font
);
344 memset(font
, 0, sizeof(font_internal_t
));
349 static VALUE
font_ascent(VALUE cls
)
352 return rb_float_new(font
->font
->ascent
);
355 static VALUE
font_descent(VALUE cls
)
358 return rb_float_new(font
->font
->descent
);
361 static VALUE
font_name(VALUE cls
)
364 return rb_tainted_str_new2(font
->font
->id
);
367 static VALUE
font_glyphs(VALUE cls
)
370 return font
->glyph_array
;
373 static VALUE
font_save_ttf(VALUE cls
, VALUE _filename
)
376 Check_Type(_filename
, T_STRING
);
377 const char*filename
= StringValuePtr(_filename
);
378 gfxfont_save(font
->font
, filename
);
382 static VALUE
font_save_eot(VALUE cls
, VALUE _filename
)
385 Check_Type(_filename
, T_STRING
);
386 const char*filename
= StringValuePtr(_filename
);
387 gfxfont_save_eot(font
->font
, filename
);
391 // ------------------------ gfx device --------------------------------------
393 typedef struct device_internal
{
398 static ID id_setparameter
= 0;
399 static ID id_startpage
= 0;
400 static ID id_startclip
= 0;
401 static ID id_endclip
= 0;
402 static ID id_stroke
= 0;
403 static ID id_fill
= 0;
404 static ID id_fillbitmap
= 0;
405 static ID id_fillgradient
= 0;
406 static ID id_addfont
= 0;
407 static ID id_drawchar
= 0;
408 static ID id_drawlink
= 0;
409 static ID id_endpage
= 0;
410 static ID id_geterror
= 0;
411 static ID id_finish
= 0;
412 static ID id_butt
= 0;
413 static ID id_round
= 0;
414 static ID id_square
= 0;
415 static ID id_bevel
= 0;
416 static ID id_miter
= 0;
417 static ID id_move
= 0;
418 static ID id_line
= 0;
419 static ID id_spline
= 0;
420 static ID id_radial
= 0;
421 static ID id_linear
= 0;
422 static ID id_remove_font_transforms
= 0;
423 static ID id_maketransparent
= 0;
424 static ID id_vectors_to_glyphs
= 0;
426 static VALUE
noop(int argc
, VALUE
*argv
, VALUE obj
) {return obj
;}
428 #define forward(v,id,args...) rb_respond_to((v), (id))?rb_funcall((v), (id), args):0
430 VALUE
convert_line(gfxline_t
*line
)
434 while(l
) {l
=l
->next
;len
++;}
436 volatile VALUE array
= rb_ary_new2(len
);
442 if(l
->type
== gfx_moveTo
) {
443 e
= rb_ary_new3(3, ID2SYM(id_move
), Qfalse
, Qfalse
);
444 rb_ary_store(array
, pos
, e
);
445 rb_ary_store(e
, 1, rb_float_new(l
->x
));
446 rb_ary_store(e
, 2, rb_float_new(l
->y
));
447 } else if(l
->type
== gfx_lineTo
) {
448 e
= rb_ary_new3(3, ID2SYM(id_line
), Qfalse
, Qfalse
);
449 rb_ary_store(array
, pos
, e
);
450 rb_ary_store(e
, 1, rb_float_new(l
->x
));
451 rb_ary_store(e
, 2, rb_float_new(l
->y
));
453 e
= rb_ary_new3(5, ID2SYM(id_spline
), Qfalse
, Qfalse
, Qfalse
, Qfalse
);
454 rb_ary_store(array
, pos
, e
);
455 rb_ary_store(e
, 1, rb_float_new(l
->x
));
456 rb_ary_store(e
, 2, rb_float_new(l
->y
));
457 rb_ary_store(e
, 3, rb_float_new(l
->sx
));
458 rb_ary_store(e
, 4, rb_float_new(l
->sy
));
465 VALUE
convert_color(gfxcolor_t
*color
)
467 return rb_ary_new3(4, INT2FIX(color
->a
), INT2FIX(color
->r
), INT2FIX(color
->g
), INT2FIX(color
->b
));
469 VALUE
convert_matrix(gfxmatrix_t
*matrix
)
471 volatile VALUE array
= rb_ary_new2(3);
472 volatile VALUE a
= rb_ary_new2(2);
473 rb_ary_store(array
, 0, a
);
474 rb_ary_store(a
, 0, rb_float_new(matrix
->m00
));
475 rb_ary_store(a
, 1, rb_float_new(matrix
->m01
));
477 rb_ary_store(array
, 1, a
);
478 rb_ary_store(a
, 0, rb_float_new(matrix
->m10
));
479 rb_ary_store(a
, 1, rb_float_new(matrix
->m11
));
481 rb_ary_store(array
, 2, a
);
482 rb_ary_store(a
, 0, rb_float_new(matrix
->tx
));
483 rb_ary_store(a
, 1, rb_float_new(matrix
->ty
));
486 static VALUE
font_is_cached(device_internal_t
*i
, gfxfont_t
*font
)
488 return (VALUE
)gfxfontlist_getuserdata(i
->doc
->fontlist
, font
->id
);
490 static void cache_font(device_internal_t
*i
, gfxfont_t
*font
, VALUE v
)
492 i
->doc
->fontlist
= gfxfontlist_addfont2(i
->doc
->fontlist
, font
, (void*)v
);
494 static VALUE
convert_font(gfxfont_t
*font
)
496 volatile VALUE v2
= font_allocate(Font
);
499 f
->glyph_array
= rb_ary_new2(font
->num_glyphs
);
502 for(t
=0;t
<font
->num_glyphs
;t
++) {
503 volatile VALUE a
= glyph_allocate(Glyph
);
504 rb_ary_store(f
->glyph_array
, t
, a
);
511 static VALUE
convert_gradient(gfxgradient_t
*gradient
)
516 device_internal_t*i = (device_internal_t*)dev->internal; \
518 int rb_setparameter(gfxdevice_t
*dev
, const char*key
, const char*value
)
521 volatile VALUE v_key
= rb_tainted_str_new2(key
);
522 volatile VALUE v_value
= rb_tainted_str_new2(value
);
523 VALUE ret
= forward(v
,id_setparameter
,2,v_key
,v_value
);
526 void rb_startpage(gfxdevice_t
*dev
, int width
, int height
)
529 VALUE ret
= forward(v
,id_startpage
,2,INT2FIX(width
),INT2FIX(height
));
531 void rb_startclip(gfxdevice_t
*dev
, gfxline_t
*line
)
534 volatile VALUE v_line
= convert_line(line
);
535 VALUE ret
= forward(v
,id_startclip
,1,v_line
);
537 void rb_endclip(gfxdevice_t
*dev
)
540 VALUE ret
= forward(v
,id_endclip
,0);
542 void rb_stroke(gfxdevice_t
*dev
, gfxline_t
*line
, gfxcoord_t width
, gfxcolor_t
*color
, gfx_capType cap_style
, gfx_joinType joint_style
, gfxcoord_t miterLimit
)
547 if(cap_style
== gfx_capButt
) cap
= id_butt
;
548 else if(cap_style
== gfx_capRound
) cap
= id_round
;
549 else if(cap_style
== gfx_capSquare
) cap
= id_square
;
552 if(joint_style
== gfx_joinRound
) joint
= id_round
;
553 else if(joint_style
== gfx_joinMiter
) joint
= id_miter
;
554 else if(joint_style
== gfx_joinBevel
) joint
= id_bevel
;
556 volatile VALUE v_line
= convert_line(line
);
557 volatile VALUE v_width
= rb_float_new(width
);
558 volatile VALUE v_color
= convert_color(color
);
559 volatile VALUE v_miter
= rb_float_new(miterLimit
);
560 forward(v
, id_stroke
, 6, v_line
, v_width
, v_color
, ID2SYM(cap
), ID2SYM(joint
), v_miter
);
562 void rb_fill(gfxdevice_t
*dev
, gfxline_t
*line
, gfxcolor_t
*color
)
566 volatile VALUE v_line
= convert_line(line
);
567 volatile VALUE v_color
= convert_color(color
);
568 forward(v
, id_fill
, 2, v_line
, v_color
);
570 void rb_fillbitmap(gfxdevice_t
*dev
, gfxline_t
*line
, gfximage_t
*img
, gfxmatrix_t
*matrix
, gfxcxform_t
*cxform
)
573 volatile VALUE v_image
= convert_image(i
->doc
, img
);
574 volatile VALUE v_line
= convert_line(line
);
575 volatile VALUE v_matrix
= convert_matrix(matrix
);
576 forward(v
, id_fillbitmap
, 4, v_line
, v_image
, v_matrix
, Qnil
);
577 invalidate_image(v_image
);
579 void rb_fillgradient(gfxdevice_t
*dev
, gfxline_t
*line
, gfxgradient_t
*gradient
, gfxgradienttype_t type
, gfxmatrix_t
*matrix
)
582 ID
typeid = (type
== gfxgradient_linear
)? id_linear
: id_radial
;
584 volatile VALUE v_line
= convert_line(line
);
585 volatile VALUE v_matrix
= convert_matrix(matrix
);
586 volatile VALUE v_gradient
= convert_gradient(gradient
);
587 forward(v
, id_fillgradient
, 4, v_line
, v_gradient
, ID2SYM(typeid), v_matrix
);
589 void rb_addfont(gfxdevice_t
*dev
, gfxfont_t
*font
)
593 volatile VALUE f
= font_is_cached(i
, font
);
594 if(!f
) {f
=convert_font(font
);cache_font(i
,font
,f
);}
596 forward(v
, id_addfont
, 1, f
);
598 void rb_drawchar(gfxdevice_t
*dev
, gfxfont_t
*font
, int glyphnr
, gfxcolor_t
*color
, gfxmatrix_t
*matrix
)
601 volatile VALUE f
= font_is_cached(i
, font
);
602 if(!f
) {f
=convert_font(font
);cache_font(i
,font
,f
);}
604 volatile VALUE v_color
= convert_color(color
);
605 volatile VALUE v_matrix
= convert_matrix(matrix
);
606 forward(v
, id_drawchar
, 4, f
, INT2FIX(glyphnr
), v_color
, v_matrix
);
608 void rb_drawlink(gfxdevice_t
*dev
, gfxline_t
*line
, const char*action
, const char*text
)
611 volatile VALUE v_line
= convert_line(line
);
612 volatile VALUE v_action
= rb_tainted_str_new2(action
);
613 volatile VALUE v_text
= rb_tainted_str_new2(text
);
615 forward(v
, id_drawlink
, 3, v_line
, v_action
, v_text
);
617 void rb_endpage(gfxdevice_t
*dev
)
620 forward(v
, id_endpage
, 0);
622 void gfxresult_rb_destroy(gfxresult_t
*r
)
626 gfxresult_t
* rb_finish(gfxdevice_t
*dev
)
629 VALUE ret
= forward(v
, id_finish
, 0);
630 gfxresult_t
*r
= (gfxresult_t
*)rfx_calloc(sizeof(gfxresult_t
));
631 r
->destroy
= gfxresult_rb_destroy
;
632 r
->internal
= (void*)(ptroff_t
)ret
;
636 #define make_device(dev, idoc, device) \
638 device_internal_t i; \
642 dev.setparameter = rb_setparameter; \
643 dev.startpage = rb_startpage; \
644 dev.startclip = rb_startclip; \
645 dev.endclip = rb_endclip; \
646 dev.stroke = rb_stroke; \
647 dev.fill = rb_fill; \
648 dev.fillbitmap = rb_fillbitmap; \
649 dev.fillgradient = rb_fillgradient; \
650 dev.addfont = rb_addfont; \
651 dev.drawchar = rb_drawchar; \
652 dev.drawlink = rb_drawlink; \
653 dev.endpage = rb_endpage; \
654 dev.finish = rb_finish;
656 static VALUE
page_render(VALUE cls
, VALUE device
)
658 Check_Type(device
, T_OBJECT
);
661 make_device(dev
, page
->doc
, device
);
663 dev
.startpage(&dev
, page
->page
->width
, page
->page
->height
);
664 page
->page
->render(page
->page
, &dev
);
670 static VALUE
doc_render(VALUE cls
, VALUE device
, VALUE _range
, VALUE filters
)
672 const char*range
= 0;
674 Check_Type(_range
, T_STRING
);
675 range
= StringValuePtr(_range
);
679 make_device(_dev
, doc
, device
);
680 gfxdevice_t
*dev
= &_dev
;
682 if(!NIL_P(filters
)) {
683 if(TYPE(filters
) != T_ARRAY
)
684 rb_raise(rb_eArgError
, "third argument of doc->render must be an array of symbols");
686 int len
= RARRAY(filters
)->len
;
689 VALUE filter
= RARRAY(filters
)->ptr
[t
++];
690 Check_Type(filter
, T_SYMBOL
);
691 ID id
= SYM2ID(filter
);
692 # define PARAM(x) VALUE x;if(t==len) rb_raise(rb_eArgError, "End of array while parsing arguments for filter %s", rb_id2name(id)); \
693 else x = RARRAY(filters)->ptr[t++];
694 if(id
== id_remove_font_transforms
) {
695 wrap_filter2(dev
, remove_font_transforms
);
696 } else if(id
== id_vectors_to_glyphs
) {
697 wrap_filter2(dev
, vectors_to_glyphs
);
698 } else if(id
== id_maketransparent
) {
700 wrap_filter(dev
, maketransparent
, FIX2INT(alpha
));
702 rb_raise(rb_eArgError
, "unknown filter %s", rb_id2name(id
));
708 for(pagenr
=1;pagenr
<=doc
->doc
->num_pages
;pagenr
++) {
709 if(is_in_range(pagenr
, (char*)range
)) {
710 gfxpage_t
*page
= doc
->doc
->getpage(doc
->doc
, pagenr
);
711 dev
->startpage(dev
, page
->width
, page
->height
);
712 page
->render(page
, dev
);
719 gfxresult_t
*r
= dev
->finish(dev
);
725 static VALUE
doc_prepare(VALUE cls
, VALUE device
)
728 make_device(dev
, doc
, device
);
729 doc
->doc
->prepare(doc
->doc
, &dev
);
734 // ---------------------- global functions ----------------------------------
736 VALUE
gfx_setparameter(VALUE module
, VALUE _key
, VALUE _value
)
738 Check_Type(_key
, T_STRING
);
739 Check_Type(_value
, T_STRING
);
740 const char*key
= StringValuePtr(_key
);
741 const char*value
= StringValuePtr(_value
);
742 pdfdriver
->setparameter(pdfdriver
, key
, value
);
743 swfdriver
->setparameter(swfdriver
, key
, value
);
744 imagedriver
->setparameter(imagedriver
, key
, value
);
748 // --------------------------------------------------------------------------
752 initLog(0,0,0,0,0,2);
761 pdfdriver
= gfxsource_pdf_create();
762 swfdriver
= gfxsource_swf_create();
763 imagedriver
= gfxsource_image_create();
765 GFX
= rb_define_module("GFX");
766 rb_define_const(GFX
, "VERSION", INT2FIX(20100309));
768 rb_define_module_function(GFX
, "setparameter", gfx_setparameter
, 2);
770 DocumentPage
= rb_define_class_under(GFX
, "DocumentPage", rb_cObject
);
771 rb_define_method(DocumentPage
, "width", page_width
, 0);
772 rb_define_method(DocumentPage
, "height", page_height
, 0);
773 rb_define_method(DocumentPage
, "nr", page_nr
, 0);
774 rb_define_method(DocumentPage
, "render", page_render
, 1);
776 Document
= rb_define_class_under(GFX
, "Document", rb_cObject
);
777 rb_define_method(Document
, "initialize", doc_initialize
, 1);
778 rb_define_method(Document
, "page", doc_get_page
, 1);
779 rb_define_method(Document
, "each_page", doc_each_page
, 0);
780 rb_define_method(Document
, "prepare", doc_prepare
, 1);
781 rb_define_method(Document
, "render", doc_render
, 3);
783 Bitmap
= rb_define_class_under(GFX
, "Bitmap", rb_cObject
);
784 rb_define_method(Bitmap
, "save_jpeg", image_save_jpeg
, 2);
785 rb_define_method(Bitmap
, "save_png", image_save_png
, 1);
786 rb_define_method(Bitmap
, "width", image_width
, 0);
787 rb_define_method(Bitmap
, "height", image_height
, 0);
788 rb_define_method(Bitmap
, "rescale", image_rescale
, 2);
789 rb_define_method(Bitmap
, "has_alpha", image_has_alpha
, 0);
791 Glyph
= rb_define_class_under(GFX
, "Glyph", rb_cObject
);
792 rb_define_method(Glyph
, "polygon", glyph_polygon
, 0);
793 rb_define_method(Glyph
, "unicode", glyph_unicode
, 0);
794 rb_define_method(Glyph
, "advance", glyph_advance
, 0);
795 rb_define_method(Glyph
, "bbox", glyph_bbox
, 0);
797 Font
= rb_define_class_under(GFX
, "Font", rb_cObject
);
798 rb_define_method(Font
, "name", font_name
, 0);
799 rb_define_method(Font
, "ascent", font_ascent
, 0);
800 rb_define_method(Font
, "descent", font_descent
, 0);
801 rb_define_method(Font
, "glyphs", font_glyphs
, 0);
802 rb_define_method(Font
, "save_ttf", font_save_ttf
, 1);
803 rb_define_method(Font
, "save_eot", font_save_eot
, 1);
805 Device
= rb_define_class_under(GFX
, "Device", rb_cObject
);
806 rb_define_method(Device
, "startpage", noop
, -1);
807 rb_define_method(Device
, "endpage", noop
, -1);
808 rb_define_method(Device
, "startclip", noop
, -1);
809 rb_define_method(Device
, "endclip", noop
, -1);
810 rb_define_method(Device
, "stroke", noop
, -1);
811 rb_define_method(Device
, "fill", noop
, -1);
812 rb_define_method(Device
, "fillbitmap", noop
, -1);
813 rb_define_method(Device
, "fillgradient", noop
, -1);
814 rb_define_method(Device
, "addfont", noop
, -1);
815 rb_define_method(Device
, "drawchar", noop
, -1);
816 rb_define_method(Device
, "drawlink", noop
, -1);
818 PDFClass
= rb_define_class_under(GFX
, "PDF", Document
);
819 rb_define_alloc_func(PDFClass
, pdf_allocate
);
821 SWFClass
= rb_define_class_under(GFX
, "SWF", Document
);
822 rb_define_alloc_func(SWFClass
, swf_allocate
);
824 ImageClass
= rb_define_class_under(GFX
, "ImageRead", Document
);
825 rb_define_alloc_func(ImageClass
, imgdrv_allocate
);
827 id_setparameter
= rb_intern("setparameter");
828 id_startpage
= rb_intern("startpage") ;
829 id_startclip
= rb_intern("startclip") ;
830 id_endclip
= rb_intern("endclip") ;
831 id_stroke
= rb_intern("stroke") ;
832 id_fill
= rb_intern("fill") ;
833 id_fillbitmap
= rb_intern("fillbitmap") ;
834 id_fillgradient
= rb_intern("fillgradient") ;
835 id_addfont
= rb_intern("addfont") ;
836 id_drawchar
= rb_intern("drawchar") ;
837 id_drawlink
= rb_intern("drawlink") ;
838 id_endpage
= rb_intern("endpage") ;
839 id_geterror
= rb_intern("geterror") ;
840 id_finish
= rb_intern("finish") ;
841 id_butt
= rb_intern("butt");
842 id_round
= rb_intern("round");
843 id_square
= rb_intern("square");
844 id_miter
= rb_intern("miter");
845 id_bevel
= rb_intern("bevel");
846 id_move
= rb_intern("move");
847 id_line
= rb_intern("line");
848 id_spline
= rb_intern("spline");
849 id_radial
= rb_intern("radial");
850 id_linear
= rb_intern("linear");
851 id_remove_font_transforms
= rb_intern("remove_font_transforms");
852 id_maketransparent
= rb_intern("maketransparent");
853 id_vectors_to_glyphs
= rb_intern("vectors_to_glyphs");