X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswftext.c;h=ad17f1c4997e43b3d577964eb52e09f569de8df4;hb=d0884f3fcd06d63b52834d48076a100d0a4e9557;hp=0adaf2be5a7f8066b48841aefde988dc758da336;hpb=9ad02f173cca3f7c0d51f641d0d668219a561e7d;p=swftools.git diff --git a/lib/modules/swftext.c b/lib/modules/swftext.c index 0adaf2b..ad17f1c 100644 --- a/lib/modules/swftext.c +++ b/lib/modules/swftext.c @@ -519,6 +519,7 @@ int swf_FontReduce(SWFFONT * f,FONTUSAGE * use) { int i,j; if ((!f)||(!use)) return -1; + /* TODO: layout, glyphnames */ j = 0; for (i=0;inumchars;i++) if (f->glyph[i].shape) @@ -542,6 +543,68 @@ int swf_FontReduce(SWFFONT * f,FONTUSAGE * use) return j; } +void swf_FontSort(SWFFONT * font) +{ + if(!font) return; + int i,j,k; + int* newplace = malloc(sizeof(int)*font->numchars); + int* newpos; + + for(i=0;inumchars;i++) { + newplace[i] = i; + } + for(i=0;inumchars;i++) + for(j=0;jglyph2ascii[i] < font->glyph2ascii[j]) { + int n1,n2; + char* c1,*c2; + SWFGLYPH g1,g2; + SRECT r1,r2; + n1=newplace[i]; + n2=newplace[j]; + newplace[j] = n1; + newplace[i] = n2; + n1=font->glyph2ascii[i]; + n2=font->glyph2ascii[j]; + font->glyph2ascii[j] = n1; + font->glyph2ascii[i] = n2; + g1=font->glyph[i]; + g2=font->glyph[j]; + font->glyph[j] = g1; + font->glyph[i] = g2; + if(font->glyphnames) { + c1 = font->glyphnames[i]; + c2 = font->glyphnames[j]; + font->glyphnames[j] = c1; + font->glyphnames[i] = c2; + } + if(font->layout) { + r1 = font->layout->bounds[i]; + r2 = font->layout->bounds[j]; + font->layout->bounds[j] = r1; + font->layout->bounds[i] = r2; + } + } + } + newpos = malloc(sizeof(int)*font->numchars); + for(i=0;inumchars;i++) { + newpos[newplace[i]] = i; + } + for(i=0;imaxascii;i++) { + if(font->ascii2glyph[i]>=0) + font->ascii2glyph[i] = newpos[font->ascii2glyph[i]]; + } + + free(newpos); + free(newplace); +} + +void swf_FontPrepareForEditText(SWFFONT * font) +{ + if(!font->layout) + swf_FontCreateLayout(font); + swf_FontSort(font); +} int swf_FontInitUsage(SWFFONT* f, FONTUSAGE * use) { if (!use) return -1; @@ -677,7 +740,7 @@ int swf_FontSetDefine2(TAG *tag, SWFFONT * f) /* font code table */ if(flags & 4) /* wide codes */ { - for(t=0;tnumchars;t++) { + for(t=0;tnumchars;t++) { swf_SetU16(tag,f->glyph2ascii[t]); } } else { @@ -750,9 +813,10 @@ int swf_FontSetInfo(TAG * t,SWFFONT * f) swf_SetU8(t,(flags&0xfe)|wide); for (i=0;inumchars;i++) { - if (f->glyph[i].shape) - wide?swf_SetU16(t,f->glyph2ascii[i]): - swf_SetU8(t,f->glyph2ascii[i]); + if (f->glyph[i].shape) { + int g2a = f->glyph2ascii[i]; + wide?swf_SetU16(t,g2a):swf_SetU8(t,g2a); + } } return 0; @@ -1184,7 +1248,7 @@ void swf_SetEditText(TAG*tag, U16 flags, SRECT r, char*text, RGBA*color, swf_SetString(tag,text); } -SRECT swf_SetDefineText(TAG*tag, SWFFONT*font, RGBA*rgb, char*text, int scale, MATRIX* m) +SRECT swf_SetDefineText(TAG*tag, SWFFONT*font, RGBA*rgb, char*text, int scale) { SRECT r; U8 gbits, abits; @@ -1204,7 +1268,15 @@ SRECT swf_SetDefineText(TAG*tag, SWFFONT*font, RGBA*rgb, char*text, int scale, M } swf_SetRect(tag,&r); - swf_SetMatrix(tag,m); + + /* The text matrix is pretty boring, as it doesn't apply to + individual characters, but rather whole text objects (or + at least whole char records- haven't tested). + So it can't do anything which we can't already do with + the placeobject tag we use for placing the text on the scene. + */ + swf_SetMatrix(tag,0); + swf_TextCountBitsUTF8(font,text,scale*20,&gbits,&abits); swf_SetU8(tag,gbits); swf_SetU8(tag,abits); @@ -1259,7 +1331,7 @@ void swf_FontCreateLayout(SWFFONT*f) they are used)- we now have to guess whether that width might be possible, which is the case if it isn't either much too big or much too small */ if(width > f->glyph[t].advance*3/2 || - width*2 < f->glyph[t].advance) + width < f->glyph[t].advance/2) f->glyph[t].advance = width; if(-bbox.ymin > f->layout->ascent)