|
@@ -2,7 +2,22 @@ package h2d;
|
|
|
|
|
|
class Font #if !macro extends Tile #end {
|
|
class Font #if !macro extends Tile #end {
|
|
|
|
|
|
- static var DEFAULT_CHARS = " ?!\"#$%&|<>@'()[]{}*+-=/.,:;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzéèêëÉÈÊËàâäáÀÂÄÁùûüúÙÛÜÚîïíÎÏÍôóöõÔÓÖçÇñÑ¡¿ßæœÆŒ";
|
|
|
|
|
|
+ /**
|
|
|
|
+ Contains Hiragana, Katanaga, japanese punctuaction and full width space (0x3000) full width numbers (0-9) and some full width ascii punctuation (!:?%&()-). Does not include full width A-Za-z.
|
|
|
|
+ **/
|
|
|
|
+ public static var JP_KANA = " あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわゐゑをんがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽゃゅょアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヱヲンガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポヴャぇっッュョァィゥェォ・ー「」、。『』“”!:?%&()-0123456789";
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Contains the whole ASCII charset.
|
|
|
|
+ **/
|
|
|
|
+ public static var ASCII = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ The Latin1 (ISO 8859-1) charset (only the extra chars, no the ASCII part)
|
|
|
|
+ **/
|
|
|
|
+ public static var LATIN1 = "¡¢£¤¥¦§¨©ª«¬-®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
|
|
|
|
+
|
|
|
|
+ static var DEFAULT_CHARSET = ASCII + LATIN1;
|
|
|
|
|
|
#if !macro
|
|
#if !macro
|
|
|
|
|
|
@@ -10,16 +25,16 @@ class Font #if !macro extends Tile #end {
|
|
public var size(default, null) : Int;
|
|
public var size(default, null) : Int;
|
|
public var glyphs : Array<Tile>;
|
|
public var glyphs : Array<Tile>;
|
|
public var lineHeight : Int;
|
|
public var lineHeight : Int;
|
|
- var chars : String;
|
|
|
|
|
|
+ var charset : String;
|
|
var aa : Bool;
|
|
var aa : Bool;
|
|
|
|
|
|
- public function new( name : String, size : Int, aa = true, ?chars ) {
|
|
|
|
|
|
+ public function new( name : String, size : Int, aa = true, ?charset ) {
|
|
super(null, 0, 0, 0, 0);
|
|
super(null, 0, 0, 0, 0);
|
|
- if( chars == null )
|
|
|
|
- chars = DEFAULT_CHARS;
|
|
|
|
|
|
+ if( charset == null )
|
|
|
|
+ charset = DEFAULT_CHARSET;
|
|
this.name = name;
|
|
this.name = name;
|
|
this.size = size;
|
|
this.size = size;
|
|
- this.chars = chars;
|
|
|
|
|
|
+ this.charset = charset;
|
|
this.aa = aa;
|
|
this.aa = aa;
|
|
init();
|
|
init();
|
|
}
|
|
}
|
|
@@ -35,6 +50,10 @@ class Font #if !macro extends Tile #end {
|
|
lineHeight >>= 1;
|
|
lineHeight >>= 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function hasChar( code : Int ) {
|
|
|
|
+ return glyphs[code] != null;
|
|
|
|
+ }
|
|
|
|
+
|
|
function init() {
|
|
function init() {
|
|
lineHeight = 0;
|
|
lineHeight = 0;
|
|
var tf = new flash.text.TextField();
|
|
var tf = new flash.text.TextField();
|
|
@@ -54,8 +73,8 @@ class Font #if !macro extends Tile #end {
|
|
}
|
|
}
|
|
var surf = 0;
|
|
var surf = 0;
|
|
var sizes = [];
|
|
var sizes = [];
|
|
- for( i in 0...chars.length ) {
|
|
|
|
- tf.text = chars.charAt(i);
|
|
|
|
|
|
+ for( i in 0...charset.length ) {
|
|
|
|
+ tf.text = charset.charAt(i);
|
|
var w = Math.ceil(tf.textWidth);
|
|
var w = Math.ceil(tf.textWidth);
|
|
if( w == 0 ) continue;
|
|
if( w == 0 ) continue;
|
|
var h = Math.ceil(tf.textHeight);
|
|
var h = Math.ceil(tf.textHeight);
|
|
@@ -78,7 +97,7 @@ class Font #if !macro extends Tile #end {
|
|
all = [];
|
|
all = [];
|
|
var m = new flash.geom.Matrix();
|
|
var m = new flash.geom.Matrix();
|
|
var x = 0, y = 0, lineH = 0;
|
|
var x = 0, y = 0, lineH = 0;
|
|
- for( i in 0...chars.length ) {
|
|
|
|
|
|
+ for( i in 0...charset.length ) {
|
|
var size = sizes[i];
|
|
var size = sizes[i];
|
|
if( size == null ) continue;
|
|
if( size == null ) continue;
|
|
var w = size.w;
|
|
var w = size.w;
|
|
@@ -96,11 +115,11 @@ class Font #if !macro extends Tile #end {
|
|
}
|
|
}
|
|
m.tx = x - 2;
|
|
m.tx = x - 2;
|
|
m.ty = y - 2;
|
|
m.ty = y - 2;
|
|
- tf.text = chars.charAt(i);
|
|
|
|
|
|
+ tf.text = charset.charAt(i);
|
|
bmp.draw(tf, m);
|
|
bmp.draw(tf, m);
|
|
var t = sub(x, y, w, h);
|
|
var t = sub(x, y, w, h);
|
|
all.push(t);
|
|
all.push(t);
|
|
- glyphs[chars.charCodeAt(i)] = t;
|
|
|
|
|
|
+ glyphs[charset.charCodeAt(i)] = t;
|
|
// next element
|
|
// next element
|
|
if( h > lineH ) lineH = h;
|
|
if( h > lineH ) lineH = h;
|
|
x += w + 1;
|
|
x += w + 1;
|
|
@@ -136,6 +155,26 @@ class Font #if !macro extends Tile #end {
|
|
innerTex.uploadBytes(bytes);
|
|
innerTex.uploadBytes(bytes);
|
|
|
|
|
|
bmp.dispose();
|
|
bmp.dispose();
|
|
|
|
+
|
|
|
|
+ inline function map(code, to) {
|
|
|
|
+ if( glyphs[code] == null ) glyphs[code] = glyphs[to];
|
|
|
|
+ }
|
|
|
|
+ // fullwidth unicode to ASCII (if missing)
|
|
|
|
+ for( i in 1...0x5E )
|
|
|
|
+ map(0xFF01 + i, 0x21 + i);
|
|
|
|
+ // unicode spaces
|
|
|
|
+ map(0x3000, 0x20); // full width space
|
|
|
|
+ map(0xA0, 0x20); // nbsp
|
|
|
|
+ // unicode quotes
|
|
|
|
+ map("«".code, '"'.code);
|
|
|
|
+ map("»".code, '"'.code);
|
|
|
|
+ map("“".code, '"'.code);
|
|
|
|
+ map("”".code, '"'.code);
|
|
|
|
+ map("‘".code, "'".code);
|
|
|
|
+ map("’".code, "'".code);
|
|
|
|
+ map("‘".code, "'".code);
|
|
|
|
+ map("‹".code, "<".code);
|
|
|
|
+ map("›".code, ">".code);
|
|
}
|
|
}
|
|
|
|
|
|
#else
|
|
#else
|
|
@@ -153,7 +192,13 @@ class Font #if !macro extends Tile #end {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
#end
|
|
#end
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ By default, the charset is ASCII+LATIN1
|
|
|
|
+ **/
|
|
|
|
+ public static function setDefaultCharset( chars ) {
|
|
|
|
+ DEFAULT_CHARSET = chars;
|
|
|
|
+ }
|
|
|
|
|
|
public macro static function embed( name : String, file : String, ?chars : String, ?skipErrors : Bool ) {
|
|
public macro static function embed( name : String, file : String, ?chars : String, ?skipErrors : Bool ) {
|
|
var ok = true;
|
|
var ok = true;
|