changed addfont/drawchar prototype
[swftools.git] / lib / devices / render.c
1 /* gfxdevice_bitmap.cc
2
3    Part of the swftools package.
4
5    Copyright (c) 2005 Matthias Kramm <kramm@quiss.org> 
6  
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <math.h>
24 #include <memory.h>
25 #include "../gfxdevice.h"
26 #include "../gfxtools.h"
27 #include "../png.h"
28 #include "../mem.h"
29
30 typedef unsigned int U32;
31 typedef unsigned char U8;
32
33 typedef gfxcolor_t RGBA;
34
35 typedef struct _renderpoint
36 {
37     float x;
38 } renderpoint_t;
39
40 typedef struct _renderline
41 {
42     renderpoint_t*points;
43     int size;
44     int num;
45 } renderline_t;
46
47 typedef struct _internal_result {
48     int width;
49     int height;
50     RGBA* img;
51     struct _internal_result*next;
52 } internal_result_t;
53
54 typedef struct _clipbuffer {
55     U32*data;
56     int linesize;
57     struct _clipbuffer*prev;
58 } clipbuffer_t;
59
60 typedef struct _internal {
61     int width;
62     int height;
63     int width2;
64     int height2;
65     int multiply;
66     int antialize;
67     int ymin, ymax;
68
69     int depth;
70
71     RGBA* img;
72     int* zbuf; 
73
74     gfxfont_t*font;
75     char*fontid;
76     
77     clipbuffer_t*clipbufs;
78     clipbuffer_t*clipbuf;
79
80     renderline_t*lines;
81
82     internal_result_t*results;
83     internal_result_t*result_next;
84 } internal_t;
85
86 typedef enum {filltype_solid,filltype_clip,filltype_bitmap} filltype_t;
87
88 typedef struct _fillinfo {
89     filltype_t type; //0=solid,1=clip
90     gfxcolor_t*color;
91     gfximage_t*image;
92     gfxmatrix_t*matrix;
93     gfxcxform_t*cxform;
94     char clip;
95 } fillinfo_t;
96
97
98 static inline void add_pixel(internal_t*i, float x, int y)
99 {
100     renderpoint_t p;
101
102     if(x >= i->width2 || y >= i->height2 || y<0) return;
103     p.x = x;
104     if(y<i->ymin) i->ymin = y;
105     if(y>i->ymax) i->ymax = y;
106
107     renderline_t*l = &i->lines[y];
108
109     if(l->num == l->size) {
110         l->size += 32;
111         l->points = (renderpoint_t*)rfx_realloc(l->points, l->size * sizeof(renderpoint_t));
112     }
113     l->points[l->num] = p;
114     l->num++;
115 }
116
117 /* set this to 0.777777 or something if the "both fillstyles set while not inside shape"
118    problem appears to often */
119 #define CUT 0.5
120
121 #define INT(x) ((int)((x)+16)-16)
122
123 static void add_line(gfxdevice_t*dev , double x1, double y1, double x2, double y2)
124 {
125     internal_t*i = (internal_t*)dev->internal;
126     double diffx, diffy;
127     double ny1, ny2, stepx;
128 /*    if(DEBUG&4) {
129         int l = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
130         printf(" l[%d - %.2f/%.2f -> %.2f/%.2f]\n", l, x1/20.0, y1/20.0, x2/20.0, y2/20.0);
131     }*/
132
133     if(y2 < y1) {
134         double x;
135         double y;
136         x = x1;x1 = x2;x2=x;
137         y = y1;y1 = y2;y2=y;
138     }
139     
140     diffx = x2 - x1;
141     diffy = y2 - y1;
142     
143     ny1 = INT(y1)+CUT;
144     ny2 = INT(y2)+CUT;
145
146     if(ny1 < y1) {
147         ny1 = INT(y1) + 1.0 + CUT;
148     }
149     if(ny2 >= y2) {
150         ny2 = INT(y2) - 1.0 + CUT;
151     }
152
153     if(ny1 > ny2)
154         return;
155
156     stepx = diffx/diffy;
157     x1 = x1 + (ny1-y1)*stepx;
158     x2 = x2 + (ny2-y2)*stepx;
159
160     {
161         int posy=INT(ny1);
162         int endy=INT(ny2);
163         double posx=0;
164         double startx = x1;
165
166         while(posy<=endy) {
167             float xx = (float)(startx + posx);
168             add_pixel(i, xx ,posy);
169             posx+=stepx;
170             posy++;
171         }
172     }
173 }
174 #define PI 3.14159265358979
175 static void add_solidline(gfxdevice_t*dev, double x1, double y1, double x2, double y2, double width)
176 {
177     internal_t*i = (internal_t*)dev->internal;
178
179     double dx = x2-x1;
180     double dy = y2-y1;
181     double sd;
182     double d;
183
184     int t;
185     int segments;
186     double lastx,lasty;
187     double vx,vy;
188     double xx,yy;
189   
190     /* Make sure the line is always at least one pixel wide */
191 #ifdef LINEMODE1
192     /* That's what Macromedia's Player does at least at zoom level >= 1.  */
193     width += 1.0;
194 #else
195     /* That's what Macromedia's Player seems to do at zoom level 0.  */
196     /* TODO: needs testing */
197
198     /* TODO: how does this interact with scaling? */
199     if(width * i->multiply < 1.0)
200         width = 1.0 / i->multiply;
201 #endif
202
203     sd = (double)dx*(double)dx+(double)dy*(double)dy;
204     d = sqrt(sd);
205
206     if(!dx && !dy) {
207         vx = 1;
208         vy = 0;
209     } else {
210         vx = ( dy/d);
211         vy = (-dx/d);
212     }
213
214     segments = width/2;
215     if(segments < 2)
216         segments = 2;
217
218     segments = 8;
219
220     vx=vx*width*0.5;
221     vy=vy*width*0.5;
222
223     xx = x2+vx;
224     yy = y2+vy;
225     add_line(dev, x1+vx, y1+vy, xx, yy);
226     lastx = xx;
227     lasty = yy;
228     for(t=1;t<segments;t++) {
229         double s = sin(t*PI/segments);
230         double c = cos(t*PI/segments);
231         xx = (x2 + vx*c - vy*s);
232         yy = (y2 + vx*s + vy*c);
233         add_line(dev, lastx, lasty, xx, yy);
234         lastx = xx;
235         lasty = yy;
236     }
237     
238     xx = (x2-vx);
239     yy = (y2-vy);
240     add_line(dev, lastx, lasty, xx, yy);
241     lastx = xx;
242     lasty = yy;
243     xx = (x1-vx);
244     yy = (y1-vy);
245     add_line(dev, lastx, lasty, xx, yy);
246     lastx = xx;
247     lasty = yy;
248     for(t=1;t<segments;t++) {
249         double s = sin(t*PI/segments);
250         double c = cos(t*PI/segments);
251         xx = (x1 - vx*c + vy*s);
252         yy = (y1 - vx*s - vy*c);
253         add_line(dev, lastx, lasty, xx, yy);
254         lastx = xx;
255         lasty = yy;
256     }
257     add_line(dev, lastx, lasty, (x1+vx), (y1+vy));
258 }
259
260 static int compare_renderpoints(const void * _a, const void * _b)
261 {
262     renderpoint_t*a = (renderpoint_t*)_a;
263     renderpoint_t*b = (renderpoint_t*)_b;
264     if(a->x < b->x) return -1;
265     if(a->x > b->x) return 1;
266     return 0;
267 }
268
269 static void fill_line_solid(RGBA*line, U32*z, int y, int x1, int x2, RGBA col)
270 {
271     int x = x1;
272
273     U32 bit = 1<<(x1&31);
274     int bitpos = (x1/32);
275
276     if(col.a!=255) {
277         int ainv = 255-col.a;
278         col.r = (col.r*col.a)>>8;
279         col.g = (col.g*col.a)>>8;
280         col.b = (col.b*col.a)>>8;
281         col.a = 255;
282         do {
283             if(z[bitpos]&bit) {
284                 line[x].r = ((line[x].r*ainv)>>8)+col.r;
285                 line[x].g = ((line[x].g*ainv)>>8)+col.g;
286                 line[x].b = ((line[x].b*ainv)>>8)+col.b;
287                 line[x].a = 255;
288             }
289             bit <<= 1;
290             if(!bit) {
291                 bit = 1;bitpos++;
292             }
293         } while(++x<x2);
294     } else {
295         do {
296             if(z[bitpos]&bit) {
297                 line[x] = col;
298             }
299             bit <<= 1;
300             if(!bit) {
301                 bit = 1;bitpos++;
302             }
303         } while(++x<x2);
304     }
305 }
306
307 static void fill_line_bitmap(RGBA*line, U32*z, int y, int x1, int x2, fillinfo_t*info)
308 {
309     int x = x1;
310
311     gfxmatrix_t*m = info->matrix;
312     gfximage_t*b = info->image;
313     
314     double det = m->m00*m->m11 - m->m01*m->m10;
315     if(fabs(det) < 0.0005) { 
316         /* x direction equals y direction- the image is invisible */
317         return;
318     }
319     det = 1.0/det;
320     
321     if(!b->width || !b->height) {
322         gfxcolor_t red = {255,255,0,0};
323         fill_line_solid(line, z, y, x1, x2, red);
324         return;
325     }
326
327     U32 bit = 1<<(x1&31);
328     int bitpos = (x1/32);
329
330     do {
331         if(z[bitpos]&bit) {
332             RGBA col;
333             int xx = (int)((  (x - m->tx) * m->m11 - (y - m->ty) * m->m10)*det);
334             int yy = (int)((- (x - m->tx) * m->m01 + (y - m->ty) * m->m00)*det);
335             int ainv;
336
337             if(info->clip) {
338                 if(xx<0) xx=0;
339                 if(xx>=b->width) xx = b->width-1;
340                 if(yy<0) yy=0;
341                 if(yy>=b->height) yy = b->height-1;
342             } else {
343                 xx %= b->width;
344                 yy %= b->height;
345                 if(xx<0) xx += b->width;
346                 if(yy<0) yy += b->height;
347             }
348
349             col = b->data[yy*b->width+xx];
350             ainv = 255-col.a;
351
352             line[x].r = ((line[x].r*ainv)>>8)+col.r;
353             line[x].g = ((line[x].g*ainv)>>8)+col.g;
354             line[x].b = ((line[x].b*ainv)>>8)+col.b;
355             line[x].a = 255;
356         }
357         bit <<= 1;
358         if(!bit) {
359             bit = 1;bitpos++;
360         }
361     } while(++x<x2);
362 }
363
364 static void fill_line_clip(RGBA*line, U32*z, int y, int x1, int x2)
365 {
366     int x = x1;
367
368     U32 bit = 1<<(x1&31);
369     int bitpos = (x1/32);
370
371     do {
372         z[bitpos]|=bit;
373         bit <<= 1;
374         if(!bit) {
375             bit = 1;bitpos++;
376         }
377     } while(++x<x2);
378 }
379
380 void fill_line(gfxdevice_t*dev, RGBA*line, U32*zline, int y, int startx, int endx, fillinfo_t*fill)
381 {
382     if(fill->type == filltype_solid)
383         fill_line_solid(line, zline, y, startx, endx, *fill->color);
384     else if(fill->type == filltype_clip)
385         fill_line_clip(line, zline, y, startx, endx);
386     else if(fill->type == filltype_bitmap)
387         fill_line_bitmap(line, zline, y, startx, endx, fill);
388     // etc.
389 }
390
391 void fill(gfxdevice_t*dev, fillinfo_t*fill)
392 {
393     internal_t*i = (internal_t*)dev->internal;
394     int y;
395     U32 clipdepth = 0;
396     for(y=i->ymin;y<=i->ymax;y++) {
397         renderpoint_t*points = i->lines[y].points;
398         RGBA*line = &i->img[i->width2*y];
399         int*zline = &i->zbuf[i->width2*y];
400         int n;
401         int num = i->lines[y].num;
402         int lastx;
403         qsort(points, num, sizeof(renderpoint_t), compare_renderpoints);
404
405         for(n=0;n<num;n++) {
406             renderpoint_t*p = &points[n];
407             renderpoint_t*next= n<num-1?&points[n+1]:0;
408             int startx = p->x;
409             int endx = next?next->x:i->width2;
410             if(endx > i->width2)
411                 endx = i->width2;
412             if(startx < 0)
413                 startx = 0;
414             if(endx < 0)
415                 endx = 0;
416
417             if(!(n&1))
418                 fill_line(dev, line, zline, y, startx, endx, fill);
419
420             lastx = endx;
421             if(endx == i->width2)
422                 break;
423         }
424         i->lines[y].num = 0;
425     }
426 }
427
428 void fill_solid(gfxdevice_t*dev, gfxcolor_t* color)
429 {
430     fillinfo_t info;
431     info.type = filltype_solid;
432     info.color = color;
433     fill(dev, &info);
434 }
435
436 int render_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
437 {
438     internal_t*i = (internal_t*)dev->internal;
439     if(!strcmp(key, "antialize")) {
440         i->antialize = atoi(value);
441     } else if(!strcmp(key, "multiply")) {
442         i->multiply = atoi(value);
443     }
444     return 0;
445 }
446
447 void newclip(struct _gfxdevice*dev)
448 {
449     internal_t*i = (internal_t*)dev->internal;
450     
451     clipbuffer_t*c = rfx_calloc(sizeof(clipbuffer_t));
452     c->linesize = ((i->width2+31) / 32);
453     c->data = rfx_calloc(c->linesize * i->height2);
454
455     if(!i->clipbufs) {
456         i->clipbufs = i->clipbuf = c;
457     } else {
458         clipbuffer_t*old = i->clipbuf;
459         i->clipbuf = c;
460         i->clipbuf->prev = old;
461     }
462 }
463
464 void endclip(struct _gfxdevice*dev)
465 {
466     internal_t*i = (internal_t*)dev->internal;
467     
468     if(!i->clipbufs) {
469         fprintf(stderr, "endclip without any active clip buffers");
470         return;
471     }
472     
473     clipbuffer_t*old = i->clipbuf;
474
475     if(i->clipbuf == i->clipbufs)
476         i->clipbufs = 0;
477
478     i->clipbuf = i->clipbuf->prev;
479
480     old->prev = 0;
481     free(old->data);old->data = 0;
482     free(old);
483 }
484
485 void render_stroke(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
486 {
487     internal_t*i = (internal_t*)dev->internal;
488     double x,y;
489     
490     if(cap_style != gfx_capRound || joint_style != gfx_joinRound) {
491         fprintf(stderr, "Warning: cap/joint style != round not yet supported\n");
492     }
493
494     while(line) {
495         int x1,y1,x2,y2,x3,y3;
496
497         if(line->type == gfx_moveTo) {
498         } else if(line->type == gfx_lineTo) {
499             double x1=x,y1=y;
500             double x3=line->x,y3=line->y;
501             add_solidline(dev, x1, y1, x3, y3, width * i->multiply);
502             fill_solid(dev, color);
503         } else if(line->type == gfx_splineTo) {
504             int c,t,parts,qparts;
505             double xx,yy;
506            
507             double x1=x,y1=y;
508             double x2=line->sx,y2=line->sy;
509             double x3=line->x,y3=line->y;
510             
511             c = abs(x3-2*x2+x1) + abs(y3-2*y2+y1);
512             xx=x1;
513             yy=y1;
514
515             parts = (int)(sqrt(c)/3);
516             if(!parts) parts = 1;
517
518             for(t=1;t<=parts;t++) {
519                 double nx = (double)(t*t*x3 + 2*t*(parts-t)*x2 + (parts-t)*(parts-t)*x1)/(double)(parts*parts);
520                 double ny = (double)(t*t*y3 + 2*t*(parts-t)*y2 + (parts-t)*(parts-t)*y1)/(double)(parts*parts);
521                 
522                 add_solidline(dev, xx, yy, nx, ny, width * i->multiply);
523                 fill_solid(dev, color);
524                 xx = nx;
525                 yy = ny;
526             }
527         }
528         x = line->x;
529         y = line->y;
530         line = line->next;
531     }
532 }
533
534 static void draw_line(gfxdevice_t*dev, gfxline_t*line)
535 {
536     internal_t*i = (internal_t*)dev->internal;
537     double x,y;
538
539     while(line)
540     {
541         int x1,y1,x2,y2,x3,y3;
542
543         if(line->type == gfx_moveTo) {
544         } else if(line->type == gfx_lineTo) {
545             double x1=x,y1=y;
546             double x3=line->x,y3=line->y;
547             
548             add_line(dev, x1, y1, x3, y3);
549         } else if(line->type == gfx_splineTo) {
550             int c,t,parts,qparts;
551             double xx,yy;
552             
553             double x1=x,y1=y;
554             double x2=line->sx,y2=line->sy;
555             double x3=line->x,y3=line->y;
556             
557             c = abs(x3-2*x2+x1) + abs(y3-2*y2+y1);
558             xx=x1;
559             yy=y1;
560
561             parts = (int)(sqrt(c)/3);
562             if(!parts) parts = 1;
563
564             for(t=1;t<=parts;t++) {
565                 double nx = (double)(t*t*x3 + 2*t*(parts-t)*x2 + (parts-t)*(parts-t)*x1)/(double)(parts*parts);
566                 double ny = (double)(t*t*y3 + 2*t*(parts-t)*y2 + (parts-t)*(parts-t)*y1)/(double)(parts*parts);
567                 
568                 add_line(dev, xx, yy, nx, ny);
569                 xx = nx;
570                 yy = ny;
571             }
572         }
573         x = line->x;
574         y = line->y;
575         line = line->next;
576     }
577 }
578
579 void render_startclip(struct _gfxdevice*dev, gfxline_t*line)
580 {
581     internal_t*i = (internal_t*)dev->internal;
582     fillinfo_t info;
583     newclip(dev);
584     info.type = filltype_clip;
585     draw_line(dev, line);
586     fill(dev, &info);
587 }
588
589 void render_endclip(struct _gfxdevice*dev)
590 {
591     internal_t*i = (internal_t*)dev->internal;
592     endclip(dev);
593 }
594
595 void render_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color)
596 {
597     internal_t*i = (internal_t*)dev->internal;
598
599     draw_line(dev, line);
600     fill_solid(dev, color);
601 }
602
603 void render_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
604 {
605     internal_t*i = (internal_t*)dev->internal;
606
607     gfxcolor_t black = {255,0,0,0};
608
609     draw_line(dev, line);
610
611     fillinfo_t info;
612     info.type = filltype_bitmap;
613     info.image = img;
614     info.matrix = matrix;
615     info.cxform = cxform;
616     fill(dev, &info);
617 }
618
619 void render_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
620 {
621     internal_t*i = (internal_t*)dev->internal;
622     
623     gfxcolor_t black = {255,0,0,0};
624
625     draw_line(dev, line);
626     fill_solid(dev, &black);
627 }
628
629 void render_addfont(struct _gfxdevice*dev, gfxfont_t*font)
630 {
631 }
632
633 void render_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
634 {
635     internal_t*i = (internal_t*)dev->internal;
636
637     gfxglyph_t*glyph = &font->glyphs[glyphnr];
638     gfxline_t*line2 = gfxline_clone(glyph->line);
639     gfxline_transform(line2, matrix);
640     draw_line(dev, line2);
641     fill_solid(dev, color);
642     gfxline_free(line2);
643     
644     return;
645 }
646
647 void render_result_write(gfxresult_t*r, int filedesc)
648 {
649     internal_result_t*i= (internal_result_t*)r->internal;
650 }
651 int  render_result_save(gfxresult_t*r, char*filename)
652 {
653     internal_result_t*i= (internal_result_t*)r->internal;
654     if(i->next) {
655         int nr=0;
656         while(i->next) {
657             writePNG(filename, (unsigned char*)i->img, i->width, i->height);
658             nr++;
659         }
660     } else {
661         writePNG(filename, (unsigned char*)i->img, i->width, i->height);
662     }
663     return 1;
664 }
665 void*render_result_get(gfxresult_t*r, char*name)
666 {
667     internal_result_t*i= (internal_result_t*)r->internal;
668     return 0;
669 }
670 void render_result_destroy(gfxresult_t*r)
671 {
672     internal_result_t*i= (internal_result_t*)r->internal;
673     free(i); r->internal = 0;
674     free(r);
675 }
676
677 gfxresult_t* render_finish(struct _gfxdevice*dev)
678 {
679     internal_t*i = (internal_t*)dev->internal;
680     
681     gfxresult_t* res = (gfxresult_t*)rfx_calloc(sizeof(gfxresult_t));
682     
683     res->internal = i->results;i->results = 0;
684     res->write = render_result_write;
685     res->save = render_result_save;
686     res->get = render_result_get;
687     res->destroy = render_result_destroy;
688
689     free(dev->internal); dev->internal = 0; i = 0;
690
691     /* TODO: free fonts */
692
693     return res;
694 }
695
696 void render_startpage(struct _gfxdevice*dev, int width, int height)
697 {
698     internal_t*i = (internal_t*)dev->internal;
699     int y;
700
701     if(i->width2 || i->height2) {
702         fprintf(stderr, "Error: startpage() called twice (no endpage()?)\n");
703         exit(1);
704     }
705     
706     i->width = width;
707     i->height = height;
708     i->width2 = width*i->antialize*i->multiply;
709     i->height2 = height*i->antialize*i->multiply;
710
711     i->lines = (renderline_t*)rfx_alloc(i->height2*sizeof(renderline_t));
712     for(y=0;y<i->height2;y++) {
713         memset(&i->lines[y], 0, sizeof(renderline_t));
714         i->lines[y].points = 0;
715         i->lines[y].num = 0;
716     }
717     i->zbuf = (int*)rfx_calloc(sizeof(int)*i->width2*i->height2);
718     i->img = (RGBA*)rfx_calloc(sizeof(RGBA)*i->width2*i->height2);
719     i->ymin = 0x7fffffff;
720     i->ymax = -0x80000000;
721
722     newclip(dev);
723 }
724
725 void render_endpage(struct _gfxdevice*dev)
726 {
727     internal_t*i = (internal_t*)dev->internal;
728     
729     if(!i->width2 || !i->height2) {
730         fprintf(stderr, "Error: endpage() called without corresponding startpage()\n");
731         exit(1);
732     }
733
734     endclip(dev);
735     while(i->clipbufs) {
736         fprintf(stderr, "Warning: unclosed clip while processing endpage()\n");
737         endclip(dev);
738     }
739     
740     internal_result_t*ir= (internal_result_t*)rfx_calloc(sizeof(internal_result_t));
741     ir->width = i->width;
742     ir->height = i->height;
743     ir->img = i->img; i->img = 0;
744     ir->next = 0;
745     if(i->result_next) {
746         i->result_next->next = ir;
747     }
748     if(!i->results) {
749         i->results = ir;
750     }
751     i->result_next = ir;
752
753     rfx_free(i->lines);i->lines=0; //FIXME
754     rfx_free(i->zbuf);i->zbuf = 0;
755     if(i->img) {rfx_free(i->img);i->img = 0;}
756
757     i->width2 = 0;
758     i->height2 = 0;
759 }
760
761 void render_drawlink(struct _gfxdevice*dev, gfxline_t*line, char*action)
762 {
763     /* not supported for this output device */
764 }
765
766 void gfxdevice_render_init(gfxdevice_t*dev)
767 {
768     internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
769     int y;
770     memset(dev, 0, sizeof(gfxdevice_t));
771     dev->internal = i;
772     
773     i->width = 0;
774     i->width2 = 0;
775     i->height = 0;
776     i->height2 = 0;
777     i->antialize = 1;
778     i->multiply = 1;
779
780     dev->setparameter = render_setparameter;
781     dev->startpage = render_startpage;
782     dev->startclip = render_startclip;
783     dev->endclip = render_endclip;
784     dev->stroke = render_stroke;
785     dev->fill = render_fill;
786     dev->fillbitmap = render_fillbitmap;
787     dev->fillgradient = render_fillgradient;
788     dev->addfont = render_addfont;
789     dev->drawchar = render_drawchar;
790     dev->drawlink = render_drawlink;
791     dev->endpage = render_endpage;
792     dev->finish = render_finish;
793 }
794