Exemplo n.º 1
0
static void AnchorD_FreeChar(AnchorDlg *a) {
    int i;

    BDFCharFree(a->bdfc); a->bdfc = NULL;
    for ( i=0; i<a->cnt; ++i )
	BDFCharFree(a->apmatch[i].bdfc);
    free(a->apmatch); a->apmatch = NULL;
    if ( a->freetypecontext!=NULL ) {
        FreeTypeFreeContext(a->freetypecontext);
        a->freetypecontext = NULL;
    }
}
Exemplo n.º 2
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" );
}
Exemplo n.º 3
0
static void AnchorD_ChangeSize(AnchorDlg *a) {
    int i, off;

    GDrawSetCursor(a->gw,ct_watch);
    GDrawSync(NULL);
    /* GDrawProcessPendingEvents(NULL); */ /* Any expose events on the current dlg will cause a crash as there are no bdfc's now */

    a->scale = a->pixelsize / (double) (a->sc->parent->ascent + a->sc->parent->descent);

    BDFCharFree(a->bdfc);
    a->bdfc = APRasterize(a->freetypecontext,a->sc,a->layer,&a->char_off,&a->char_size,a->pixelsize);
    a->ymin = a->bdfc->ymin; a->ymax = a->bdfc->ymax;
    for ( i=0; i<a->cnt; ++i ) {
	BDFCharFree(a->apmatch[i].bdfc);
	a->apmatch[i].bdfc = APRasterize(a->freetypecontext,a->apmatch[i].sc,a->layer,&a->apmatch[i].off,&a->apmatch[i].size,a->pixelsize);
	if ( a->ap->type==at_centry || a->ap->type==at_cexit )
	    a->apmatch[i].size += a->char_size;
	else if ( a->ap->type!=at_mark )
	    a->apmatch[i].size = a->char_size;
	switch ( a->ap->type ) {
	  case at_cexit:
	  case at_basechar: case at_baselig: case at_basemark:
	    off = rint((-a->apos.y + a->apmatch[i].ap->me.y)*a->scale);
	    if ( a->apmatch[i].bdfc->ymax+off > a->ymax )
		a->ymax = a->apmatch[i].bdfc->ymax+off;
	    if ( a->apmatch[i].bdfc->ymin+off < a->ymin )
		a->ymin = a->apmatch[i].bdfc->ymin+off;
	  break;
	  case at_centry:
	  case at_mark:
	    if ( a->apmatch[i].bdfc->ymax > a->ymax )
		a->ymax = a->apmatch[i].bdfc->ymax;
	    if ( a->apmatch[i].bdfc->ymin < a->ymin )
		a->ymin = a->apmatch[i].bdfc->ymin;
	    off = rint((-a->apmatch[i].ap->me.y + a->apos.y)*a->scale);
	    if ( a->bdfc->ymax+off > a->ymax )
		a->ymax = a->bdfc->ymax+off;
	    if ( a->bdfc->ymin+off < a->ymin )
		a->ymin = a->bdfc->ymin+off;
	  break;
	}
    }
    AnchorD_ChangeMag(a);
    GDrawSetCursor(a->gw,ct_pointer);
}
Exemplo n.º 4
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 );
}