package { import flash.display.GradientType; import flash.display.MovieClip; import flash.display.SpreadMethod; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.geom.Matrix; import org.libspark.font.AnotherFontLoader; import org.libspark.font.data.RawFont; import org.libspark.font.render.GlyphShape; public class RuntimeFontParser extends MovieClip { private var _loader:AnotherFontLoader private var _typeface:RawFont; private var _myGlyph:Sprite; private var _glyph_ar:Array; private var _glyph:GlyphShape; /** * example usage of some classes within the RuntimeFontParser packages */ public function RuntimeFontParser() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; _loader = new AnotherFontLoader( "AppleSimple.ttf" ); _loader.addEventListener( Event.COMPLETE, drawGlyphs ); } private function drawGlyphs(evt:Event):void { _typeface = _loader.font; //this.addEventListener( Event.ENTER_FRAME, drawGradientGlyph ); drawGradientGlyph(null); } private var _num:Number = 0; private function drawGradientGlyph(evt:Event):void { _typeface.graphics.clear(); //_typeface.graphics.lineStyle( 15, 0x99add3, 1, true, "normal", null, null, 1 ); //_typeface.effects.beginFill( 0xffffff, 1 ); // _typeface.effects.b _num+=.1; var fillType:String = GradientType.RADIAL; var colors:Array = [0x2f252c, 0xd3ccb2, 0x6e6751]; var alphas:Array = [1, 1, 1]; var ratios:Array = [80, 150, 255]; var matr:Matrix = new Matrix(); matr.createGradientBox( 50 + Math.abs(Math.cos(_num)*100), 50 + Math.abs(Math.cos(_num)*100), 0, 250+(Math.cos(_num)*200), 250+(Math.sin(_num)*200)); var spreadMethod:String = SpreadMethod.REFLECT; //REPEATE, PAD, OR REFLECT _typeface.graphics.beginGradientFill( fillType, colors, alphas, ratios, matr, spreadMethod ); //_myGlyph = _typeface.graphics.drawGlyph( Math.random()*200 ); if(_myGlyph) { removeChild(_myGlyph); _myGlyph = null; } _myGlyph = _typeface.graphics.drawGlyph( 94 ); _myGlyph.x = 100; _myGlyph.y = 50; _myGlyph.scaleX = _myGlyph.scaleY = .2; addChild(_myGlyph); _myGlyph = _typeface.graphics.drawGlyph( 95 ); _myGlyph.x = 300; _myGlyph.y = 50; _myGlyph.scaleX = _myGlyph.scaleY = .2; addChild(_myGlyph); //_glyphs = []; // try just drawing this shape //drawLetter( 50, 100, 100 ); } /** * draw a physical letter */ private function drawLetter( char:Number, x:Number, y:Number ):void { _glyph = new GlyphShape(); _glyph.data = _typeface; _glyph.drawPhysicalGlyph( char ); _glyph.x = x; _glyph.y = y; //_glyph.scaleX = _glyph.scaleY = .2; //_glyph.rotation = 180; //_glyph.x = 1000; //_glyph.y = 200; addChild(_glyph); _glyphs.push(_glyph); } private var _glyphs:Array; private function spinGlyphs(evt:Event):void { for(var i:int=0;i<_glyphs.length;i++) { GlyphShape(_glyphs[i]).rotationY += 3; } } } }