--- swfmill-0.2.12/src/swft/swft_import_ttf.cpp 2007-01-10 00:09:10.000000000 +0900 +++ swfmill-0.2.12-hack/src/swft/swft_import_ttf.cpp 2007-02-08 15:03:17.742187500 +0900 @@ -54,6 +54,49 @@ return( _a - _b ); } + +//******************************************************************************************** +// unique +// +// make the given array unique, +// returns the number of unique elements contained in the array. +// requires a compartor function comp(void *p, void *q) which should return +// ret < 0 when p < q +// ret == 0 retn p = q +// ret > 0 when p > q +// +// example: [aabccdeee] -> [abcde], returns 5 +//******************************************************************************************** +size_t unique( void *array, size_t num, size_t size, int (*comp)(const void *, const void *) ) +{ + // scan over all elements of the array + char *start = (char *)array; + char *stop = (char *)array + (size*(num-1)); // the last element + char *dst = start; + char *p = start; + while( p <= stop ) + { + // q points the tail of unique elements found + char *q = p; + while( (q < stop) && (0!=comp(q,q+size)) ) + q = q + size; + + // copy elements p..q at the position dst points + size_t elements = ((q - p)/size) + 1; + memmove( dst, p, size * elements ); + dst = dst + size * elements; // adjust the disposition + + // skip duplicating elements + p = q + size; + while( (p <= stop) && (0==comp(q,p)) ) + p = p + size; + } + return (dst-start) / size; // return the number of unique elements +}//unique + + + + void importDefineFont2( DefineFont2 *tag, const char *filename, const char *fontname, const xmlChar *glyphs_xml, Context *ctx, swft_ctx *swftctx, int offset ) { FT_Library swfft_library; FT_Face face; @@ -132,7 +175,8 @@ // sort the list of glyphs qsort( glyphs, nGlyphs_, sizeof(int), compareGlyphs ); - nGlyphs = nGlyphs_; + // make the list of glyphs unique + nGlyphs = (int)unique( glyphs, (size_t)nGlyphs_, sizeof(int), compareGlyphs ); } glyphList->allocate( nGlyphs ); @@ -381,3 +425,5 @@ fprintf( stderr, "WARNING: could not import %s\n", filename ); return; } + +