mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Avoid creating intermediate strings in sanitizeMetrics
This patch avoids creating many intermediate strings, when adding dummy width/lsb entries for glyphs where those are missing. For the relevant PDF files in our test suite, the average number of intermediate strings are well over 1000.
This commit is contained in:
parent
b4fb1e21e7
commit
ae896fc071
1 changed files with 5 additions and 9 deletions
|
@ -3297,16 +3297,12 @@ var Font = (function FontClosure() {
|
|||
var numMissing = numOfSidebearings -
|
||||
((metrics.length - numOfMetrics * 4) >> 1);
|
||||
|
||||
var i, ii;
|
||||
if (numMissing > 0) {
|
||||
font.pos = (font.start ? font.start : 0) + metrics.offset;
|
||||
var entries = '';
|
||||
for (i = 0, ii = metrics.length; i < ii; i++) {
|
||||
entries += String.fromCharCode(font.getByte());
|
||||
}
|
||||
for (i = 0; i < numMissing; i++) {
|
||||
entries += '\x00\x00';
|
||||
}
|
||||
// For each missing glyph, we set both the width and lsb to 0 (zero).
|
||||
// Since we need to add two properties for each glyph, this explains
|
||||
// the use of |numMissing * 2| when initializing the typed array.
|
||||
var entries = new Uint8Array(metrics.length + numMissing * 2);
|
||||
entries.set(metrics.data);
|
||||
metrics.data = entries;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue