Embedded Fonts Bug?
forked from フォント共有テスト(Dynamic Embedded Fonts) (diff: 86)
http://twitpic.com/3v200c
ActionScript3 source code
/**
* Copyright zob ( http://wonderfl.net/user/zob )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7D7X
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.events.Event;
import flash.utils.*;
[SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]
public class TextTest extends Sprite {
private var text:TextField = new TextField();
public function TextTest() {
var newFont:FontEmbed = new FontEmbed();
newFont.addEventListener(FontEmbed.FONT_LOADED, onFontLoaded);
newFont.load("http://nullurban.appspot.com/times.swf", "Times New Roman");
}
private function onFontLoaded(e:Event):void
{
text.height = 45; text.width = 600; text.embedFonts = true; text.defaultTextFormat = new TextFormat("Times New Roman", 75);
text.y = stage.stageHeight; text.text = "WONDERFL"; addChild(text);
stage.addEventListener(Event.ENTER_FRAME, processing);
}
private function processing(e:Event):void
{
text.textColor = 0xFFFFFF*Math.sin(getTimer()/1000);
text.x = 30+50*Math.sin(getTimer()/100);
text.y = 465-(getTimer()/10)%520;
}
}
}
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.EventDispatcher;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.Font;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
import flash.system.Security;
class FontEmbed extends EventDispatcher {
private var _fontClassName:String
private var _loader:Loader = new Loader()
public var progress:int;
public var font:String;
public static const FONT_LOADED:String = "font_loaded";
public function FontEmbed() {}
public function load(fontPath:String, fontClassName:String):void {
Security.loadPolicyFile("http://nullurban.appspot.com/crossdomain.xml");
Security.allowDomain("nullurban.appspot.com");
font = fontClassName;
swfLoad(fontPath);
_fontClassName = fontClassName;
}
//Load FontSwf
private function swfLoad(fontPath:String):void{
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.securityDomain = SecurityDomain.currentDomain;
context.applicationDomain = ApplicationDomain.currentDomain;
var req:URLRequest = new URLRequest(fontPath);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadComplete);
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgressListener);
_loader.load(req, context);
}
//Progress
private function onProgressListener(e:ProgressEvent):void {
progress = e.bytesLoaded/e.bytesTotal*100;
}
//Load Complete
private function swfLoadComplete(e:Event):void {
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,swfLoadComplete);
_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,onProgressListener);
var fontClass:Class = _loader.contentLoaderInfo.applicationDomain.getDefinition(_fontClassName) as Class;
try{
Font.registerFont(fontClass);
}catch(e:Error){
//
}
dispatchEvent(new Event(FontEmbed.FONT_LOADED));
}
}