Flash Bilder 4日本語で文字を限定した埋め込みFontの作り方が面倒くさそう。
Flash CS5 で埋め込みFontを作成してFlash Builder 4で使ってみることにしました。
【Flash CS5】
1.Flash新規ドキュメント(Actionscript 3)
2.テキストツール(T)でテキストフィールドを作成
以下、プロパティパネル
3.今回はTLFテキストを選択しました
4.埋め込みたいフォントのフォントファミリーとスタイルを選択
5.埋め込み…をクリック
6.オプションタブ:名前を入力、埋め込む文字を指定
7.Actionscriptタブ:アウトラインフォーマットを選択
アウトラインフォーマットは、クラシック(DF3)とTLF(DF4)のどちらかを選択します。
Actionscript 用に書き出しと1 フレームに書き出しにチェック
クラス名にはオプションでつけた名前が入っています
今回のクラス名は
"HiraginoKakuGoW3"
ですクラシックはFlash Player 9までの従来のTextFieldのことで
TLFはFlash Player 10以降の
flash.text.engine.*
かflashx.textLayout.*
のことだろうと思います。http://help.adobe.com/ja_JP/flash/cs/using/WSb03e830bd6f770ee21a3597d124daee0526-8000.html
「ActionScript 用に書き出し」を選択した場合は、アウトラインフォーマットも選択します。TLF テキストコンテナの場合は、「TLF(DF4)」をアウトラインフォーマットとして選択します。クラシックテキストコンテナの場合は、「クラシック(DF3)」を選択します。
TLF コンテナとクラシックテキストコンテナのそれぞれで埋め込みフォントシンボルを使用するには、それぞれのコンテナごとに埋め込みフォントシンボルを作成する必要があります。TLF(DF4)アウトラインフォーマットは、PostScript Type 1 フォントでは使用できません。TLF(DF4)を使用するには、Flash Player バージョン 10 以降が必要です。
8.パブリッシュする。今回はfont.swfにしました。
【Flash Builder 4】
フォントをEmbedするClassをFontFamilyとしsingletonで作成しています。
リンケージクラス名をsymbolに設定します。
package { import flash.events.EventDispatcher; import flash.events.IEventDispatcher; import flash.text.Font; public class FontFamily extends EventDispatcher { private static var _instance:FontFamily; [Embed(source="assets/font.swf", symbol="HiraginoKakuGoW3")] private static var HiraginoKakuGoW3:Class; private static var _hiraginow3:Font; public function FontFamily(target:IEventDispatcher=null) { super(target); if( _instance != null ) throw new Error("Error:FontFamily already initialised."); if( _instance == null ) _instance = this; } public static function get instance():FontFamily { return initialize(); } private static function initialize():FontFamily { if (_instance == null){ _instance = new FontFamily(); } return _instance; } public static function get hiraginow3():Font { if (!_hiraginow3) _hiraginow3 = new HiraginoKakuGoW3() as Font; return _hiraginow3; } } } |
使い方はいたって簡単です。
今回はflash.text.engine.*を使いました。
var size:uint = 13; var color:uint = 0xffffff; var locale:String = 'ja'; // FontFamily.hiraginow3.fontName // FontLookup.EMBEDDED_CFF var font:FontDescription = new FontDescription(FontFamily.hiraginow3.fontName,FontWeight.NORMAL, FontPosture.NORMAL, FontLookup.EMBEDDED_CFF, RenderingMode.CFF); var format:ElementFormat = new ElementFormat(font, size, color); format.locale = locale; var textBlock:TextBlock = new TextBlock(); textBlock.lineRotation = TextRotation.ROTATE_0; textBlock.textJustifier = new EastAsianJustifier(locale, LineJustification.UNJUSTIFIED); var str:String = "埋め込みFont作成"; var w:uint = 300; var textElement:TextElement = new TextElement(str, format); textBlock.content = textElement; var textLine:TextLine = textBlock.createTextLine(null, w); var ypos:uint = 0; while(textLine) { addChild(textLine); textLine.x = 0; ypos += textLine.textHeight + 8; textLine.y = ypos; textLine = textBlock.createTextLine(textLine, w); } |
FontDescription
を新規作成する時にフォント名を指定するのと、FontLookup.EMBEDDED_CFF
に設定します。
Text Engine めんどくさい。
Text Layout Framework(TLF)もかなりめんどくさいけど、負けず劣らずです。
Adobeは何をさせたいんかなぁ。
ところで、Text Engine と TLFの使い分けはどこなんでしょう?