コード例 #1
0
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]);
    }
#ifdef STATS
    state->size_lines = old_size_lines;
    state->size_fonts += w->pos - oldpos;
#endif
}
コード例 #2
0
static void dumpImage(writer_t*w, state_t*state, gfximage_t*img)
{
    int oldpos = w->pos;
    writer_writeU16(w, img->width);
    writer_writeU16(w, img->height);
#ifdef COMPRESS_IMAGES
    //35.3% images (2027305 bytes) (with filter, Z_BEST_COMPRESSION)
    //39.9% images (2458904 bytes) (with filter, Z_BEST_SPEED)
    //45.2% images (3055340 bytes) (without filter)
    //45.9% images (3149247 bytes) (without filter, 5)
    //48.0% images (3480495 bytes) (with filter, fastlz)
    //48.0% images (3488650 bytes) (without filter, Z_BEST_SPEED)
    //55.3% images (4665889 bytes) (without filter, fastlz level 2)
    //55.6% images (4726334 bytes) (without filter, fastlz level 1)
    //83.0% images (18091804 bytes) (no compression)

    gfxcolor_t*image;
#ifdef FILTER_IMAGES
    unsigned char*filter = malloc(img->height);
    int y;
    image = malloc(img->width*img->height*sizeof(gfxcolor_t));
    for(y=0;y<img->height;y++) {
	filter[y] = png_apply_filter_32(
		(void*)&image[y*img->width], 
		(void*)&img->data[y*img->width], img->width, y);
    }
#else
    image = img->data;
#endif
    int size = img->width*img->height;
    uLongf compressdata_size = compressBound(size*sizeof(gfxcolor_t));
    void*compressdata = malloc(compressdata_size);

#ifdef HAVE_FASTLZ
    compressdata_size = fastlz_compress_level(2, (void*)image, size*sizeof(gfxcolor_t), compressdata);
#else
    compress2(compressdata, &compressdata_size, (void*)image, sizeof(gfxcolor_t)*size, Z_BEST_SPEED);
#endif

    writer_writeU32(w, compressdata_size);
#ifdef FILTER_IMAGES
    w->write(w, filter, img->height);
    free(filter);
    free(image);
#endif
    w->write(w, compressdata, compressdata_size);
    free(compressdata);
#else
    w->write(w, img->data, img->width*img->height*sizeof(gfxcolor_t));
#endif
#ifdef STATS
    state->size_images += w->pos - oldpos;
#endif
}
コード例 #3
0
ファイル: record.c プロジェクト: MaChao5/pdfviewer-win32
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);
    }
}