Comparing version 0.3.0 to 0.4.0
@@ -101,16 +101,16 @@ var Directory = require('./directory') | ||
this.widths = [] | ||
for (var code in this.codeMap) { | ||
if (code < 32) continue | ||
var gid = this.codeMap[code] | ||
this.widths.push(Math.round(this.tables.hmtx.metrics[gid] * this.scaleFactor)) | ||
} | ||
this.avgCharWidth = this.tables.os2 && (this.tables.os2.xAvgCharWidth * this.scaleFactor) || 0 | ||
this.avgCharWidth = this.tables.os2 && this.tables.os2.xAvgCharWidth || 0 | ||
} | ||
TTFFont.prototype.stringWidth = function(string, size) { | ||
var width = 0, scale = size / 1000 | ||
var width = 0, scale = size / this.tables.head.unitsPerEm | ||
for (var i = 0, len = string.length; i < len; ++i) { | ||
var code = string.charCodeAt(i) - 32 // - 32 because of non AFM font | ||
width += this.widths[code] || this.avgCharWidth | ||
var code = string.charCodeAt(i) //- 32 // - 32 because of non AFM font | ||
if (code < 32) { | ||
continue | ||
} | ||
var gid = this.codeMap[code] | ||
width += this.tables.hmtx.metrics[gid] || this.avgCharWidth | ||
} | ||
@@ -117,0 +117,0 @@ return width * scale |
@@ -8,3 +8,3 @@ { | ||
"description": "TTFjs is a TrueType font parser entirely written in JavaScript and compatible to both Node.js and the Browser.", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"main": "./lib/ttf", | ||
@@ -11,0 +11,0 @@ "homepage": "https://github.com/rkusa/ttfjs", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32522
813