Merge pull request #15534 from Snuffleupagus/FontLoader-cleanup-3
[api-minor] Stop setting an `id` on the styleElement used with CSS font-loading
This commit is contained in:
commit
4e58dabb32
@ -2281,7 +2281,6 @@ class WorkerTransport {
|
|||||||
this.loadingTask = loadingTask;
|
this.loadingTask = loadingTask;
|
||||||
this.commonObjs = new PDFObjects();
|
this.commonObjs = new PDFObjects();
|
||||||
this.fontLoader = new FontLoader({
|
this.fontLoader = new FontLoader({
|
||||||
docId: loadingTask.docId,
|
|
||||||
onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
|
onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
|
||||||
ownerDocument: params.ownerDocument,
|
ownerDocument: params.ownerDocument,
|
||||||
styleElement: params.styleElement,
|
styleElement: params.styleElement,
|
||||||
|
@ -25,12 +25,10 @@ import {
|
|||||||
|
|
||||||
class FontLoader {
|
class FontLoader {
|
||||||
constructor({
|
constructor({
|
||||||
docId,
|
|
||||||
onUnsupportedFeature,
|
onUnsupportedFeature,
|
||||||
ownerDocument = globalThis.document,
|
ownerDocument = globalThis.document,
|
||||||
styleElement = null, // For testing only.
|
styleElement = null, // For testing only.
|
||||||
}) {
|
}) {
|
||||||
this.docId = docId;
|
|
||||||
this._onUnsupportedFeature = onUnsupportedFeature;
|
this._onUnsupportedFeature = onUnsupportedFeature;
|
||||||
this._document = ownerDocument;
|
this._document = ownerDocument;
|
||||||
|
|
||||||
@ -52,15 +50,13 @@ class FontLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
insertRule(rule) {
|
insertRule(rule) {
|
||||||
let styleElement = this.styleElement;
|
if (!this.styleElement) {
|
||||||
if (!styleElement) {
|
this.styleElement = this._document.createElement("style");
|
||||||
styleElement = this.styleElement = this._document.createElement("style");
|
|
||||||
styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
|
|
||||||
this._document.documentElement
|
this._document.documentElement
|
||||||
.getElementsByTagName("head")[0]
|
.getElementsByTagName("head")[0]
|
||||||
.append(styleElement);
|
.append(this.styleElement);
|
||||||
}
|
}
|
||||||
const styleSheet = styleElement.sheet;
|
const styleSheet = this.styleElement.sheet;
|
||||||
styleSheet.insertRule(rule, styleSheet.cssRules.length);
|
styleSheet.insertRule(rule, styleSheet.cssRules.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ describe("custom ownerDocument", function () {
|
|||||||
expect(style).toBeFalsy();
|
expect(style).toBeFalsy();
|
||||||
expect(ownerDocument.fonts.size).toBeGreaterThanOrEqual(1);
|
expect(ownerDocument.fonts.size).toBeGreaterThanOrEqual(1);
|
||||||
expect(Array.from(ownerDocument.fonts).find(checkFont)).toBeTruthy();
|
expect(Array.from(ownerDocument.fonts).find(checkFont)).toBeTruthy();
|
||||||
await doc.destroy();
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
CanvasFactory.destroy(canvasAndCtx);
|
||||||
expect(ownerDocument.fonts.size).toBe(0);
|
expect(ownerDocument.fonts.size).toBe(0);
|
||||||
@ -204,7 +204,7 @@ describe("custom ownerDocument", function () {
|
|||||||
const style = elements.find(element => element.tagName === "style");
|
const style = elements.find(element => element.tagName === "style");
|
||||||
expect(style.sheet.cssRules.length).toBeGreaterThanOrEqual(1);
|
expect(style.sheet.cssRules.length).toBeGreaterThanOrEqual(1);
|
||||||
expect(style.sheet.cssRules.find(checkFontFaceRule)).toBeTruthy();
|
expect(style.sheet.cssRules.find(checkFontFaceRule)).toBeTruthy();
|
||||||
await doc.destroy();
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
CanvasFactory.destroy(canvasAndCtx);
|
CanvasFactory.destroy(canvasAndCtx);
|
||||||
expect(style.remove.called).toBe(true);
|
expect(style.remove.called).toBe(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user