Example #1
0
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;
}