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("<trace> record: %08x FILLBITMAP\n", dev); writer_writeU8(&i->w, OP_FILLBITMAP); dumpImage(&i->w, &i->state, img); dumpMatrix(&i->w, &i->state, matrix); dumpLine(&i->w, &i->state, line); dumpCXForm(&i->w, &i->state, cxform); }
static void record_endclip(struct _gfxdevice*dev) { internal_t*i = (internal_t*)dev->internal; msg("<trace> record: %08x ENDCLIP\n", dev); writer_writeU8(&i->w, OP_ENDCLIP); i->cliplevel--; if(i->cliplevel<0) { msg("<error> record: endclip() without startclip()"); } }
static gfxresult_t* record_finish(struct _gfxdevice*dev) { internal_t*i = (internal_t*)dev->internal; msg("<trace> record: %08x END", dev); if(i->cliplevel) { msg("<error> Warning: unclosed cliplevels"); } state_clear(&i->state); #ifdef STATS int total = i->w.pos; if(total && i->use_tempfile) { state_t*s = &i->state; msg("<notice> record device finished. stats:"); msg("<notice> %4.1f%% matrices (%d bytes)", s->size_matrices*100.0/total, s->size_matrices); msg("<notice> %4.1f%% positions (%d bytes)", s->size_positions*100.0/total, s->size_positions); msg("<notice> %4.1f%% colors (%d bytes)", s->size_colors*100.0/total, s->size_colors); msg("<notice> %4.1f%% lines (%d bytes)", s->size_lines*100.0/total, s->size_lines); msg("<notice> %4.1f%% fonts (%d bytes)", s->size_fonts*100.0/total, s->size_fonts); msg("<notice> %4.1f%% images (%d bytes)", s->size_images*100.0/total, s->size_images); msg("<notice> %4.1f%% characters (%d bytes)", s->size_chars*100.0/total, s->size_chars); msg("<notice> total: %d bytes", total); } #endif writer_writeU8(&i->w, OP_END); gfxfontlist_free(i->fontlist, 0); internal_result_t*ir = (internal_result_t*)rfx_calloc(sizeof(gfxresult_t)); ir->use_tempfile = i->use_tempfile; if(i->use_tempfile) { ir->filename = i->filename; } else { ir->data = writer_growmemwrite_getmem(&i->w); ir->length = i->w.pos; } i->w.finish(&i->w); gfxresult_t*result= (gfxresult_t*)rfx_calloc(sizeof(gfxresult_t)); result->save = record_result_save; result->get = record_result_get; result->destroy = record_result_destroy; result->internal = ir; free(dev->internal);memset(dev, 0, sizeof(gfxdevice_t)); return result; }
char*reader_readString(reader_t*r) { writer_t g; writer_init_growingmemwriter(&g, 16); while(1) { U8 b = reader_readU8(r); writer_writeU8(&g, b); if(!b) break; } char*string = (char*)writer_growmemwrite_getmem(&g); g.finish(&g); return string; }
static void record_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix) { internal_t*i = (internal_t*)dev->internal; if(font && !gfxfontlist_hasfont(i->fontlist, font)) { record_addfont(dev, font); } msg("<trace> record: %08x DRAWCHAR %d\n", glyphnr, dev); const char*font_id = (font&&font->id)?font->id:"*NULL*"; gfxmatrix_t*l = &i->state.last_matrix[OP_DRAWCHAR]; U8 flags = 0; if(!font) flags |= FLAG_ZERO_FONT; char same_font = i->state.last_string[OP_DRAWCHAR] && !strcmp(i->state.last_string[OP_DRAWCHAR], font_id); char same_matrix = (l->m00 == matrix->m00) && (l->m01 == matrix->m01) && (l->m10 == matrix->m10) && (l->m11 == matrix->m11); char same_color = !memcmp(color, &i->state.last_color[OP_DRAWCHAR], sizeof(gfxcolor_t)); /* FIXME if(same_font && same_matrix && same_color) flags |= FLAG_SAME_AS_LAST; */ writer_writeU8(&i->w, OP_DRAWCHAR|flags); writer_writeU32(&i->w, glyphnr); #ifdef STATS i->state.size_chars += 5; #endif if(!(flags&FLAG_SAME_AS_LAST)) { if(!(flags&FLAG_ZERO_FONT)) writer_writeString(&i->w, font_id); dumpColor(&i->w, &i->state, color); dumpMatrix(&i->w, &i->state, matrix); if(i->state.last_string[OP_DRAWCHAR]) free(i->state.last_string[OP_DRAWCHAR]); i->state.last_string[OP_DRAWCHAR] = strdup(font_id); i->state.last_color[OP_DRAWCHAR] = *color; i->state.last_matrix[OP_DRAWCHAR] = *matrix; } else { dumpXY(&i->w, &i->state, matrix); } }
static void dumpFont(writer_t*w, state_t*state, gfxfont_t*font) { int oldpos = w->pos; #ifdef STATS int old_size_lines = state->size_lines; #endif writer_writeString(w, font->id); writer_writeU32(w, font->num_glyphs); writer_writeU32(w, font->max_unicode); writer_writeDouble(w, font->ascent); writer_writeDouble(w, font->descent); int t; for(t=0;t<font->num_glyphs;t++) { dumpLine(w, state, font->glyphs[t].line); writer_writeDouble(w, font->glyphs[t].advance); writer_writeU32(w, font->glyphs[t].unicode); if(font->glyphs[t].name) { writer_writeString(w,font->glyphs[t].name); } else { writer_writeU8(w,0); } } for(t=0;t<font->max_unicode;t++) { writer_writeU32(w, font->unicode2glyph[t]); } writer_writeU32(w, font->kerning_size); for(t=0;t<font->kerning_size;t++) { writer_writeU32(w, font->kerning[t].c1); writer_writeU32(w, font->kerning[t].c2); writer_writeU32(w, font->kerning[t].advance); } #ifdef STATS state->size_lines = old_size_lines; state->size_fonts += w->pos - oldpos; #endif }
static void record_endpage(struct _gfxdevice*dev) { internal_t*i = (internal_t*)dev->internal; msg("<trace> record: %08x ENDPAGE\n", dev); writer_writeU8(&i->w, OP_ENDPAGE); }