AS3でフォント埋め込み

Filed under AS3



フォント埋め込みのサンプル。

こちらのフォントを使わせてもらいました。

サンプルはこちら

以下ソースです。

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	[SWF(backgroundColor="0xFFFFFF")]
	public class embedFont extends Sprite
	{
		// フォント埋め込み
		[Embed(source='asset\\pf_ronda_seven.ttf', embedAsCFF="false", fontName='myFont', mimeType='application/x-font')]
		private var font:Class;

		public function embedFont()
		{
			// ステージの背低
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;

			// 埋め込んだフォントを使う
			var tf:TextField=new TextField();
			tf.embedFonts=true;
			tf.defaultTextFormat=new TextFormat("myFont", 20, 0x666666);
			tf.text="Embed Font Sample\n\nI used this font : Ronda Seven Fonts\n\nhttp://p.yusukekamiyamane.com/fonts/";
			tf.autoSize=TextFieldAutoSize.LEFT;
			tf.selectable=false;

			addChild(tf);
			tf.x = tf.y = 10;
		}
	}
}

Post a Comment

Your email is never published nor shared.