X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fdevices%2Frecord.c;h=f0b70f6e6271c8439b7323aa2d9969d4e7637b93;hb=018b4ff4529ff084c6c551fa40ff1c2a8be32741;hp=964792316519a41c00a4b0bb67bacd269fbd0c45;hpb=b7685336c293cd0489a5891c598e1ec21ef11f25;p=swftools.git diff --git a/lib/devices/record.c b/lib/devices/record.c index 9647923..f0b70f6 100644 --- a/lib/devices/record.c +++ b/lib/devices/record.c @@ -40,6 +40,7 @@ typedef struct _internal { gfxfontlist_t* fontlist; writer_t w; + int cliplevel; } internal_t; typedef struct _internal_result { @@ -69,7 +70,7 @@ typedef struct _internal_result { static int record_setparameter(struct _gfxdevice*dev, const char*key, const char*value) { internal_t*i = (internal_t*)dev->internal; - msg(" record: SETPARAM %s %s\n", key, value); + msg(" record: %08x SETPARAM %s %s\n", dev, key, value); writer_writeU8(&i->w, OP_SETPARAM); writer_writeString(&i->w, key); writer_writeString(&i->w, value); @@ -283,7 +284,7 @@ static gfxfont_t*readFont(reader_t*r) static void record_stroke(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit) { internal_t*i = (internal_t*)dev->internal; - msg(" record: STROKE\n"); + msg(" record: %08x STROKE\n", dev); writer_writeU8(&i->w, OP_STROKE); writer_writeDouble(&i->w, width); writer_writeDouble(&i->w, miterLimit); @@ -296,22 +297,27 @@ static void record_stroke(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t widt static void record_startclip(struct _gfxdevice*dev, gfxline_t*line) { internal_t*i = (internal_t*)dev->internal; - msg(" record: STARTCLIP\n"); + msg(" record: %08x STARTCLIP\n", dev); writer_writeU8(&i->w, OP_STARTCLIP); dumpLine(&i->w, line); + i->cliplevel++; } static void record_endclip(struct _gfxdevice*dev) { internal_t*i = (internal_t*)dev->internal; - msg(" record: ENDCLIP\n"); + msg(" record: %08x ENDCLIP\n", dev); writer_writeU8(&i->w, OP_ENDCLIP); + i->cliplevel--; + if(i->cliplevel<0) { + msg(" record: endclip() without startclip()"); + } } static void record_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color) { internal_t*i = (internal_t*)dev->internal; - msg(" record: FILL\n"); + msg(" record: %08x FILL\n", dev); writer_writeU8(&i->w, OP_FILL); dumpColor(&i->w, color); dumpLine(&i->w, line); @@ -320,7 +326,7 @@ static void record_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color) static void record_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform) { internal_t*i = (internal_t*)dev->internal; - msg(" record: FILLBITMAP\n"); + msg(" record: %08x FILLBITMAP\n", dev); writer_writeU8(&i->w, OP_FILLBITMAP); dumpImage(&i->w, img); dumpMatrix(&i->w, matrix); @@ -331,7 +337,7 @@ static void record_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t* static void record_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix) { internal_t*i = (internal_t*)dev->internal; - msg(" record: FILLGRADIENT\n"); + msg(" record: %08x FILLGRADIENT %08x\n", dev, gradient); writer_writeU8(&i->w, OP_FILLGRADIENT); writer_writeU8(&i->w, type); dumpGradient(&i->w, gradient); @@ -342,10 +348,12 @@ static void record_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradie static void record_addfont(struct _gfxdevice*dev, gfxfont_t*font) { internal_t*i = (internal_t*)dev->internal; - msg(" record: ADDFONT\n"); - writer_writeU8(&i->w, OP_ADDFONT); - dumpFont(&i->w, font); - i->fontlist = gfxfontlist_addfont(i->fontlist, font); + msg(" record: %08x ADDFONT %s\n", dev, font->id); + if(font && !gfxfontlist_hasfont(i->fontlist, font)) { + writer_writeU8(&i->w, OP_ADDFONT); + dumpFont(&i->w, font); + i->fontlist = gfxfontlist_addfont(i->fontlist, font); + } } static void record_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix) @@ -353,10 +361,9 @@ static void record_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, internal_t*i = (internal_t*)dev->internal; if(font && !gfxfontlist_hasfont(i->fontlist, font)) { record_addfont(dev, font); - i->fontlist = gfxfontlist_addfont(i->fontlist, font); } - msg(" record: DRAWCHAR %d\n", glyphnr); + msg(" record: %08x DRAWCHAR %d\n", glyphnr, dev); writer_writeU8(&i->w, OP_DRAWCHAR); if(font) writer_writeString(&i->w, font->id); @@ -370,7 +377,7 @@ static void record_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, static void record_startpage(struct _gfxdevice*dev, int width, int height) { internal_t*i = (internal_t*)dev->internal; - msg(" record: STARTPAGE\n"); + msg(" record: %08x STARTPAGE\n", dev); writer_writeU8(&i->w, OP_STARTPAGE); writer_writeU16(&i->w, width); writer_writeU16(&i->w, height); @@ -379,24 +386,24 @@ static void record_startpage(struct _gfxdevice*dev, int width, int height) static void record_endpage(struct _gfxdevice*dev) { internal_t*i = (internal_t*)dev->internal; - msg(" record: ENDPAGE\n"); + msg(" record: %08x ENDPAGE\n", dev); writer_writeU8(&i->w, OP_ENDPAGE); } static void record_drawlink(struct _gfxdevice*dev, gfxline_t*line, const char*action) { internal_t*i = (internal_t*)dev->internal; - msg(" record: DRAWLINK\n"); + msg(" record: %08x DRAWLINK\n", dev); writer_writeU8(&i->w, OP_DRAWLINK); dumpLine(&i->w, line); writer_writeString(&i->w, action); } -static void replay(struct _gfxdevice*recorddev, gfxdevice_t*device, void*data, int length) +static void replay(struct _gfxdevice*dev, gfxdevice_t*out, void*data, int length) { internal_t*i = 0; - if(recorddev) { - i = (internal_t*)recorddev->internal; + if(dev) { + i = (internal_t*)dev->internal; } reader_t r2; @@ -408,15 +415,14 @@ static void replay(struct _gfxdevice*recorddev, gfxdevice_t*device, void*data, i unsigned char op = reader_readU8(r); switch(op) { case OP_END: - msg(" replay: END"); - return; + goto finish; case OP_SETPARAM: { msg(" replay: SETPARAM"); char*key; char*value; key = reader_readString(r); value = reader_readString(r); - device->setparameter(device, key, value); + out->setparameter(out, key, value); free(key); free(value); break; @@ -425,7 +431,7 @@ static void replay(struct _gfxdevice*recorddev, gfxdevice_t*device, void*data, i msg(" replay: STARTPAGE"); U16 width = reader_readU16(r); U16 height = reader_readU16(r); - device->startpage(device, width, height); + out->startpage(out, width, height); break; } case OP_ENDPAGE: { @@ -456,27 +462,27 @@ static void replay(struct _gfxdevice*recorddev, gfxdevice_t*device, void*data, i case 2: jointtype = gfx_joinBevel; break; } gfxline_t* line = readLine(r); - device->stroke(device, line, width, &color, captype, jointtype,miterlimit); + out->stroke(out, line, width, &color, captype, jointtype,miterlimit); gfxline_free(line); break; } case OP_STARTCLIP: { msg(" replay: STARTCLIP"); gfxline_t* line = readLine(r); - device->startclip(device, line); + out->startclip(out, line); gfxline_free(line); break; } case OP_ENDCLIP: { msg(" replay: ENDCLIP"); - device->endclip(device); + out->endclip(out); break; } case OP_FILL: { msg(" replay: FILL"); gfxcolor_t color = readColor(r); gfxline_t* line = readLine(r); - device->fill(device, line, &color); + out->fill(out, line, &color); gfxline_free(line); break; } @@ -486,9 +492,11 @@ static void replay(struct _gfxdevice*recorddev, gfxdevice_t*device, void*data, i gfxmatrix_t matrix = readMatrix(r); gfxline_t* line = readLine(r); gfxcxform_t* cxform = readCXForm(r); - device->fillbitmap(device, line, &img, &matrix, cxform); + out->fillbitmap(out, line, &img, &matrix, cxform); + gfxline_free(line); if(cxform) free(cxform); + free(img.data);img.data=0; break; } case OP_FILLGRADIENT: { @@ -504,23 +512,23 @@ static void replay(struct _gfxdevice*recorddev, gfxdevice_t*device, void*data, i gfxgradient_t*gradient = readGradient(r); gfxmatrix_t matrix = readMatrix(r); gfxline_t* line = readLine(r); - device->fillgradient(device, line, gradient, type, &matrix); + out->fillgradient(out, line, gradient, type, &matrix); break; } case OP_DRAWLINK: { msg(" replay: DRAWLINK"); gfxline_t* line = readLine(r); char* s = reader_readString(r); - device->drawlink(device,line,s); + out->drawlink(out,line,s); gfxline_free(line); free(s); break; } case OP_ADDFONT: { - msg(" replay: ADDFONT"); + msg(" replay: ADDFONT out=%08x(%s)", out, out->name); gfxfont_t*font = readFont(r); fontlist = gfxfontlist_addfont(fontlist, font); - device->addfont(device, font); + out->addfont(out, font); break; } case OP_DRAWCHAR: { @@ -533,12 +541,14 @@ static void replay(struct _gfxdevice*recorddev, gfxdevice_t*device, void*data, i msg(" replay: DRAWCHAR font=%s glyph=%d", id, glyph); gfxcolor_t color = readColor(r); gfxmatrix_t matrix = readMatrix(r); - device->drawchar(device, font, glyph, &color, &matrix); + out->drawchar(out, font, glyph, &color, &matrix); free(id); break; } } } +finish: + r->dealloc(r); gfxfontlist_free(fontlist, 1); } void gfxresult_record_replay(gfxresult_t*result, gfxdevice_t*device) @@ -584,6 +594,31 @@ static void record_result_destroy(gfxresult_t*r) free(r); } +static unsigned char printable(unsigned char a) +{ + if(a<32 || a==127) return '.'; + else return a; +} + +static void hexdumpMem(unsigned char*data, int len) +{ + int t; + char ascii[32]; + for(t=0;tinternal; @@ -598,9 +633,15 @@ void gfxdevice_record_flush(gfxdevice_t*dev, gfxdevice_t*out) static gfxresult_t* record_finish(struct _gfxdevice*dev) { internal_t*i = (internal_t*)dev->internal; - msg(" record: END\n"); + msg(" record: %08x END", dev); + + if(i->cliplevel) { + msg(" Warning: unclosed cliplevels"); + } writer_writeU8(&i->w, OP_END); + + gfxfontlist_free(i->fontlist, 0); internal_result_t*ir = (internal_result_t*)rfx_calloc(sizeof(gfxresult_t)); ir->data = writer_growmemwrite_getmem(&i->w); @@ -628,6 +669,7 @@ void gfxdevice_record_init(gfxdevice_t*dev) writer_init_growingmemwriter(&i->w, 1048576); i->fontlist = gfxfontlist_create(); + i->cliplevel = 0; dev->setparameter = record_setparameter; dev->startpage = record_startpage;