Revert "[api-minor] Allow loading pdf fonts into another document."

This commit is contained in:
Jonas Jenwald 2020-08-01 12:52:39 +02:00 committed by GitHub
parent 173b92a873
commit 05baa4c89f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 158 deletions

View file

@ -25,17 +25,12 @@ import {
} from "../shared/util.js";
class BaseFontLoader {
constructor({
docId,
onUnsupportedFeature,
ownerDocument = globalThis.document,
}) {
constructor({ docId, onUnsupportedFeature }) {
if (this.constructor === BaseFontLoader) {
unreachable("Cannot initialize BaseFontLoader.");
}
this.docId = docId;
this._onUnsupportedFeature = onUnsupportedFeature;
this._document = ownerDocument;
this.nativeFontFaces = [];
this.styleElement = null;
@ -43,15 +38,15 @@ class BaseFontLoader {
addNativeFontFace(nativeFontFace) {
this.nativeFontFaces.push(nativeFontFace);
this._document.fonts.add(nativeFontFace);
document.fonts.add(nativeFontFace);
}
insertRule(rule) {
let styleElement = this.styleElement;
if (!styleElement) {
styleElement = this.styleElement = this._document.createElement("style");
styleElement = this.styleElement = document.createElement("style");
styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
this._document.documentElement
document.documentElement
.getElementsByTagName("head")[0]
.appendChild(styleElement);
}
@ -61,8 +56,8 @@ class BaseFontLoader {
}
clear() {
this.nativeFontFaces.forEach(nativeFontFace => {
this._document.fonts.delete(nativeFontFace);
this.nativeFontFaces.forEach(function (nativeFontFace) {
document.fonts.delete(nativeFontFace);
});
this.nativeFontFaces.length = 0;
@ -121,8 +116,7 @@ class BaseFontLoader {
}
get isFontLoadingAPISupported() {
const supported =
typeof this._document !== "undefined" && !!this._document.fonts;
const supported = typeof document !== "undefined" && !!document.fonts;
return shadow(this, "isFontLoadingAPISupported", supported);
}
@ -152,8 +146,8 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
// PDFJSDev.test('CHROME || GENERIC')
FontLoader = class GenericFontLoader extends BaseFontLoader {
constructor(params) {
super(params);
constructor(docId) {
super(docId);
this.loadingContext = {
requests: [],
nextRequestId: 0,
@ -260,7 +254,7 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
let i, ii;
// The temporary canvas is used to determine if fonts are loaded.
const canvas = this._document.createElement("canvas");
const canvas = document.createElement("canvas");
canvas.width = 1;
canvas.height = 1;
const ctx = canvas.getContext("2d");
@ -322,22 +316,22 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
}
names.push(loadTestFontId);
const div = this._document.createElement("div");
const div = document.createElement("div");
div.style.visibility = "hidden";
div.style.width = div.style.height = "10px";
div.style.position = "absolute";
div.style.top = div.style.left = "0px";
for (i = 0, ii = names.length; i < ii; ++i) {
const span = this._document.createElement("span");
const span = document.createElement("span");
span.textContent = "Hi";
span.style.fontFamily = names[i];
div.appendChild(span);
}
this._document.body.appendChild(div);
document.body.appendChild(div);
isFontReady(loadTestFontId, () => {
this._document.body.removeChild(div);
isFontReady(loadTestFontId, function () {
document.body.removeChild(div);
request.complete();
});
/** Hack end */