外部SWFの埋め込みフォントをロードして読み込んで使う。
こちらの記事を参考にさせて頂きました。ありがとうございます。
http://plamo-tokyo.com/labo/as3swf/
FlashIDE で
・Flaファイル(フォント埋め込み用)を新規作成。
・「ライブラリパネル」>「新しいフォント」を選択してフォントシンボルを作成して、リンケージ名(クラス名)を付けます。
リンケージ名はここではMyHelveticaWorldとします。
で、パブリッシュして、 swfファイル名をMyFontEmbed.swfとします。
こちらの記事を参考にさせて頂きました。ありがとうございます。
http://119.245.215.115/blog/2010-03-12/1659
MyFontEmbed.as
package
{
import flash.display.Sprite;
import flash.events.Event;
public class MyFontEmbed extends Sprite
{
[Embed(
source = "./font_helvetica/HelveticaWorld-Regular.ttf",
fontName = "MyHelveticaWorld",
mimeType = "application/x-font",
advancedAntiAliasing = "true",
unicodeRange = "U+0020-U+007e"
)]
public static const MyHelveticaWorld:Class;
[Embed(
source = "./font_iwata/iwp3gm.ttf",
fontName = "MyIwataGothicV3",
mimeType = "application/x-font",
advancedAntiAliasing = "true",
unicodeRange = "U+0020-U+007e"
)]
public static const MyIwataGothicV3:Class;
public function MyFontEmbed() {
}
}
}
これをコンパイルしてMyFontEmbed.swfを作成します。
以上のどちらかで、フォントを埋め込んだ外部swfファイルができました。
で、このswfファイルをロードすることで埋め込みフォントが利用できます。
以下をコンパイル
MyFont.as
package {
import flash.display.Sprite;
import flash.display.Loader;
import flash.display.DisplayObject;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.text.*;
[SWF(backgroundColor=0xffffff, width="440", height="440", frameRate="60")]
public class MyFont extends Sprite {
private var _url :URLRequest = new URLRequest("MyFontEmbed.swf");
private var _loader:Loader = new Loader();
private var _context:LoaderContext = new LoaderContext();
public function MyFont () {
_context.applicationDomain = ApplicationDomain.currentDomain;
_loader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadComplete );
_loader.load( _url, _context );
}
private function loadComplete( e:Event ) :void{
var MyHelveticaWorld:Class = ApplicationDomain.currentDomain.getDefinition( "MyFontEmbed_MyHelveticaWorld" ) as Class; //Flex SDKでフォントswfをコンパイルした場合
//var MyHelveticaWorld:Class = ApplicationDomain.currentDomain.getDefinition( "MyHelveticaWorld" ) as Class; //FlashIDEでフォントswfをコンパイルした場合
Font.registerFont( MyHelveticaWorld );
var txt:TextField = addChild( new TextField () as DisplayObject ) as TextField;
var f:Font = new MyHelveticaWorld();
txt.defaultTextFormat = new TextFormat( f.fontName, 36);
txt.embedFonts = true;
txt.height = 60;
txt.width = 440;
txt.text = 'HelveticaWorld'
txt.x = stage.stageWidth / 2 - 120;
txt.y = stage.stageHeight / 2 - 40;
txt.background = true;
txt.backgroundColor = 0x000000;
txt.textColor = 0xfffffff;
}
}
}
日本語を表示させたいときは日本語用のunicode rangeを指定する必要があります。
それについては
D:\flex_sdk_3.4.0.6955(FlexSDKインストールディレクトリ)\frameworks\flash-unicode-table.xml
に記載されています。
No related posts.