Merge pull request #11515 from Snuffleupagus/cache-fallback-font
Cache the fallback font dictionary on the `PartialEvaluator` (PR 11218 follow-up)
This commit is contained in:
commit
cbbda9d883
@ -33,7 +33,14 @@ import {
|
|||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import { Catalog, ObjectLoader, XRef } from "./obj.js";
|
import { Catalog, ObjectLoader, XRef } from "./obj.js";
|
||||||
import { Dict, isDict, isName, isStream, Ref } from "./primitives.js";
|
import {
|
||||||
|
clearPrimitiveCaches,
|
||||||
|
Dict,
|
||||||
|
isDict,
|
||||||
|
isName,
|
||||||
|
isStream,
|
||||||
|
Ref,
|
||||||
|
} from "./primitives.js";
|
||||||
import {
|
import {
|
||||||
getInheritableProperty,
|
getInheritableProperty,
|
||||||
MissingDataException,
|
MissingDataException,
|
||||||
@ -815,8 +822,8 @@ class PDFDocument {
|
|||||||
return this.catalog.fontFallback(id, handler);
|
return this.catalog.fontFallback(id, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
async cleanup() {
|
||||||
return this.catalog.cleanup();
|
return this.catalog ? this.catalog.cleanup() : clearPrimitiveCaches();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -935,11 +935,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
// Falling back to a default font to avoid completely broken rendering,
|
// Falling back to a default font to avoid completely broken rendering,
|
||||||
// but note that there're no guarantees that things will look "correct".
|
// but note that there're no guarantees that things will look "correct".
|
||||||
fontRef = new Dict();
|
fontRef = PartialEvaluator.getFallbackFontDict();
|
||||||
fontRef.set("BaseFont", Name.get("PDFJS-FallbackFont"));
|
|
||||||
fontRef.set("Type", Name.get("FallbackType"));
|
|
||||||
fontRef.set("Subtype", Name.get("FallbackType"));
|
|
||||||
fontRef.set("Encoding", Name.get("WinAnsiEncoding"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.fontCache.has(fontRef)) {
|
if (this.fontCache.has(fontRef)) {
|
||||||
@ -3132,6 +3128,21 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: Change this to a `static` getter, using shadowing, once
|
||||||
|
// `PartialEvaluator` is converted to a proper class.
|
||||||
|
PartialEvaluator.getFallbackFontDict = function() {
|
||||||
|
if (this._fallbackFontDict) {
|
||||||
|
return this._fallbackFontDict;
|
||||||
|
}
|
||||||
|
const dict = new Dict();
|
||||||
|
dict.set("BaseFont", Name.get("PDFJS-FallbackFont"));
|
||||||
|
dict.set("Type", Name.get("FallbackType"));
|
||||||
|
dict.set("Subtype", Name.get("FallbackType"));
|
||||||
|
dict.set("Encoding", Name.get("WinAnsiEncoding"));
|
||||||
|
|
||||||
|
return (this._fallbackFontDict = dict);
|
||||||
|
};
|
||||||
|
|
||||||
return PartialEvaluator;
|
return PartialEvaluator;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -593,16 +593,22 @@ var WorkerMessageHandler = {
|
|||||||
|
|
||||||
handler.on("Terminate", function wphTerminate(data) {
|
handler.on("Terminate", function wphTerminate(data) {
|
||||||
terminated = true;
|
terminated = true;
|
||||||
|
|
||||||
|
const waitOn = [];
|
||||||
if (pdfManager) {
|
if (pdfManager) {
|
||||||
pdfManager.terminate(new AbortException("Worker was terminated."));
|
pdfManager.terminate(new AbortException("Worker was terminated."));
|
||||||
|
|
||||||
|
const cleanupPromise = pdfManager.cleanup();
|
||||||
|
waitOn.push(cleanupPromise);
|
||||||
|
|
||||||
pdfManager = null;
|
pdfManager = null;
|
||||||
|
} else {
|
||||||
|
clearPrimitiveCaches();
|
||||||
}
|
}
|
||||||
if (cancelXHRs) {
|
if (cancelXHRs) {
|
||||||
cancelXHRs(new AbortException("Worker was terminated."));
|
cancelXHRs(new AbortException("Worker was terminated."));
|
||||||
}
|
}
|
||||||
clearPrimitiveCaches();
|
|
||||||
|
|
||||||
var waitOn = [];
|
|
||||||
WorkerTasks.forEach(function(task) {
|
WorkerTasks.forEach(function(task) {
|
||||||
waitOn.push(task.finished);
|
waitOn.push(task.finished);
|
||||||
task.terminate();
|
task.terminate();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user