+ int textid = id++;
+ int spriteid = id++;
+ SRECT r;
+ r.xmin = 0;
+ r.ymin = miny*fontsize/1024;
+ r.xmax = width*fontsize/20480;
+ r.ymax = maxy*fontsize/1024;
+ tag = swf_InsertTag(tag, ST_DEFINETEXT);
+ swf_SetU16(tag, textid);
+ swf_SetRect(tag, &r);
+ swf_SetMatrix(tag, NULL);
+
+ U8 abits = 15;
+ U8 gbits = swf_CountBits(font->numchars, 0);
+ swf_SetU8(tag, gbits);
+ swf_SetU8(tag, abits);
+
+ RGBA rgb = {255,0,0,0};
+
+ swf_TextSetInfoRecord(tag, font, fontsize, &rgb, SET_TO_ZERO, SET_TO_ZERO);
+ ActionTAG*array = 0;
+ double x=0;
+ array = action_PushString(array, "xpos");
+ for(t=0;t<font->numchars;t++) {
+ swf_SetU8(tag, 1);
+ int width = abs((xmax[t] - xmin[t+1])*fontsize/1024) + 60;
+ array = action_PushInt(array, x/20 +(xmin[t]*scale/1024)/20);
+ x += width * overlarge_factor;
+ swf_SetBits(tag, t, gbits);
+ swf_SetBits(tag, width, abits);
+ swf_SetU8(tag, 128);
+ }
+ array = action_PushInt(array, x/20);
+ array = action_PushInt(array, font->numchars+1);
+ array = action_InitArray(array);
+ array = action_SetVariable(array);
+ swf_SetU8(tag, 0);
+
+ if(font->layout) {
+ tag = swf_InsertTag(tag, ST_DEFINESHAPE2);
+ SHAPE* s;
+ swf_ShapeNew(&s);
+ int ls = swf_ShapeAddLineStyle(s,20,&white);
+ int shapeid = id++;
+ swf_SetU16(tag,shapeid);
+ SRECT r;
+ r.xmin = 0;
+ r.xmax = 1024*20;
+ r.ymin = 0;
+ r.ymax = 256*20;
+ swf_SetRect(tag,&r);
+ swf_SetShapeHeader(tag,s);
+ swf_ShapeSetAll(tag,s,0,0,ls,0,0);
+
+ /* Ç and  are good chars to test ascent/descent extend */
+ int y1 = (-font->layout->ascent-miny*20.0)*256.0/(maxy-miny);
+ int y2 = (font->layout->descent-miny*20.0)*256.0/(maxy-miny);
+
+ swf_ShapeSetMove(tag,s,0,y1);
+ swf_ShapeSetLine(tag,s,width,0);
+ swf_ShapeSetMove(tag,s,0,y2);
+ swf_ShapeSetLine(tag,s,width,0);
+
+ swf_ShapeSetEnd(tag);
+ swf_ShapeFree(s);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ swf_ObjectPlace(tag, shapeid, depth++, NULL, NULL, NULL);
+ }
+
+ /* shapes */
+
+ for(t=0;t<font->numchars;t++) {
+ tag = swf_InsertTag(tag, ST_DEFINESHAPE2);
+ SHAPE* s;
+ swf_ShapeNew(&s);
+ int ls = swf_ShapeAddLineStyle(s,20*2,&black);
+ int ls2 = swf_ShapeAddLineStyle(s,20*2,&green);
+ int fs = swf_ShapeAddSolidFillStyle(s, &gray50);
+ int shapeid = id++;
+ swf_SetU16(tag,shapeid);
+ SRECT r;
+ r.xmin = 0;
+ r.xmax = 1024*20;
+ r.ymin = 0;
+ r.ymax = 512*20;
+ swf_SetRect(tag,&r);
+ swf_SetShapeHeader(tag,s);
+ swf_ShapeSetAll(tag,s,0,0,ls,fs,0);
+ SHAPE2*s2 = swf_ShapeToShape2(font->glyph[t].shape);
+ SHAPELINE*l = s2->lines;
+ int lastx=0,lasty=0;
+
+ double x1 = (1024*20 - (xmax[t] - xmin[t])*20*2*scale/20480.0)/2;
+ double y1 = -miny*20*scale*2/20480.0;
+ double scalex = scale*2/20480.0;
+ double scaley = scale*2/20480.0;
+
+ while(l) {
+ int lx = (l->x)*scalex+x1;
+ int ly = (l->y)*scaley+y1;
+ int sx = (l->sx)*scalex+x1;
+ int sy = (l->sy)*scaley+y1;
+ if(l->type == moveTo) {
+ swf_ShapeSetMove(tag,s,lx,ly);
+ } else if(l->type == lineTo) {
+ swf_ShapeSetLine(tag,s,lx-lastx,ly-lasty);
+ } else if(l->type == splineTo) {
+ swf_ShapeSetCurve(tag,s,sx-lastx,sy-lasty,lx-sx,ly-sy);
+ }
+ lastx = lx;
+ lasty = ly;
+ l = l->next;
+ }
+
+ if(font->alignzones) {
+ ALIGNZONE*zone = &font->alignzones[t];
+ swf_ShapeSetAll(tag,s,0,0,ls2,SET_TO_ZERO,SET_TO_ZERO);
+ if((zone->x&zone->dx)!=0xffff) {
+ double x = F16toFloat(zone->x)*20480.0*scalex+x1;
+ double dx = (F16toFloat(zone->x)+F16toFloat(zone->dx))*20480.0*scalex+x1;
+ swf_ShapeSetMove(tag,s,x,0);
+ swf_ShapeSetLine(tag,s,0,1024*20);
+ swf_ShapeSetMove(tag,s,dx,0);
+ swf_ShapeSetLine(tag,s,0,1024*20);
+ }
+ if((zone->y&zone->dy)!=0xffff) {
+ double y = -F16toFloat(zone->y)*20480.0*scaley+y1;
+ double dy = -(F16toFloat(zone->y)+F16toFloat(zone->dy))*20480.0*scaley+y1;
+ swf_ShapeSetMove(tag,s,0,y);
+ swf_ShapeSetLine(tag,s,1024*20,0);
+ swf_ShapeSetMove(tag,s,0,dy);
+ swf_ShapeSetLine(tag,s,1024*20,0);
+ }
+ }
+
+ swf_ShapeSetEnd(tag);
+ swf_ShapeFree(s);
+
+ tag = swf_InsertTag(tag, ST_DEFINESPRITE);
+ U16 spriteid=id++;
+ swf_SetU16(tag, spriteid);
+ swf_SetU16(tag, 1);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ swf_ObjectPlace(tag, shapeid, 1, NULL, NULL, NULL);
+ tag = swf_InsertTag(tag, ST_END);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ MATRIX m;
+ swf_GetMatrix(0, &m);
+ m.ty = 20000;
+ char txt[80];
+ sprintf(txt, "char%d", font->numchars-t);
+ swf_ObjectPlace(tag, spriteid, depth++, &m, NULL, txt);
+ }
+
+ /* marker */
+ tag = swf_InsertTag(tag, ST_DEFINESHAPE2);
+ int shapeid=id++;
+ RGBA blue = {0xff,0xc0,0xc0,0xff};
+ swf_ShapeSetRectangle(tag, shapeid, 20, 20, &blue);
+ tag = swf_InsertTag(tag, ST_DEFINESPRITE);
+ U16 spriteid2=id++;
+ swf_SetU16(tag, spriteid2);
+ swf_SetU16(tag, 1);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ swf_ObjectPlace(tag, shapeid, 1, NULL, NULL, NULL);
+ tag = swf_InsertTag(tag, ST_END);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ swf_ObjectPlace(tag, spriteid2, depth++, NULL, NULL, "marker");
+
+ /* textbar */
+ tag = swf_InsertTag(tag, ST_DEFINESPRITE);
+ swf_SetU16(tag, spriteid);
+ swf_SetU16(tag, 1);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ MATRIX m;
+ swf_GetMatrix(0, &m);
+ m.sx = 65536 * overlarge_factor;
+ m.sy = 65536 * overlarge_factor;
+ m.tx = 0;
+ m.ty = -miny*256*20/(maxy-miny);
+ swf_ObjectPlace(tag, textid, 1, &m, NULL, NULL);
+ tag = swf_InsertTag(tag, ST_END);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ swf_ObjectPlace(tag, spriteid, depth++, NULL, NULL, "textbar");
+
+ /* marker2 */
+ RGBA blue2 = {0x80,0x80,0xff,0x80};
+ tag = swf_InsertTag(tag, ST_DEFINESHAPE3);
+ int shapeid2=id++;
+ swf_ShapeSetRectangleWithBorder(tag, shapeid2, 20, 20, &blue2, 0, &white);
+ tag = swf_InsertTag(tag, ST_DEFINESPRITE);
+ U16 spriteid3=id++;
+ swf_SetU16(tag, spriteid3);
+ swf_SetU16(tag, 1);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ swf_ObjectPlace(tag, shapeid2, 1, NULL, NULL, NULL);
+ tag = swf_InsertTag(tag, ST_END);
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ swf_ObjectPlace(tag, spriteid3, depth++, NULL, NULL, "marker2");
+
+
+char*data =
+" var mouseListener = new Object();"
+" var speed = 0;"
+" var myx = 0;"
+" var currentMouseOver, currentChar;"
+" mouseListener.onMouseDown = function() { "
+" eval(\"_root.char\"+currentChar)._y = 20000;"
+" currentChar = currentMouseOver;"
+" var i = currentMouseOver;"
+" eval(\"_root.char\"+i)._y = 256;"
+" _root.marker2._yscale=256*100;"
+" _root.marker2._xscale=(xpos[i-1]-xpos[i])*100;"
+" _root.marker2._x=xpos[i]+myx;"
+" };"
+" mouseListener.onMouseMove = function() { "
+" if(_ymouse<256) {"
+" speed = Math.abs(_xmouse-512)>256?(512-_xmouse)/8:0;"
+" } else {"
+" speed = 0;"
+" }; "
+" }; "
+" setInterval( function(){ "
+" if(_ymouse<256) {"
+" var i, x=_xmouse-_root.textbar._x;"
+" for(i=xpos.length-1;i>0;i--) {"
+" if(x<xpos[i-1]) break;"
+" }"
+" currentMouseOver = i;"
+" _root.marker._yscale=256*100;"
+" _root.marker._xscale=(xpos[i-1]-xpos[i])*100;"
+" _root.marker._x=xpos[i]+myx;"
+" _root.textbar._x += 0.05;"
+" }"
+" if(myx+speed>0) {"
+" speed=0;"
+" } else if(myx+speed<-xpos[0]+1024) {"
+" speed=0;"
+" }"
+" myx+=speed;"
+" _root.textbar._x = myx;"
+" _root.marker._x += speed;"
+" _root.marker2._x += speed;"
+" }, 20);"
+" Mouse.addListener(mouseListener);"
+;
+ ActionTAG* atag = swf_ActionCompile(data, 6);
+
+ tag = swf_InsertTag(tag, ST_DOACTION);
+ swf_ActionSet(tag, array);
+ swf_ActionSet(tag, atag);
+ swf_SetU8(tag, 0);
+ swf_ActionFree(atag);
+
+ tag = swf_InsertTag(tag, ST_SHOWFRAME);
+
+ free(flags);
+ free(xmin);
+ free(xmax);
+ }
+
+ tag = swf_InsertTag(tag, ST_END);
+
+ swf.compressed = -1;
+ swf_SaveSWF(&swf, filename);
+ swf_FreeTags(&swf);
+}