X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswftext.c;h=3d6a49be8f9da61e988e868d9ab0f8b6758c887a;hb=7155f27b636876b1b3c2c9f39c6393b9b5ce0f8d;hp=55fe65997651bd195048c8a5a561e9f9a30c96a9;hpb=ea142ad9cabaf19232f5e18753e6b994a0226b45;p=swftools.git diff --git a/lib/modules/swftext.c b/lib/modules/swftext.c index 55fe659..3d6a49b 100644 --- a/lib/modules/swftext.c +++ b/lib/modules/swftext.c @@ -57,22 +57,26 @@ int swf_FontEnumerate(SWF * swf,void (*FontCallback) (U16,U8*)) n = 0; while (t) - { if (swf_GetTagID(t)==ST_DEFINEFONTINFO || swf_GetTagID(t)==ST_DEFINEFONTINFO2 || - swf_GetTagID(t)==ST_DEFINEFONT2) + { + if (swf_GetTagID(t)==ST_DEFINEFONT2 || swf_GetTagID(t)==ST_DEFINEFONT) { n++; if (FontCallback) { U16 id; int l; U8 s[257]; + s[0] = 0; swf_SaveTagPos(t); swf_SetTagPos(t,0); id = swf_GetU16(t); - if(swf_GetTagID(t) == ST_DEFINEFONT2) + if(swf_GetTagID(t) == ST_DEFINEFONT2 || + swf_GetTagID(t) == ST_DEFINEFONTINFO || + swf_GetTagID(t) == ST_DEFINEFONTINFO2) { swf_GetU16(t); - l = swf_GetU8(t); - swf_GetBlock(t,s,l); - s[l] = 0; + l = swf_GetU8(t); + swf_GetBlock(t,s,l); + s[l] = 0; + } (FontCallback)(id,s); @@ -323,15 +327,18 @@ int swf_FontExtract_DefineFont2(int id,SWFFONT * font,TAG * tag) #define FEDTJ_MODIFY 0x02 #define FEDTJ_CALLBACK 0x04 -int swf_FontExtract_DefineTextCallback(int id,SWFFONT * f,TAG * t,int jobs, - void(*callback)(int*chars, int nr, int fontid)) +static int swf_FontExtract_DefineTextCallback(int id,SWFFONT * f,TAG * t,int jobs, + void(*callback)(void*self, int*chars, int*ypos, int nr, int fontid, int fontsize, int xstart, int ystart, RGBA* color), void*self) { U16 cid; SRECT r; MATRIX m; - U8 gbits, abits, flags; - int fid; + U8 gbits, abits; + int fid=0; + RGBA color; + int x=0,y=0; + int fontsize=0; - fid = 0; + memset(&color, 0, sizeof(color)); swf_SaveTagPos(t); swf_SetTagPos(t,0); @@ -342,57 +349,77 @@ int swf_FontExtract_DefineTextCallback(int id,SWFFONT * f,TAG * t,int jobs, gbits = swf_GetU8(t); abits = swf_GetU8(t); - flags = swf_GetU8(t); - - while(flags) + while(1) { - // FIXME: according to open-swf@macromedia.com, this is wrong. - // it should alternate textcontrol and text arrays, not - // rely on the high bit. (and length can be 0-255). + int flags,num; + flags = swf_GetU8(t); + if(!flags) + break; + if (flags&TF_TEXTCONTROL) { if (flags&TF_HASFONT) fid = swf_GetU16(t); if (flags&TF_HASCOLOR) - { swf_GetU8(t); // rgb - swf_GetU8(t); - swf_GetU8(t); - if (swf_GetTagID(t)==ST_DEFINETEXT2) swf_GetU8(t); + { color.r = swf_GetU8(t); // rgb + color.g = swf_GetU8(t); + color.b = swf_GetU8(t); + if (swf_GetTagID(t)==ST_DEFINETEXT2) color.a = swf_GetU8(t); } - if (flags&TF_HASXOFFSET) swf_GetS16(t); - if (flags&TF_HASYOFFSET) swf_GetS16(t); - if (flags&TF_HASFONT) swf_GetU16(t); + if (flags&TF_HASXOFFSET) x = swf_GetS16(t); + if (flags&TF_HASYOFFSET) y = swf_GetS16(t); + if (flags&TF_HASFONT) fontsize = swf_GetU16(t); } - else + + num = swf_GetU8(t); + if(!num) + break; + { int i; int buf[256]; - for (i=0;i + if (id==fid) { if (jobs&FEDTJ_PRINT) { - { int code = f->glyph2ascii[glyph]; + int code = f->glyph2ascii[glyph]; printf("%c",code); } if (jobs&FEDTJ_MODIFY) - /*if (!f->glyph[code].advance)*/ f->glyph[glyph].advance = adv; - } + f->glyph[glyph].advance = adv*20; //? + } else { + if (jobs&FEDTJ_PRINT) { + printf("?"); + } + } + // + buf[i] = glyph; } if ((id==fid)&&(jobs&FEDTJ_PRINT)) printf("\n"); if (jobs&FEDTJ_CALLBACK) - callback(buf, flags, fid); + callback(self, buf, advance, num, fid, fontsize, x, y, &color); + x += xpos; } - flags = swf_GetU8(t); } swf_RestoreTagPos(t); return id; } +int swf_ParseDefineText(TAG * tag, void(*callback)(void*self, int*chars, int*ypos, int nr, int fontid, int fontsize, int xstart, int ystart, RGBA* color), void*self) +{ + return swf_FontExtract_DefineTextCallback(-1, 0, tag, FEDTJ_CALLBACK, callback, self); +} int swf_FontExtract_DefineText(int id,SWFFONT * f,TAG * t,int jobs) { - return swf_FontExtract_DefineTextCallback(id,f,t,jobs,0); + return swf_FontExtract_DefineTextCallback(id,f,t,jobs,0,0); } int swf_FontExtract(SWF * swf,int id,SWFFONT * * font) @@ -451,7 +478,7 @@ int swf_FontReduce(SWFFONT * f,FONTUSAGE * use) j = 0; for (i=0;inumchars;i++) if (f->glyph[i].shape) - { if (f->glyph2ascii[i]numchars&& + { if (f->glyph2ascii[i]maxascii&& use->code[f->glyph2ascii[i]]) { f->ascii2glyph[f->glyph2ascii[i]] = j; f->glyph2ascii[j] = f->glyph2ascii[i]; @@ -474,8 +501,8 @@ int swf_FontReduce(SWFFONT * f,FONTUSAGE * use) int swf_FontInitUsage(SWFFONT* f, FONTUSAGE * use) { if (!use) return -1; - use->code = malloc(sizeof(use->code[0])*f->numchars); - memset(use->code,0,sizeof(use->code[0])*f->numchars); + use->code = malloc(sizeof(use->code[0])*f->maxascii); + memset(use->code,0,sizeof(use->code[0])*f->maxascii); return 0; } @@ -484,7 +511,7 @@ void swf_FontClearUsage(SWFFONT* f, FONTUSAGE * use) free(use->code); } -int swf_FontUse(FONTUSAGE * use,U8 * s) +int swf_FontUse(SWFFONT*f, FONTUSAGE * use,U8 * s) { if ((!use)||(!s)) return -1; while (s[0]) { use->code[s[0]] = 1; @@ -773,7 +800,7 @@ int swf_TextCountBits(SWFFONT * font,U8 * s,int scale,U8 * gbits,U8 * abits) glyph = font->ascii2glyph[s[0]]; if(glyph>=0) { g = swf_CountUBits(glyph,g); - a = swf_CountBits((((U32)font->glyph[glyph].advance)*scale)/100,a); + a = swf_CountBits(((((U32)font->glyph[glyph].advance)*scale)/20)/100,a); } s++; } @@ -799,7 +826,7 @@ int swf_TextSetCharRecord(TAG * t,SWFFONT * font,U8 * s,int scale,U8 gbits,U8 ab g = font->ascii2glyph[s[i]]; if(g>=0) { swf_SetBits(t,g,gbits); - swf_SetBits(t,(((U32)font->glyph[g].advance)*scale)/100,abits); + swf_SetBits(t,((((U32)font->glyph[g].advance)*scale)/20)/100,abits); l++; if(l==0x7f) break; @@ -822,7 +849,7 @@ U32 swf_TextGetWidth(SWFFONT * font,U8 * s,int scale) if(*s < font->maxascii) g = font->ascii2glyph[*s]; if(g>=0) - res += font->glyph[g].advance; + res += font->glyph[g].advance/20; s++; } if (scale) res = (res*scale)/100; @@ -922,8 +949,8 @@ void swf_WriteFont(SWFFONT*font, char* filename) { int g = font->ascii2glyph[s]; if(g>=0) { - if(font->glyph[g].advance*textscale/64 > xmax) { - xmax = font->glyph[g].advance*textscale/64; + if((font->glyph[g].advance*textscale/20)/64 > xmax) { + xmax = (font->glyph[g].advance*textscale/20)/64; } c++; } @@ -984,8 +1011,8 @@ void swf_WriteFont(SWFFONT*font, char* filename) } swf_SetU8(t,1); swf_SetBits(t, g, gbits); - swf_SetBits(t, font->glyph[g].advance, abits); - lastx = x*xmax+font->glyph[g].advance; + swf_SetBits(t, font->glyph[g].advance/20, abits); + lastx = x*xmax+(font->glyph[g].advance/20); swf_ResetWriteBits(t); } } @@ -1068,7 +1095,7 @@ SRECT swf_SetDefineText(TAG*tag, SWFFONT*font, RGBA*rgb, char*text, int scale) rn.ymin = (rn.ymin * scale)/100; rn.ymax = (rn.ymax * scale)/100; swf_ExpandRect2(&r, &rn); - pos += (font->glyph[g].advance*scale*20)/100; + pos += (font->glyph[g].advance*scale)/100; } } c++; @@ -1131,9 +1158,8 @@ void swf_FontCreateLayout(SWFFONT*f) bbox = swf_GetShapeBoundingBox(shape2); swf_Shape2Free(shape2); f->layout->bounds[t] = bbox; - /* FIXME */ - //width = (bbox.xmax - bbox.xmin)/20; - width = (bbox.xmax)/20; + + width = (bbox.xmax); /* The following is a heuristic- it may be that extractfont_DefineText has already found out some widths for individual characters (from the way @@ -1229,7 +1255,7 @@ void swf_DrawText(drawer_t*draw, SWFFONT*font, char*text) l = l->next; } swf_Shape2Free(shape2); - advance += font->glyph[g].advance; + advance += font->glyph[g].advance/20.0; } }