From 05566bd1109337a58463cd31d5e922d54a1ba6c6 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 30 Sep 2026 13:21:37 +0200 Subject: [PATCH] Stop exporting the Font `mimetype` property - All embedded font data, regardless of how it's specified in the PDF, is always converted into OpenType in the worker-thread. This has been the case since "forever" in the PDF.js project, hence the value of `Font.prototype.mimetype` never varies (when actually set). - With the introduction of the CSS Font Loading API, in the font-loading code, the `mimetype` property is no longer used *by default* in the main-thread. - Given that `Font.prototype.mimetype` is either a string or `null`, the way that PR 20197 implemented the serialization/deserialization isn't actually correct since an explicit `null` value is being converted into a `"null"` string. --- src/core/fonts.js | 6 ------ src/display/font_loader.js | 2 +- src/display/obj_bin_transform_display.js | 6 +----- src/shared/obj_bin_transform_utils.js | 2 +- test/unit/obj_bin_transform_spec.js | 4 +--- 5 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/core/fonts.js b/src/core/fonts.js index c90bd608d9d86..17c71e41e3eab 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -96,7 +96,6 @@ const EXPORT_DATA_PROPERTIES = [ "isType3Font", "italic", "loadedName", - "mimetype", "missingFile", "name", "remeasure", @@ -1050,7 +1049,6 @@ class Font { constructor(name, file, properties, evaluatorOptions) { this.name = name; this.psName = null; - this.mimetype = null; this.disableFontFace = evaluatorOptions.disableFontFace; this.fontExtraProperties = evaluatorOptions.fontExtraProperties; @@ -1165,8 +1163,6 @@ class Font { /* falls through */ case "Type1": case "CIDFontType0": - this.mimetype = "font/opentype"; - const cff = subtype === "Type1C" || subtype === "CIDFontType0C" ? new CFFFont(file, properties) @@ -1181,8 +1177,6 @@ class Font { case "OpenType": case "TrueType": case "CIDFontType2": - this.mimetype = "font/opentype"; - // Repair the TrueType file. It is can be damaged in the point of // view of the sanitizer data = this.checkAndRepair(name, file, properties); diff --git a/src/display/font_loader.js b/src/display/font_loader.js index ea0b3f4728fb1..cef67f91f4e40 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -567,7 +567,7 @@ class FontFaceObject { } get mimetype() { - return this.#fontData.mimetype; + return this.missingFile ? null : "font/opentype"; } get name() { diff --git a/src/display/obj_bin_transform_display.js b/src/display/obj_bin_transform_display.js index 6e871a9e901a2..b9c2de87835b6 100644 --- a/src/display/obj_bin_transform_display.js +++ b/src/display/obj_bin_transform_display.js @@ -224,12 +224,8 @@ class FontInfo { return this.#readString(1); } - get mimetype() { - return this.#readString(2); - } - get name() { - return this.#readString(3); + return this.#readString(2); } #getDataOffsets() { diff --git a/src/shared/obj_bin_transform_utils.js b/src/shared/obj_bin_transform_utils.js index cb0b0c786a0c6..6187b17ea1820 100644 --- a/src/shared/obj_bin_transform_utils.js +++ b/src/shared/obj_bin_transform_utils.js @@ -39,7 +39,7 @@ class FONT_INFO { static numbers = ["ascent", "descent"]; - static strings = ["fallbackName", "loadedName", "mimetype", "name"]; + static strings = ["fallbackName", "loadedName", "name"]; static OFFSET_NUMBERS = Math.ceil((this.bools.length * 2) / 8); diff --git a/test/unit/obj_bin_transform_spec.js b/test/unit/obj_bin_transform_spec.js index ee2f347d5fe84..8207a720c74f8 100644 --- a/test/unit/obj_bin_transform_spec.js +++ b/test/unit/obj_bin_transform_spec.js @@ -70,7 +70,6 @@ describe("obj_bin_transform", function () { fontMatrix: [1, 1, 1, 1, 1, 1], fallbackName: "string", loadedName: "string", - mimetype: "string", name: "string", data: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), uselessProp: "something", @@ -124,7 +123,7 @@ describe("obj_bin_transform", function () { describe("FontInfo", function () { it("must roundtrip correctly for FontInfo", function () { - let sizeEstimate = 77; // fixed offset until the strings + let sizeEstimate = 67; // fixed offset until the strings const { encoder } = InfoUtils; sizeEstimate += 4 + 4 * (4 + encoder.encode("string").length); sizeEstimate += 4 + 4; // cssFontInfo and systemFontInfo @@ -148,7 +147,6 @@ describe("obj_bin_transform", function () { expect(deserialized.fontMatrix).toEqual([1, 1, 1, 1, 1, 1]); expect(deserialized.fallbackName).toEqual("string"); expect(deserialized.loadedName).toEqual("string"); - expect(deserialized.mimetype).toEqual("string"); expect(deserialized.name).toEqual("string"); expect(Array.from(deserialized.data)).toEqual([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,