示例#1
0
static void EpsGeneratePreview(FILE *eps,SplineChar *sc,int layer,DBounds *b) {
    double scale, temp;
    int pixelsize, depth;
    BDFChar *bdfc;
    int i,j;

    /* Try for a preview that fits within a 72x72 box */
    if ( b->maxx==b->minx || b->maxy==b->miny )
return;
    scale = 72.0/(b->maxx-b->minx);
    temp = 72.0/(b->maxy-b->miny);
    if ( temp<scale ) scale = temp;
    pixelsize = rint((sc->parent->ascent+sc->parent->descent)*scale);
    scale = pixelsize/(double) (sc->parent->ascent+sc->parent->descent);

    depth = 4;
    bdfc = SplineCharFreeTypeRasterizeNoHints(sc,layer,pixelsize,72,4);
    if ( bdfc==NULL )
	bdfc = SplineCharAntiAlias(sc,layer,pixelsize,4);
    if ( bdfc==NULL )
return;

    fprintf(eps,"%%%%BeginPreview: %d %d %d %d\n",
	    bdfc->xmax-bdfc->xmin+1, bdfc->ymax-bdfc->ymin+1, depth, bdfc->ymax-bdfc->ymin+1 );
    for ( i=0; i<=bdfc->ymax-bdfc->ymin; ++i ) {
	putc('%',eps);
	for ( j=0; j<=bdfc->xmax-bdfc->xmin; ++j )
	    fprintf(eps,"%X",bdfc->bitmap[i*bdfc->bytes_per_line+j]);
	if ( !((bdfc->xmax-bdfc->xmin)&1) )
	    putc('0',eps);
	putc('\n',eps);
    }
    BDFCharFree(bdfc);
    fprintf(eps,"%%%%EndPreview\n" );
}
示例#2
0
static BDFChar *APRasterize(void *freetypecontext, SplineChar *sc,int layer, int *off,int *size,int pixelsize) {
    BDFChar *bdfc;

    if ( freetypecontext ) {
	bdfc = SplineCharFreeTypeRasterize(freetypecontext,sc->orig_pos,pixelsize,72,8);
    } else
	bdfc = SplineCharAntiAlias(sc,layer,pixelsize,4);

    if ( bdfc->xmin<=0 ) {
	*off = 1-bdfc->xmin;
	if ( bdfc->width>bdfc->xmax-bdfc->xmin )
	    *size = bdfc->width;
	else
	    *size = bdfc->xmax + *off;
    } else {
	*off = 0;
	if ( bdfc->width>bdfc->xmax )
	    *size = bdfc->width;
	else
	    *size = bdfc->xmax + 1;
    }
    ++*size;
return( bdfc );
}
示例#3
0
int ExportImage(char *filename,SplineChar *sc, int layer, int format, int pixelsize, int bitsperpixel) {
/* 0=*.xbm, 1=*.bmp, 2=*.png, 3=*.xpm, 4=*.c(fontforge-internal) */
    struct _GImage base;
    GImage gi;
    GClut clut;
    BDFChar *bdfc;
    int ret;
    int tot, i;
    uint8 *pt, *end;
    int scale;
    void *freetypecontext;
    double emsize = sc->parent->ascent+sc->parent->descent;

    if ( autohint_before_generate && sc->changedsincelasthinted && !sc->manualhints )
	SplineCharAutoHint(sc,layer,NULL);

    memset(&gi,'\0', sizeof(gi));
    memset(&base,'\0', sizeof(base));
    memset(&clut,'\0', sizeof(clut));
    gi.u.image = &base;

    if ( bitsperpixel==1 ) {
	if ( (freetypecontext = FreeTypeFontContext(sc->parent,sc,NULL,layer))==NULL )
	    bdfc = SplineCharRasterize(sc,layer,pixelsize);
	else {
	    bdfc = SplineCharFreeTypeRasterize(freetypecontext,sc->orig_pos,pixelsize,72,1);
	    FreeTypeFreeContext(freetypecontext);
	}
	BCRegularizeBitmap(bdfc);
	/* People don't seem to like having a minimal bounding box for their */
	/*  images. */
	BCExpandBitmapToEmBox(bdfc,
		0,
		(int) rint(sc->parent->ascent*pixelsize/emsize)-pixelsize,
		(int) rint(sc->width*pixelsize/emsize),
		(int) rint(sc->parent->ascent*pixelsize/emsize));

	/* Sigh. Bitmaps use a different defn of set than images do. make it consistant */
	tot = bdfc->bytes_per_line*(bdfc->ymax-bdfc->ymin+1);
	for ( pt = bdfc->bitmap, end = pt+tot; pt<end; *pt++ ^= 0xff );

	base.image_type = it_mono;
	base.data = bdfc->bitmap;
	base.bytes_per_line = bdfc->bytes_per_line;
	base.width = bdfc->xmax-bdfc->xmin+1;
	base.height = bdfc->ymax-bdfc->ymin+1;
	base.trans = -1;
	if ( format==0 )
	    ret = !GImageWriteXbm(&gi,filename);
#ifndef _NO_LIBPNG
	else if ( format==2 )
	    ret = GImageWritePng(&gi,filename,false);
#endif
	else if ( format==3 )
	    ret = !GImageWriteXpm(&gi,filename);
	else if ( format==4 )
	    ret = !GImageWriteGImage(&gi,filename);
	else
	    ret = GImageWriteBmp(&gi,filename);
	BDFCharFree(bdfc);
    } else {
	if ( (freetypecontext = FreeTypeFontContext(sc->parent,sc,NULL,layer))==NULL )
	    bdfc = SplineCharAntiAlias(sc,pixelsize,layer,(1<<(bitsperpixel/2)));
	else {
	    bdfc = SplineCharFreeTypeRasterize(freetypecontext,sc->orig_pos,pixelsize,72,bitsperpixel);
	    FreeTypeFreeContext(freetypecontext);
	}
	BCRegularizeGreymap(bdfc);
	BCExpandBitmapToEmBox(bdfc,
		0,
		(int) rint(sc->parent->ascent*pixelsize/emsize) - pixelsize,
		(int) rint(sc->width*pixelsize/emsize),
		(int) rint(sc->parent->ascent*pixelsize/emsize));
	base.image_type = it_index;
	base.data = bdfc->bitmap;
	base.bytes_per_line = bdfc->bytes_per_line;
	base.width = bdfc->xmax-bdfc->xmin+1;
	base.height = bdfc->ymax-bdfc->ymin+1;
	base.clut = &clut;
	base.trans = -1;
	clut.clut_len = 1<<bitsperpixel;
	clut.is_grey = true;
	clut.trans_index = -1;
	scale = 255/((1<<bitsperpixel)-1);
	scale = COLOR_CREATE(scale,scale,scale);
	for ( i=0; i< 1<<bitsperpixel; ++i )
	    clut.clut[(1<<bitsperpixel)-1 - i] = i*scale;
#ifndef _NO_LIBPNG
	if ( format==2 )
	    ret = GImageWritePng(&gi,filename,false);
	else
#endif
	    ret = GImageWriteBmp(&gi,filename);
	BDFCharFree(bdfc);
    }
return( ret );
}