X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fdevices%2Frender.c;h=2449a2c11f12c8dba2dbccfe8abc0cab248012c3;hb=5ac1e934f50f8c32e8355aba5f3b243406f3520c;hp=7e6d2ad70c8e2aac60d9c4ee02c939a8b52a64c7;hpb=a2388a02b2fb072a77d313f83e0f032c6bb031d8;p=swftools.git diff --git a/lib/devices/render.c b/lib/devices/render.c index 7e6d2ad..2449a2c 100644 --- a/lib/devices/render.c +++ b/lib/devices/render.c @@ -24,11 +24,10 @@ #include #include "../gfxdevice.h" #include "../gfxtools.h" -#include "../png.h" #include "../mem.h" - -typedef unsigned int U32; -typedef unsigned char U8; +#define PNG_INLINE_EXPORTS +#include "../types.h" +#include "../png.c" typedef gfxcolor_t RGBA; @@ -64,6 +63,7 @@ typedef struct _internal { int antialize; int zoom; int ymin, ymax; + int fillwhite; RGBA* img; @@ -445,13 +445,18 @@ void fill_solid(gfxdevice_t*dev, gfxcolor_t* color) int render_setparameter(struct _gfxdevice*dev, const char*key, const char*value) { internal_t*i = (internal_t*)dev->internal; - if(!strcmp(key, "antialize")) { + if(!strcmp(key, "antialize") || !strcmp(key, "antialise")) { i->antialize = atoi(value); i->zoom = i->antialize * i->multiply; + return 1; } else if(!strcmp(key, "multiply")) { i->multiply = atoi(value); i->zoom = i->antialize * i->multiply; fprintf(stderr, "Warning: multiply not implemented yet\n"); + return 1; + } else if(!strcmp(key, "fillwhite")) { + i->fillwhite = atoi(value); + return 1; } return 0; } @@ -491,9 +496,9 @@ void render_stroke(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t width, gfxc internal_t*i = (internal_t*)dev->internal; double x,y; - if(cap_style != gfx_capRound || joint_style != gfx_joinRound) { + /*if(cap_style != gfx_capRound || joint_style != gfx_joinRound) { fprintf(stderr, "Warning: cap/joint style != round not yet supported\n"); - } + }*/ while(line) { int x1,y1,x2,y2,x3,y3; @@ -644,6 +649,10 @@ void render_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolo { internal_t*i = (internal_t*)dev->internal; + /* align characters to whole pixels */ + matrix->tx = (int)(matrix->tx * i->antialize) / i->antialize; + matrix->ty = (int)(matrix->ty * i->antialize) / i->antialize; + gfxglyph_t*glyph = &font->glyphs[glyphnr]; gfxline_t*line2 = gfxline_clone(glyph->line); gfxline_transform(line2, matrix); @@ -660,25 +669,72 @@ void render_result_write(gfxresult_t*r, int filedesc) } int render_result_save(gfxresult_t*r, char*filename) { - /*internal_result_t*i= (internal_result_t*)r->internal; + internal_result_t*i= (internal_result_t*)r->internal; + if(!i) { + return 0; // no pages drawn + } if(i->next) { int nr=0; + char filenamebuf[256]; + char*origname = strdup(filename); + int l = strlen(origname); + if(l>3 && strchr("gG",origname[l-1]) && strchr("nN",filename[l-2]) && + strchr("pP",origname[l-3]) && filename[l-4]=='.') { + origname[l-4] = 0; + } while(i->next) { + sprintf(filenamebuf, "%s.%d.png", origname, nr); writePNG(filename, (unsigned char*)i->img.data, i->img.width, i->img.height); nr++; } + free(origname); } else { writePNG(filename, (unsigned char*)i->img.data, i->img.width, i->img.height); - }*/ + } return 1; } +char*gfximage_asXPM(gfximage_t*img, int depth) +{ + int d= 256/depth; + char*str = (char*)malloc(img->width*img->height*4 + 500 + 16*depth*depth*depth); + char*p = str; + p+= sprintf(p, "static char *noname[] = {\n\"%d %d 262144 3\",\n"); + int r,g,b; + for(r=0;rheight;y++) { + p+=sprintf(p, "\""); + gfxcolor_t*col = &img->data[y*img->height]; + int x; + for(x=0;xwidth;x++) { + p+=sprintf(p, "%c%c%c", 32+(col->r/d), 32+(col->g/d), 32+(col->b/d)); + } + p+=sprintf(p, "\",\n"); + } + *p = 0; + return p; +} void*render_result_get(gfxresult_t*r, char*name) { internal_result_t*i= (internal_result_t*)r->internal; - if(!strncmp(name,"page",4)) { + if(!strncmp(name,"xpm",3)) { + int pagenr = atoi(&name[3]); + if(pagenr<0) + pagenr=0; + while(pagenr>0) { + i = i->next; + if(!i) + return 0; + } + return gfximage_asXPM(&i->img, 64); + } else if(!strncmp(name,"page",4)) { int pagenr = atoi(&name[4]); if(pagenr<0) - return 0; + pagenr=0; while(pagenr>0) { i = i->next; if(!i) @@ -741,6 +797,10 @@ void render_startpage(struct _gfxdevice*dev, int width, int height) i->lines[y].num = 0; } i->img = (RGBA*)rfx_calloc(sizeof(RGBA)*i->width2*i->height2); + if(i->fillwhite) { + memset(i->img, 0xff, sizeof(RGBA)*i->width2*i->height2); + } + i->ymin = 0x7fffffff; i->ymax = -0x80000000;