fixed Makefiles, made rbgfx mem handling more robust
[swftools.git] / lib / ruby / gfx.c
1 #include <ruby.h>
2 #include "../gfxdevice.h"
3 #include "../gfxsource.h"
4 #include "../gfxtools.h"
5 #include "../devices/pdf.h"
6 #include "../readers/swf.h"
7 #include "../readers/image.h"
8 #include "../pdf/pdf.h"
9 #include "../mem.h"
10 #include "../types.h"
11
12 #define RUBY_GFX_VERSION  "0.9.0"
13
14 static VALUE GFX;
15 static VALUE Font, Glyph, Bitmap, Document, DocumentPage, PDFClass, SWFClass, ImageClass, Device;
16 static ID id_doc;
17
18 typedef struct doc_internal {
19     VALUE self;
20     gfxsource_t*driver; // filled by alloc
21     gfxdocument_t*doc;
22     gfxfontlist_t*fontlist;
23 } doc_internal_t;
24
25 typedef struct page_internal {
26     doc_internal_t*doc;
27     gfxpage_t*page;
28 } page_internal_t;
29
30 typedef struct image_internal {
31     doc_internal_t*doc;
32     gfximage_t*image;
33 } image_internal_t;
34
35 typedef struct font_internal {
36     VALUE self;
37     VALUE glyph_array;
38     gfxfont_t*font;
39 } font_internal_t;
40
41 typedef struct glyph_internal {
42     font_internal_t*font;
43     int nr;
44 } glyph_internal_t;
45
46 static gfxsource_t* pdfdriver = 0;
47 static gfxsource_t* imagedriver = 0;
48 static gfxsource_t* swfdriver = 0;
49
50 #define Get_Doc(doc,cls) doc_internal_t*doc=0;Data_Get_Struct(cls, doc_internal_t, doc);
51 #define Get_Page(page,cls) page_internal_t*page=0;Data_Get_Struct(cls, page_internal_t, page);
52
53 static VALUE doc_allocate(VALUE cls, gfxsource_t*driver);
54 static VALUE page_allocate(VALUE cls);
55
56 // ------------------------ documents ---------------------------------------
57
58 static VALUE doc_initialize(VALUE cls, VALUE _filename)
59 {
60     Check_Type(_filename, T_STRING);
61     Get_Doc(doc,cls);
62     const char*filename = StringValuePtr(_filename);
63     doc->fontlist = gfxfontlist_create();
64     doc->doc = pdfdriver->open(pdfdriver, filename);
65     return cls;
66 }
67
68 static VALUE doc_num_pages(VALUE cls)
69 {
70     Get_Doc(doc,cls)
71     return INT2FIX(doc->doc->num_pages);
72 }
73
74 static VALUE doc_get_page(VALUE cls, VALUE _nr)
75 {
76     Check_Type(_nr, T_FIXNUM);
77     int nr = FIX2INT(_nr);
78     Get_Doc(doc,cls);
79
80     VALUE v = page_allocate(DocumentPage);
81     Get_Page(page,v)
82     page->page = doc->doc->getpage(doc->doc, nr);
83     page->doc = doc;
84     if(!page->page) {
85         rb_raise(rb_eArgError, "No page %d in document", nr);
86         return;
87     }
88     return v;
89 }
90
91 static VALUE doc_each_page(VALUE cls)
92 {
93     Get_Doc(doc,cls);
94     int t;
95     for(t=1;t<=doc->doc->num_pages;t++) {
96         VALUE v = page_allocate(DocumentPage);
97         Get_Page(page,v)
98         page->page = doc->doc->getpage(doc->doc, t);
99         page->doc = doc;
100         rb_yield(v);
101     }
102     return cls;
103 }
104
105 static void doc_mark(doc_internal_t*doc)
106 {
107     gfxfontlist_t*l = doc->fontlist;
108     while(l) {
109         if(l->user) 
110             rb_gc_mark((VALUE)l->user);
111         l = l->next;
112     }
113 }
114
115 static void doc_free(doc_internal_t*doc)
116 {
117     gfxfontlist_free(doc->fontlist, 0);
118     doc->doc->destroy(doc->doc);
119     free(doc);
120 }
121
122 static VALUE doc_allocate(VALUE cls, gfxsource_t*driver)
123 {
124     doc_internal_t*doc = 0;
125     VALUE v = Data_Make_Struct(cls, doc_internal_t, doc_mark, doc_free, doc);
126     doc->self = v;
127     memset(doc, 0, sizeof(doc_internal_t));
128     doc->driver = driver;
129     return v;
130 }
131
132 static VALUE pdf_allocate(VALUE cls) {return doc_allocate(cls, pdfdriver);}
133 static VALUE swf_allocate(VALUE cls) {return doc_allocate(cls, swfdriver);}
134 static VALUE imgdrv_allocate(VALUE cls) {return doc_allocate(cls, imagedriver);}
135
136 // ------------------------ doc pages ---------------------------------------
137
138 static void page_free(page_internal_t*page)
139 {
140     if(!page) return;
141     if(page->page) {
142         page->page->destroy(page->page);
143         page->page = 0;
144     }
145     free(page);
146 }
147 static void page_mark(page_internal_t*page)
148 {
149     rb_gc_mark(page->doc->self);
150 }
151 static VALUE page_allocate(VALUE cls)
152 {
153     page_internal_t*page = 0;
154     VALUE v = Data_Make_Struct(cls, page_internal_t, page_mark, page_free, page);
155     memset(page, 0, sizeof(page_internal_t));
156     return v;
157 }
158 static VALUE page_nr(VALUE cls)
159 {
160     Get_Page(page,cls)
161     return INT2FIX(page->page->nr);
162 }
163 static VALUE page_width(VALUE cls)
164 {
165     Get_Page(page,cls)
166     return INT2FIX(page->page->width);
167 }
168 static VALUE page_height(VALUE cls)
169 {
170     Get_Page(page,cls)
171     return INT2FIX(page->page->height);
172 }
173
174 // ------------------------ image -------------------------------------------
175
176 #define Get_Image(image,cls) image_internal_t*image=0;Data_Get_Struct(cls, image_internal_t, image);
177
178 static void image_free(image_internal_t*image)
179 {
180     free(image);
181 }
182 static void image_mark(image_internal_t*image)
183 {
184     rb_gc_mark(image->doc->self);
185 }
186 static VALUE image_allocate(VALUE cls)
187 {
188     image_internal_t*image = 0;
189     VALUE v = Data_Make_Struct(cls, image_internal_t, image_mark, image_free, image);
190     memset(image, 0, sizeof(image_internal_t));
191     return v;
192 }
193 static VALUE image_width(VALUE cls)
194 {
195     Get_Image(image,cls)
196     return INT2FIX(image->image->width);
197 }
198 static VALUE image_height(VALUE cls)
199 {
200     Get_Image(image,cls)
201     return INT2FIX(image->image->height);
202 }
203 static VALUE image_save_jpeg(VALUE cls, VALUE _filename, VALUE quality)
204 {
205     Get_Image(image,cls)
206     Check_Type(_filename, T_STRING);
207     Check_Type(quality, T_FIXNUM);
208     const char*filename = StringValuePtr(_filename);
209     int l = strlen(filename);
210     char jpeg = 0;
211     if(l>=4 && !strcmp(&filename[l-4], ".jpg")) jpeg = 1;
212     if(l>=5 && !strcmp(&filename[l-5], ".jpeg")) jpeg = 1;
213     if(l>=4 && !strcmp(&filename[l-4], ".JPG")) jpeg = 1;
214     jpeg_save(image->image->data, image->image->width, image->image->height, FIX2INT(quality), filename);
215     return cls;
216 }
217 VALUE convert_image(doc_internal_t*doc,gfximage_t*_image)
218 {
219     VALUE v = image_allocate(Bitmap);
220     Get_Image(image,v)
221     image->image = _image;
222     image->doc = doc;
223     return v;
224 }
225 void invalidate_image(VALUE v)
226 {
227     Get_Image(image,v)
228     image->image = 0;
229 }
230
231 // ------------------------ glyphs ------------------------------------------
232
233 static VALUE convert_line(gfxline_t*line);
234
235 #define Get_Glyph(glyph,cls) glyph_internal_t*glyph=0;Data_Get_Struct(cls, glyph_internal_t, glyph);
236
237 static void glyph_free(glyph_internal_t*glyph)
238 {
239     free(glyph);
240 }
241
242 static void glyph_mark(glyph_internal_t*glyph)
243 {
244     rb_gc_mark(glyph->font->self);
245 }
246
247 static VALUE glyph_allocate(VALUE cls)
248 {
249     glyph_internal_t*glyph = 0;
250     VALUE v = Data_Make_Struct(cls, glyph_internal_t, glyph_mark, glyph_free, glyph);
251     memset(glyph, 0, sizeof(glyph_internal_t));
252     return v;
253 }
254
255 static VALUE glyph_polygon(VALUE cls)
256 {
257     Get_Glyph(glyph,cls);
258     return convert_line(glyph->font->font->glyphs[glyph->nr].line);
259 }
260
261 static VALUE glyph_advance(VALUE cls)
262 {
263     Get_Glyph(glyph,cls);
264     return rb_float_new(glyph->font->font->glyphs[glyph->nr].advance);
265 }
266
267 static VALUE glyph_unicode(VALUE cls)
268 {
269     Get_Glyph(glyph,cls);
270     return INT2FIX(glyph->font->font->glyphs[glyph->nr].unicode);
271 }
272
273 // ------------------------ font --------------------------------------------
274
275 #define Get_Font(font,cls) font_internal_t*font=0;Data_Get_Struct(cls, font_internal_t, font);
276
277 static void font_mark(font_internal_t*font)
278 {
279     rb_gc_mark(font->glyph_array);
280 }
281
282 static void font_free(font_internal_t*font)
283 {
284     free(font);
285 }
286
287 static VALUE font_allocate(VALUE cls)
288 {
289     font_internal_t*font = 0;
290     VALUE v = Data_Make_Struct(cls, font_internal_t, font_mark, font_free, font);
291     memset(font, 0, sizeof(font_internal_t));
292     font->self = v;
293     return v;
294 }
295
296 static VALUE font_name(VALUE cls)
297 {
298     Get_Font(font,cls);
299     return rb_tainted_str_new2(font->font->id);
300 }
301
302 static VALUE font_glyphs(VALUE cls)
303 {
304     Get_Font(font,cls);
305     return font->glyph_array;
306 }
307
308 // ------------------------ gfx device --------------------------------------
309
310 typedef struct device_internal {
311     doc_internal_t*doc;
312     VALUE v;
313 } device_internal_t;
314
315 static ID id_setparameter = 0;
316 static ID id_startpage = 0;
317 static ID id_startclip = 0;
318 static ID id_endclip = 0;
319 static ID id_stroke = 0;
320 static ID id_fill = 0;
321 static ID id_fillbitmap = 0;
322 static ID id_fillgradient = 0;
323 static ID id_addfont = 0;
324 static ID id_drawchar = 0;
325 static ID id_drawlink = 0;
326 static ID id_endpage = 0;
327 static ID id_geterror = 0;
328 static ID id_finish = 0;
329 static ID id_butt = 0;
330 static ID id_round = 0;
331 static ID id_square = 0;
332 static ID id_bevel = 0;
333 static ID id_miter = 0;
334 static ID id_move = 0;
335 static ID id_line = 0;
336 static ID id_spline = 0;
337 static ID id_radial = 0;
338 static ID id_linear = 0;
339
340 static VALUE noop(int argc, VALUE *argv, VALUE obj) {return obj;}
341
342 #define forward(v,id,args...) rb_respond_to((v), (id))?rb_funcall((v), (id), args):0
343
344 VALUE convert_line(gfxline_t*line)
345 {
346     int len = 0;
347     gfxline_t*l = line;
348     while(l) {l=l->next;len++;}
349
350     volatile VALUE array = rb_ary_new2(len);
351
352     int pos = 0;
353     l = line;
354     while(l) {
355         volatile VALUE e;
356         if(l->type == gfx_moveTo) {
357             e = rb_ary_new3(3, ID2SYM(id_move), Qfalse, Qfalse);
358             rb_ary_store(array, pos, e);
359             rb_ary_store(e, 1, rb_float_new(l->x));
360             rb_ary_store(e, 2, rb_float_new(l->y));
361         } else if(l->type == gfx_lineTo) {
362             e = rb_ary_new3(3, ID2SYM(id_line), Qfalse, Qfalse);
363             rb_ary_store(array, pos, e);
364             rb_ary_store(e, 1, rb_float_new(l->x));
365             rb_ary_store(e, 2, rb_float_new(l->y));
366         } else {
367             e = rb_ary_new3(5, ID2SYM(id_spline), Qfalse, Qfalse, Qfalse, Qfalse);
368             rb_ary_store(array, pos, e);
369             rb_ary_store(e, 1, rb_float_new(l->x));
370             rb_ary_store(e, 2, rb_float_new(l->y));
371             rb_ary_store(e, 3, rb_float_new(l->sx));
372             rb_ary_store(e, 4, rb_float_new(l->sy));
373         }
374         pos++;
375         l=l->next;
376     }
377     return array;
378 }
379 VALUE convert_color(gfxcolor_t*color)
380 {
381     return rb_ary_new3(4, INT2FIX(color->a), INT2FIX(color->r), INT2FIX(color->g), INT2FIX(color->b));
382 }
383 VALUE convert_matrix(gfxmatrix_t*matrix)
384 {
385     volatile VALUE array = rb_ary_new2(3);
386     volatile VALUE a = rb_ary_new2(2);
387     rb_ary_store(array, 0, a);
388     rb_ary_store(a, 0, rb_float_new(matrix->m00));
389     rb_ary_store(a, 1, rb_float_new(matrix->m01));
390     a = rb_ary_new2(2);
391     rb_ary_store(array, 1, a);
392     rb_ary_store(a, 0, rb_float_new(matrix->m10));
393     rb_ary_store(a, 1, rb_float_new(matrix->m11));
394     a = rb_ary_new2(2);
395     rb_ary_store(array, 2, a);
396     rb_ary_store(a, 0, rb_float_new(matrix->tx));
397     rb_ary_store(a, 1, rb_float_new(matrix->ty));
398     return array;
399 }
400 static VALUE font_is_cached(device_internal_t*i, gfxfont_t*font)
401 {
402     return (VALUE)gfxfontlist_getuserdata(i->doc->fontlist, font->id);
403 }
404 static void cache_font(device_internal_t*i, gfxfont_t*font, VALUE v)
405 {
406     i->doc->fontlist = gfxfontlist_addfont2(i->doc->fontlist, font, (void*)v);
407 }
408 static VALUE convert_font(gfxfont_t*font)
409 {
410     volatile VALUE v2 = font_allocate(Font);
411     Get_Font(f, v2);
412     f->font = font;
413     f->glyph_array = rb_ary_new2(font->num_glyphs);
414
415     int t;
416     for(t=0;t<font->num_glyphs;t++) {
417         volatile VALUE a = glyph_allocate(Glyph);
418         rb_ary_store(f->glyph_array, t, a);
419         Get_Glyph(g, a);
420         g->font = f;
421         g->nr = t;
422     }
423     return v2;
424 }
425 #define HEAD \
426     device_internal_t*i = (device_internal_t*)dev->internal; \
427     VALUE v = i->v;
428 int rb_setparameter(gfxdevice_t*dev, const char*key, const char*value)
429 {
430     HEAD
431     volatile VALUE v_key = rb_tainted_str_new2(key);
432     volatile VALUE v_value = rb_tainted_str_new2(value);
433     VALUE ret = forward(v,id_setparameter,2,v_key,v_value);
434     return 0;
435 }
436 void rb_startpage(gfxdevice_t*dev, int width, int height)
437 {
438     HEAD
439     VALUE ret = forward(v,id_startpage,2,INT2FIX(width),INT2FIX(height));
440 }
441 void rb_startclip(gfxdevice_t*dev, gfxline_t*line)
442 {
443     HEAD
444     volatile VALUE v_line = convert_line(line);
445     VALUE ret = forward(v,id_startclip,1,v_line);
446 }
447 void rb_endclip(gfxdevice_t*dev)
448 {
449     HEAD
450     VALUE ret = forward(v,id_endclip,0);
451 }
452 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)
453 {
454     HEAD
455     
456     ID cap = 0;
457     if(cap_style == gfx_capButt) cap = id_butt;
458     else if(cap_style == gfx_capRound) cap = id_round;
459     else if(cap_style == gfx_capSquare) cap = id_square;
460     
461     ID joint = 0;
462     if(joint_style == gfx_joinRound) joint = id_round;
463     else if(joint_style == gfx_joinMiter) joint = id_miter;
464     else if(joint_style == gfx_joinBevel) joint = id_bevel;
465
466     volatile VALUE v_line = convert_line(line);
467     volatile VALUE v_width = rb_float_new(width);
468     volatile VALUE v_color = convert_color(color);
469     volatile VALUE v_miter = rb_float_new(miterLimit);
470     forward(v, id_stroke, 6, v_line, v_width, v_color, ID2SYM(cap), ID2SYM(joint), v_miter);
471 }
472 void rb_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
473 {
474     HEAD
475     
476     volatile VALUE v_line = convert_line(line);
477     volatile VALUE v_color = convert_color(color);
478     forward(v, id_fill, 2, v_line, v_color);
479 }
480 void rb_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
481 {
482     HEAD
483     volatile VALUE v_image = convert_image(i->doc, img);
484     volatile VALUE v_line = convert_line(line);
485     volatile VALUE v_matrix = convert_matrix(matrix);
486     forward(v, id_fillbitmap, 4, v_line, v_image, v_matrix, Qnil);
487     invalidate_image(v_image);
488 }
489 void rb_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
490 {
491     HEAD
492     ID typeid = (type == gfxgradient_linear)? id_linear : id_radial;
493     
494     volatile VALUE v_line = convert_line(line);
495     volatile VALUE v_matrix = convert_matrix(matrix);
496     volatile VALUE v_gradient = convert_gradient(gradient);
497     forward(v, id_fillgradient, 4, v_line, v_gradient, ID2SYM(typeid), v_matrix);
498 }
499 void rb_addfont(gfxdevice_t*dev, gfxfont_t*font)
500 {
501     HEAD
502
503     volatile VALUE f = font_is_cached(i, font);
504     if(!f) {f=convert_font(font);cache_font(i,font,v);}
505
506     forward(v, id_addfont, 1, f);
507 }
508 void rb_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
509 {
510     HEAD
511     volatile VALUE f = font_is_cached(i, font);
512     if(!f) {f=convert_font(font);cache_font(i,font,v);}
513
514     volatile VALUE v_color = convert_color(color);
515     volatile VALUE v_matrix = convert_matrix(matrix);
516     forward(v, id_drawchar, 4, f, INT2FIX(glyphnr), v_color, v_matrix);
517 }
518 void rb_drawlink(gfxdevice_t*dev, gfxline_t*line, const char*action)
519 {
520     HEAD
521     volatile VALUE v_line = convert_line(line);
522     volatile VALUE v_action = rb_tainted_str_new2(action);
523     forward(v, id_drawlink, v_line, v_action);
524 }
525 void rb_endpage(gfxdevice_t*dev)
526 {
527     HEAD
528     forward(v, id_endpage, 0);
529 }
530 gfxresult_t* rb_finish(gfxdevice_t*dev)
531 {
532     HEAD
533     VALUE ret = forward(v, id_endpage, 0);
534     gfxresult_t*r = (gfxresult_t*)rfx_calloc(sizeof(gfxresult_t));
535     r->internal = (void*)(ptroff_t)ret;
536     return r;
537 }
538
539 static VALUE page_render(VALUE cls, VALUE device)
540 {
541     Check_Type(device, T_OBJECT);
542     Get_Page(page,cls)
543
544     gfxdevice_t dev;
545     device_internal_t i;
546     i.v = device;
547     i.doc = page->doc;
548
549     dev.internal = &i;
550     dev.setparameter = rb_setparameter;
551     dev.startpage = rb_startpage;
552     dev.startclip = rb_startclip;
553     dev.endclip = rb_endclip;
554     dev.stroke = rb_stroke;
555     dev.fill = rb_fill;
556     dev.fillbitmap = rb_fillbitmap;
557     dev.fillgradient = rb_fillgradient;
558     dev.addfont = rb_addfont;
559     dev.drawchar = rb_drawchar;
560     dev.drawlink = rb_drawlink;
561     dev.endpage = rb_endpage;
562     dev.finish = rb_finish;
563
564     page->page->render(page->page, &dev);
565
566     return cls;
567 }
568
569
570 // --------------------------------------------------------------------------
571
572 void Init_gfx()
573 {
574     initLog(0,0,0,0,0,2);
575     pdfdriver = gfxsource_pdf_create();
576     swfdriver = gfxsource_swf_create();
577     imagedriver = gfxsource_image_create();
578
579     GFX = rb_define_module("GFX");
580     
581     DocumentPage = rb_define_class_under(GFX, "DocumentPage", rb_cObject);
582     rb_define_method(DocumentPage, "width", page_width, 0);
583     rb_define_method(DocumentPage, "height", page_height, 0);
584     rb_define_method(DocumentPage, "nr", page_nr, 0);
585     rb_define_method(DocumentPage, "render", page_render, 1);
586
587     Document = rb_define_class_under(GFX, "Document", rb_cObject);
588     rb_define_method(Document, "initialize", doc_initialize, 1);
589     rb_define_method(Document, "page", doc_get_page, 1);
590     rb_define_method(Document, "each_page", doc_each_page, 0);
591     
592     Bitmap = rb_define_class_under(GFX, "Bitmap", rb_cObject);
593     rb_define_method(Bitmap, "save_jpeg", image_save_jpeg, 2);
594     
595     Glyph = rb_define_class_under(GFX, "Glyph", rb_cObject);
596     rb_define_method(Glyph, "polygon", glyph_polygon, 0);
597     rb_define_method(Glyph, "unicode", glyph_unicode, 0);
598     rb_define_method(Glyph, "advance", glyph_advance, 0);
599     
600     Font = rb_define_class_under(GFX, "Font", rb_cObject);
601     rb_define_method(Font, "name", font_name, 0);
602     rb_define_method(Font, "glyphs", font_glyphs, 0);
603     
604     Device = rb_define_class_under(GFX, "Device", rb_cObject);
605     rb_define_method(Device, "startpage", noop, -1);
606     rb_define_method(Device, "endpage", noop, -1);
607     rb_define_method(Device, "startclip", noop, -1);
608     rb_define_method(Device, "endclip", noop, -1);
609     rb_define_method(Device, "stroke", noop, -1);
610     rb_define_method(Device, "fill", noop, -1);
611     rb_define_method(Device, "fillbitmap", noop, -1);
612     rb_define_method(Device, "fillgradient", noop, -1);
613     rb_define_method(Device, "addfont", noop, -1);
614     rb_define_method(Device, "drawchar", noop, -1);
615     rb_define_method(Device, "drawlink", noop, -1);
616     rb_define_method(Device, "endpage", noop, -1);
617
618     PDFClass = rb_define_class_under(GFX, "PDF", Document);
619     rb_define_alloc_func(PDFClass, pdf_allocate);
620     
621     SWFClass = rb_define_class_under(GFX, "SWF", Document);
622     rb_define_alloc_func(SWFClass, swf_allocate);
623     
624     ImageClass = rb_define_class_under(GFX, "ImageRead", Document);
625     rb_define_alloc_func(ImageClass, imgdrv_allocate);
626
627     id_setparameter = rb_intern("setparameter");
628     id_startpage = rb_intern("startpage") ;
629     id_startclip = rb_intern("startclip") ;
630     id_endclip = rb_intern("endclip") ;
631     id_stroke = rb_intern("stroke") ;
632     id_fill = rb_intern("fill") ;
633     id_fillbitmap = rb_intern("fillbitmap") ;
634     id_fillgradient = rb_intern("fillgradient") ;
635     id_addfont = rb_intern("addfont") ;
636     id_drawchar = rb_intern("drawchar") ;
637     id_drawlink = rb_intern("drawlink") ;
638     id_endpage = rb_intern("endpage") ;
639     id_geterror = rb_intern("geterror") ;
640     id_finish = rb_intern("finish") ;
641     id_butt = rb_intern("butt");
642     id_round = rb_intern("round");
643     id_square = rb_intern("square");
644     id_miter = rb_intern("miter");
645     id_bevel = rb_intern("bevel");
646     id_move = rb_intern("move");
647     id_line = rb_intern("line");
648     id_spline = rb_intern("spline");
649     id_radial = rb_intern("radial");
650     id_linear = rb_intern("linear");
651 }
652