Last active
December 10, 2015 06:59
-
-
Save Simn/4398181 to your computer and use it in GitHub Desktop.
haxe @:font example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@: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