Comparing version 0.8.1 to 0.8.2
@@ -30,7 +30,65 @@ // Generated by CoffeeScript 1.12.1 | ||
this.bbox = this.font.bbox; | ||
this.layoutCache = Object.create(null); | ||
} | ||
EmbeddedFont.prototype.layoutRun = function(text, features) { | ||
var i, j, key, len, position, ref, run; | ||
run = this.font.layout(text, features); | ||
ref = run.positions; | ||
for (i = j = 0, len = ref.length; j < len; i = ++j) { | ||
position = ref[i]; | ||
for (key in position) { | ||
position[key] *= this.scale; | ||
} | ||
position.advanceWidth = run.glyphs[i].advanceWidth * this.scale; | ||
} | ||
return run; | ||
}; | ||
EmbeddedFont.prototype.layoutCached = function(text) { | ||
var cached, run; | ||
if (cached = this.layoutCache[text]) { | ||
return cached; | ||
} | ||
run = this.layoutRun(text); | ||
this.layoutCache[text] = run; | ||
return run; | ||
}; | ||
EmbeddedFont.prototype.layout = function(text, features, onlyWidth) { | ||
var advanceWidth, glyphs, index, last, positions, ref, run; | ||
if (onlyWidth == null) { | ||
onlyWidth = false; | ||
} | ||
if (features) { | ||
return this.layoutRun(text, features); | ||
} | ||
glyphs = onlyWidth ? null : []; | ||
positions = onlyWidth ? null : []; | ||
advanceWidth = 0; | ||
last = 0; | ||
index = 0; | ||
while (index <= text.length) { | ||
if ((index === text.length && last < index) || ((ref = text.charAt(index)) === ' ' || ref === '\t')) { | ||
run = this.layoutCached(text.slice(last, ++index)); | ||
if (!onlyWidth) { | ||
glyphs.push.apply(glyphs, run.glyphs); | ||
positions.push.apply(positions, run.positions); | ||
} | ||
advanceWidth += run.advanceWidth; | ||
last = index; | ||
} else { | ||
index++; | ||
} | ||
} | ||
return { | ||
glyphs: glyphs, | ||
positions: positions, | ||
advanceWidth: advanceWidth | ||
}; | ||
}; | ||
EmbeddedFont.prototype.encode = function(text, features) { | ||
var base, base1, gid, glyph, glyphs, i, j, key, len, positions, ref, res; | ||
ref = this.font.layout(text, features), glyphs = ref.glyphs, positions = ref.positions; | ||
var base, base1, gid, glyph, glyphs, i, j, len, positions, ref, res; | ||
ref = this.layout(text, features), glyphs = ref.glyphs, positions = ref.positions; | ||
res = []; | ||
@@ -47,6 +105,2 @@ for (i = j = 0, len = glyphs.length; j < len; i = ++j) { | ||
} | ||
for (key in positions[i]) { | ||
positions[i][key] *= this.scale; | ||
} | ||
positions[i].advanceWidth = glyph.advanceWidth * this.scale; | ||
} | ||
@@ -58,4 +112,4 @@ return [res, positions]; | ||
var scale, width; | ||
width = this.font.layout(string, features).advanceWidth; | ||
scale = size / this.font.unitsPerEm; | ||
width = this.layout(string, features, true).advanceWidth; | ||
scale = size / 1000; | ||
return width * scale; | ||
@@ -62,0 +116,0 @@ }; |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"homepage": "http://pdfkit.org/", | ||
@@ -15,0 +15,0 @@ "author": { |
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
745348
3535