|
@@ -1,6 +1,7 @@
|
|
/**
|
|
/**
|
|
* @author gero3 / https://github.com/gero3
|
|
* @author gero3 / https://github.com/gero3
|
|
* @author tentone / https://github.com/tentone
|
|
* @author tentone / https://github.com/tentone
|
|
|
|
+ * @author troy351 / https://github.com/troy351
|
|
*
|
|
*
|
|
* Requires opentype.js to be included in the project.
|
|
* Requires opentype.js to be included in the project.
|
|
* Loads TTF files and converts them into typeface JSON that can be used directly
|
|
* Loads TTF files and converts them into typeface JSON that can be used directly
|
|
@@ -48,12 +49,16 @@ THREE.TTFLoader.prototype = {
|
|
|
|
|
|
var glyphs = {};
|
|
var glyphs = {};
|
|
var scale = ( 100000 ) / ( ( font.unitsPerEm || 2048 ) * 72 );
|
|
var scale = ( 100000 ) / ( ( font.unitsPerEm || 2048 ) * 72 );
|
|
|
|
+
|
|
|
|
+ var glyphIndexMap = font.encoding.cmap.glyphIndexMap;
|
|
|
|
+ var unicodes = Object.keys( glyphIndexMap );
|
|
|
|
|
|
- for ( var i = 0; i < font.glyphs.length; i ++ ) {
|
|
|
|
|
|
+ for ( var i = 0; i < unicodes.length; i ++ ) {
|
|
|
|
|
|
- var glyph = font.glyphs.glyphs[ i ];
|
|
|
|
|
|
+ var unicode = unicodes[ i ];
|
|
|
|
+ var glyph = font.glyphs.glyphs[ glyphIndexMap[ unicode ] ];
|
|
|
|
|
|
- if ( glyph.unicode !== undefined ) {
|
|
|
|
|
|
+ if ( unicode !== undefined ) {
|
|
|
|
|
|
var token = {
|
|
var token = {
|
|
ha: round( glyph.advanceWidth * scale ),
|
|
ha: round( glyph.advanceWidth * scale ),
|
|
@@ -98,7 +103,7 @@ THREE.TTFLoader.prototype = {
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
- glyphs[ String.fromCharCode( glyph.unicode ) ] = token;
|
|
|
|
|
|
+ glyphs[ String.fromCodePoint( glyph.unicode ) ] = token;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -106,7 +111,7 @@ THREE.TTFLoader.prototype = {
|
|
|
|
|
|
return {
|
|
return {
|
|
glyphs: glyphs,
|
|
glyphs: glyphs,
|
|
- familyName: font.familyName,
|
|
|
|
|
|
+ familyName: font.getEnglishName( 'fullName' ),
|
|
ascender: round( font.ascender * scale ),
|
|
ascender: round( font.ascender * scale ),
|
|
descender: round( font.descender * scale ),
|
|
descender: round( font.descender * scale ),
|
|
underlinePosition: font.tables.post.underlinePosition,
|
|
underlinePosition: font.tables.post.underlinePosition,
|