Skip to content

Instantly share code, notes, and snippets.

@Simn
Last active December 10, 2015 06:59
Show Gist options
  • Save Simn/4398181 to your computer and use it in GitHub Desktop.
Save Simn/4398181 to your computer and use it in GitHub Desktop.
haxe @:font example
@:font("C:/Windows/fonts/Arial.ttf", "a-zA-Z {}\\-\"1234")
class MyFont extends flash.text.Font { }
class Main {
static function main() {
var font = new MyFont();
var fmt = new flash.text.TextFormat();
fmt.size = 50;
fmt.font = font.fontName;
var tf = new flash.text.TextField();
tf.embedFonts = true;
tf.defaultTextFormat = fmt;
tf.wordWrap = true;
tf.multiline = true;
tf.width = flash.Lib.current.stage.stageWidth;
tf.height = flash.Lib.current.stage.stageHeight;
tf.type = flash.text.TextFieldType.INPUT;
var all = [];
var nlAfter = new IntHash();
nlAfter.set("9".code, true);
nlAfter.set("Z".code, true);
nlAfter.set("z".code, true);
for (i in 33...0xFF)
all.push(i);
var buf = new StringBuf();
function add(i) {
buf.addChar(i);
all.remove(i);
if (nlAfter.exists(i)) {
buf.addChar(10);
}
}
for (i in '0'.code...'9'.code + 1)
add(i);
for (i in 'a'.code...'z'.code + 1)
add(i);
for (i in 'A'.code...'Z'.code + 1)
add(i);
for (i in all)
add(i);
tf.text = buf.toString();
flash.Lib.current.addChild(tf);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment