+ drawpath(tag, outline,m);
+}
+
+/* SWFFont: copy all t1 font outlines to a local
+ array. */
+SWFFont::SWFFont(char*name, int id, char*filename)
+{
+ if(!T1_GetFontName(id))
+ T1_LoadFont(id);
+
+ this->name = strdup(T1_GetFontFileName(id));
+ this->fontid = strdup(name);
+ this->t1id = id;
+
+ char**a= T1_GetAllCharNames(id);
+ int t=0, outlinepos=0;
+ char*map[256];
+ while(a[t])
+ t++;
+
+ this->charnum = t;
+ if(!t)
+ return;
+ logf("<verbose> Font %s(%d): Storing %d outlines.\n", name, id, t);
+
+ outline = (T1_OUTLINE**)malloc(t*sizeof(T1_OUTLINE*));
+ charname = (char**)malloc(t*sizeof(char*));
+ used = (char*)malloc(t*sizeof(char));
+ char2swfcharid = (U16*)malloc(t*2);
+ swfcharid2char = (U16*)malloc(t*2);
+ swfcharpos = 0;
+
+ memset(used,0,t*sizeof(char));
+
+ this->swfid = ++currentswfid;
+
+
+ t=0;
+ while(*a)
+ {
+ map[t] = *a;
+ a++;
+ t++;
+ if(t==256 || !*a) {
+ int s;
+ for(s=t;s<256;s++)
+ map[s] = ".notdef";
+
+ int ret = T1_ReencodeFont(id, map);
+ if(ret) {
+ T1_DeleteFont(id);
+ T1_LoadFont(id);
+ int ret = T1_ReencodeFont(id, map);
+ if(ret)
+ fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret);
+ }
+
+ // parsecharacters
+ for(s=0;s<t;s++)
+ {
+ this->outline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0));
+ this->charname[outlinepos] = strdup(T1_GetCharName(id, s));
+ outlinepos++;
+ }
+ t=0;
+ }
+ }
+}
+
+/* free all tables, write out definefont tags */
+SWFFont::~SWFFont()
+{
+ int t,usednum=0;
+ int*ptr = (int*)malloc(swfcharpos*sizeof(int));
+
+ for(t=0;t<charnum;t++)
+ if(used[t]) usednum++;
+
+ if(usednum && !drawonlyshapes)
+ {
+ logf("<verbose> Font %s has %d used characters",fontid, usednum);
+ TAG*ftag = InsertTag(swf.FirstTag,ST_DEFINEFONT);
+ SetU16(ftag, this->swfid);
+ int initpos = GetDataSize(ftag);
+ swfmatrix m;
+ m.m11 = m.m22 = 1;
+ m.m21 = m.m12 = 0;
+ m.m13 = CHARMIDX;
+ m.m23 = CHARMIDY;
+ for(t=0;t<swfcharpos;t++)
+ {
+ ptr[t] = GetDataSize(ftag);
+ SetU16(ftag, 0x1234);
+ }
+ for(t=0;t<swfcharpos;t++)
+ {
+ *(U16*)&ftag->data[ptr[t]] = GetDataSize(ftag)-initpos;
+ swflastx=0;
+ swflasty=0;
+ SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
+ SHAPE s;
+ s.bits.fill = 1;
+ s.bits.line = 0;
+ ShapeSetStyle(ftag,&s,0,1,0);
+ int lastfill = fill;
+ fill = 1;
+ storefont = 1;
+ drawpath(ftag, outline[swfcharid2char[t]],&m);
+ storefont = 0;
+ fill = lastfill;
+ ShapeSetEnd(ftag);
+ }
+ }
+
+ free(ptr);
+ free(outline);
+ for(t=0;t<charnum;t++)
+ free(charname[t]);
+ free(charname);
+ free(used);
+ free(swfcharid2char);
+ free(char2swfcharid);
+}
+
+T1_OUTLINE*SWFFont::getOutline(char*name)
+{
+ int t;
+ for(t=0;t<this->charnum;t++) {
+ if(!strcmp(this->charname[t],name)) {
+ if(!used[t])
+ {
+ swfcharid2char[swfcharpos] = t;
+ char2swfcharid[t] = swfcharpos;
+ swfcharpos++;
+ used[t] = 1;
+ }
+ return outline[t];
+ }
+ }
+ return 0;
+}
+
+int SWFFont::getSWFCharID(char*name)
+{
+ int t;
+ for(t=0;t<this->charnum;t++) {
+ if(!strcmp(this->charname[t],name)) {
+ if(!used[t])
+ {
+ swfcharid2char[swfcharpos] = t;
+ char2swfcharid[t] = swfcharpos++;
+ used[t] = 1;
+ }
+ return char2swfcharid[t];
+ }
+ }
+ logf("<warning> Didn't find character '%s' in font '%s'", name, this->name);
+ return 0;
+}
+
+char*SWFFont::getName()
+{
+ return this->name;