X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fexample%2Fdumpfont.c;h=1481ed6e6c0d17c182a72463c44dff816bab9e2b;hb=b3ae7bccfb9f4ed16e26631fee072fa011f9847e;hp=01ffa9b349022e30c54db5ba5452e8700163e492;hpb=de57609a2ec9f1fbf3400d4a34eca77a9cb42a19;p=swftools.git diff --git a/lib/example/dumpfont.c b/lib/example/dumpfont.c index 01ffa9b..1481ed6 100644 --- a/lib/example/dumpfont.c +++ b/lib/example/dumpfont.c @@ -25,21 +25,21 @@ #include #include "../rfxswf.h" -#define PRINTABLE(a) ((a>='A')&&(a<='Z'))||((a>='a')&&(a<='z'))||((a>='0')&&(a<='9')) +#define PRINTABLE(a) (((a>0x20)&&(a<0xff)&&(a!='\\'))?a:0x20) SWF swf; void DumpFont(SWFFONT * f,char * name) -{ int gpos[MAX_CHAR_PER_FONT]; - int n,i; +{ int n,i; + int*gpos = malloc(sizeof(int*)*f->numchars); + memset(gpos,0,sizeof(int*)*f->numchars); // Glyph Shapes Data n = 0; printf("U8 Glyphs_%s[] = {\n\t ",name); - memset(&gpos,0x00,sizeof(gpos)); - for (i=0;inumchars;i++) if (f->glyph[i].shape) { SHAPE * s = f->glyph[i].shape; int j,l = (s->bitlen+7)/8; @@ -60,31 +60,39 @@ void DumpFont(SWFFONT * f,char * name) printf(" if (!(f=malloc(sizeof(SWFFONT)))) return NULL;\n"); printf(" memset(f,0x00,sizeof(SWFFONT));\n"); printf(" f->id = id;\n"); + printf(" f->version = %d;\n", f->version); printf(" f->name = strdup(\"%s\");\n",f->name); - printf(" f->flags = 0x%02x;\n\n",f->flags); - - for (i=0;iflags = 0x%02x;\n",f->flags); + printf(" f->numchars = %d;\n",f->numchars); + printf(" f->maxascii = %d;\n",f->maxascii); + printf(" f->glyph = (SWFGLYPH*)malloc(sizeof(SWFGLYPH)*%d);\n",f->numchars); + printf(" f->glyph2ascii = (U16*)malloc(sizeof(U16)*%d);\n",f->numchars); + printf(" f->ascii2glyph = (int*)malloc(sizeof(int)*%d);\n",f->maxascii); + printf(" memset(f->ascii2glyph, -1, sizeof(int)*%d);\n\n", f->maxascii); + + for (i=0;inumchars;i++) if (f->glyph[i].shape) - { printf(" addGlyph(f,%3i, 0x%02x,%4i,%3i, &Glyphs_%s[0x%04x],%4i); // %c\n", - i, f->codes[i], f->glyph[i].advance, f->glyph[i].gid, name, gpos[i], - f->glyph[i].shape->bitlen,(i!='\\')?i:0x20); + { printf(" addGlyph(f,%3i, 0x%02x,%4i, &Glyphs_%s[0x%04x],%4i); // %c\n", + i, f->glyph2ascii[i], f->glyph[i].advance, name, gpos[i], + f->glyph[i].shape->bitlen,PRINTABLE(f->glyph2ascii[i])); } printf(" return f;\n}\n\n"); + free(gpos); } void DumpGlobal(char * funcname) -{ printf("\nvoid %s(SWFFONT * f,int i,U16 code,U16 advance,U16 gid,U8 * data,U32 bitlen)\n",funcname); +{ printf("\nvoid %s(SWFFONT * f,int i,U16 ascii,U16 advance,U8 * data,U32 bitlen)\n",funcname); printf("{ SHAPE * s;\n U32 l = (bitlen+7)/8;\n\n"); printf(" if (FAILED(swf_ShapeNew(&s))) return;\n"); printf(" s->data = malloc(l);\n"); printf(" if (!s->data) { swf_ShapeFree(s); return; }\n\n"); - printf(" f->codes[i] = code;\n"); - printf(" f->glyph[i].advance = advance;\n"); - printf(" f->glyph[i].gid = gid;\n"); - printf(" f->glyph[i].shape = s;\n"); - printf(" s->bitlen = bitlen;\n"); - printf(" s->bits.fill = 1;\n"); + printf(" f->glyph2ascii[i] = ascii;\n"); + printf(" f->ascii2glyph[ascii] = i;\n"); + printf(" f->glyph[i].advance = advance;\n"); + printf(" f->glyph[i].shape = s;\n"); + printf(" s->bitlen = bitlen;\n"); + printf(" s->bits.fill = 1;\n"); printf(" memcpy(s->data,data,l);\n}\n\n"); } @@ -99,8 +107,13 @@ void fontcallback(U16 id,U8 * name) sprintf(s,"%s%s%s",name,swf_FontIsBold(font)?"_bold":"",swf_FontIsItalic(font)?"_italic":""); ss = s; - while(ss[0]) - { if ((*ss)==0x20) (*ss)='_'; + while(*ss) + { + if(!((*ss>='a' && *ss<='z') || + (*ss>='A' && *ss<='Z') || + (*ss>='0' && *ss<='9' && ss!=s) || + (*ss=='_'))) + *ss = '_'; ss++; }