Browse Source

Improve the handling of `Encoding` dictionary, with `Differences` array, in `PartialEvaluator_preEvaluateFont`

I recently happened to look at the code I wrote for PR 5964, which fixed [bug 1157493](https://bugzilla.mozilla.org/show_bug.cgi?id=1157493), and I quickly realized that the solution is way too simplistic.
The fact that only using the `length` of a `Differences` array worked seems more like a happy accident for a particular set of font data, but could just as easily be incorrect for other PDF files.

Note that in practice, the case where the `Encoding` entry is a regular `Dict` (and not a `Ref` or `Name`) is very rare, hence I don't think that we really need to worry about having to reparse this data.
Also, the performance of this code-block is quite a bit better by updating the `hash` with the data from the *entire* `Differences` array, instead of at every loop iteration.
Jonas Jenwald 8 years ago
parent
commit
ddea9a6b04
  1. 18
      src/core/evaluator.js

18
src/core/evaluator.js

@ -2189,11 +2189,19 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { @@ -2189,11 +2189,19 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
hash.update(entry.name);
} else if (isRef(entry)) {
hash.update(entry.toString());
} else if (isArray(entry)) { // 'Differences' entry.
// Ideally we should check the contents of the array, but to avoid
// parsing it here and then again in |extractDataStructures|,
// we only use the array length for now (fixes bug1157493.pdf).
hash.update(entry.length.toString());
} else if (isArray(entry)) {
// 'Differences' array (fixes bug1157493.pdf).
var diffLength = entry.length, diffBuf = new Array(diffLength);
for (var j = 0; j < diffLength; j++) {
var diffEntry = entry[j];
if (isName(diffEntry)) {
diffBuf[j] = diffEntry.name;
} else if (isNum(diffEntry) || isRef(diffEntry)) {
diffBuf[j] = diffEntry.toString();
}
}
hash.update(diffBuf.join());
}
}
}

Loading…
Cancel
Save