Flash Text Engineで異体字の表示

Adobe Flash 10のFlash Text EngineでIVSによる異体字切り替え

一応ソースコードをはっておく。haXeで書いた。

import flash.text.engine.ElementFormat;
import flash.text.engine.FontDescription;
import flash.text.engine.TextBlock;
import flash.text.engine.TextElement;
import flash.text.engine.TextLine;
import flash.display.Sprite;
using StringTools;
using hxunicode.UnicodeTools;

class FlashSample extends Sprite {
    public function new() {
        super();
        var str = "花園明朝 𠀋𧜣 辻#17#辻#18#";
        str = str.replace("#17#", (0xe0100).uCodeToString());
        str = str.replace("#18#", (0xe0101).uCodeToString());
        var font = new FontDescription("花園明朝OT xProN");
        var format = new ElementFormat(font);
        format.locale = "ja";
        var textElement = new TextElement(str, format);
        var textBlock:TextBlock = new TextBlock();
        textBlock.content = textElement;
        
        var textLine1 = textBlock.createTextLine();
        addChild(textLine1);
        textLine1.x = 30;
        textLine1.y = 30 + textLine1.height;
    }
    public static function main() {
        flash.Lib.current.addChild(new FlashSample());
    }
}

hxunicodeは自作ライブラリ。#17#のような表記を異体字セレクタに置き換えるのに使っただけ。