Ejemplo n.º 1
0
SplineSet *SpiroCP2SplineSet(spiro_cp *spiros) {
    int n;
    int any = 0;
    spiro_cp *nspiros;
    SplineSet *ss;
    int lastty = 0;

    if ( spiros==NULL )
return( NULL );
    for ( n=0; spiros[n].ty!=SPIRO_END; ++n )
	if ( SPIRO_SELECTED(&spiros[n]) )
	    ++any;
    if ( n==0 )
return( NULL );
    if ( n==1 ) {
	ss = chunkalloc(sizeof(SplineSet));
	ss->first = ss->last = SplinePointCreate(spiros[0].x,spiros[0].y);
    } else {
	bezctx *bc = new_bezctx_ff();
	if ( (spiros[0].ty&0x7f)=='{' ) {
	    lastty = spiros[n-1].ty;
	    spiros[n-1].ty = '}';
	}

	if ( !any ) {
#if _LIBSPIRO_FUN
	    if ( TaggedSpiroCPsToBezier0(spiros,bc)==0 ) {
		return( NULL );
	    }
#else
	    TaggedSpiroCPsToBezier(spiros,bc);
#endif
	} else {
	    nspiros = galloc((n+1)*sizeof(spiro_cp));
	    memcpy(nspiros,spiros,(n+1)*sizeof(spiro_cp));
	    for ( n=0; nspiros[n].ty!=SPIRO_END; ++n )
		nspiros[n].ty &= ~0x80;
#if _LIBSPIRO_FUN
	    if ( TaggedSpiroCPsToBezier0(nspiros,bc)==0 ) {
		free(nspiros);
		return( NULL );
	    }
#else
	    TaggedSpiroCPsToBezier(nspiros,bc);
#endif
	    free(nspiros);
	}
	ss = bezctx_ff_close(bc);

	if ( (spiros[0].ty&0x7f)=='{' )
	    spiros[n-1].ty = lastty;
    }
    ss->spiros = spiros;
    ss->spiro_cnt = ss->spiro_max = n+1;
    SPLCatagorizePoints(ss);
return( ss );
}
Ejemplo n.º 2
0
SplineSet *SpiroCP2SplineSet(spiro_cp *spiros) {
/* Create a SplineSet from the given spiros_code_points.*/
    int n;
    int any = 0;
    SplineSet *ss;
    int lastty = 0;

    if ( spiros==NULL )
	return( NULL );
    for ( n=0; spiros[n].ty!=SPIRO_END; ++n )
	if ( SPIRO_SELECTED(&spiros[n]) )
	    ++any;
    if ( n==0 )
	return( NULL );
    if ( n==1 ) {
	/* Spiro only haS 1 code point sofar (no conversion needed yet) */
	if ( (ss=chunkalloc(sizeof(SplineSet)))==NULL || \
	     (ss->first=ss->last=SplinePointCreate(spiros[0].x,spiros[0].y))==NULL ) {
	    chunkfree(ss,sizeof(SplineSet));
	    return( NULL );
	}
    } else {
	/* Spiro needs to be converted to bezier curves using libspiro. */
	bezctx *bc;
	if ( (bc=new_bezctx_ff())==NULL )
	    return( NULL );
	if ( (spiros[0].ty&0x7f)=='{' ) {
	    lastty = spiros[n-1].ty;
	    spiros[n-1].ty = '}';
	}

	if ( !any ) {
#if _LIBSPIRO_FUN
	    if ( TaggedSpiroCPsToBezier0(spiros,bc)==0 ) {
		if ( lastty ) spiros[n-1].ty = lastty;
		free(bc);
		return( NULL );
	    }
#else
	    TaggedSpiroCPsToBezier(spiros,bc);
#endif
	} else {
	    int i;
	    spiro_cp *nspiros;
	    if ( (nspiros=malloc((n+1)*sizeof(spiro_cp)))==NULL ) {
		if ( lastty ) spiros[n-1].ty = lastty;
		free(bc);
		return( NULL );
	    }
	    memcpy(nspiros,spiros,(n+1)*sizeof(spiro_cp));
	    for ( i=0; nspiros[i].ty!=SPIRO_END; ++i )
		nspiros[i].ty &= ~0x80;
#if _LIBSPIRO_FUN
	    if ( TaggedSpiroCPsToBezier0(nspiros,bc)==0 ) {
		if ( lastty ) spiros[n-1].ty = lastty;
		free(nspiros);
		free(bc);
		return( NULL );
	    }
#else
	    TaggedSpiroCPsToBezier(nspiros,bc);
#endif
	    free(nspiros);
	}
	if ( lastty ) spiros[n-1].ty = lastty;

	if ( (ss=bezctx_ff_close(bc))==NULL ) return( NULL );
    }
    ss->spiros = spiros;
    ss->spiro_cnt = ss->spiro_max = n+1;
    SPLCatagorizePoints(ss);
    return( ss );
}