Move the string32 helper to the src/display/font_loader.js file

After the previous patches the `string32` helper function is now only used in the `FontLoader.prototype._prepareFontLoadEvent` method, which is stubbed out in the Firefox PDF Viewer, hence move it there instead to avoid bundling dead code.
This commit is contained in:
Jonas Jenwald 2026-04-14 17:29:29 +02:00
parent cb935c35d3
commit b2cc9ae6d5
3 changed files with 8 additions and 26 deletions

View File

@ -18,7 +18,6 @@ import {
FeatureTest, FeatureTest,
isNodeJS, isNodeJS,
shadow, shadow,
string32,
unreachable, unreachable,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
@ -270,6 +269,14 @@ class FontLoader {
(data.charCodeAt(offset + 3) & 0xff) (data.charCodeAt(offset + 3) & 0xff)
); );
} }
function string32(value) {
return String.fromCharCode(
(value >> 24) & 0xff,
(value >> 16) & 0xff,
(value >> 8) & 0xff,
value & 0xff
);
}
function spliceString(s, offset, remove, insert) { function spliceString(s, offset, remove, insert) {
const chunk1 = s.substring(0, offset); const chunk1 = s.substring(0, offset);
const chunk2 = s.substring(offset + remove); const chunk2 = s.substring(offset + remove);

View File

@ -596,21 +596,6 @@ function stringToBytes(str) {
return bytes; return bytes;
} }
function string32(value) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
assert(
typeof value === "number" && Math.abs(value) < 2 ** 32,
`string32: Unexpected input "${value}".`
);
}
return String.fromCharCode(
(value >> 24) & 0xff,
(value >> 16) & 0xff,
(value >> 8) & 0xff,
value & 0xff
);
}
function objectSize(obj) { function objectSize(obj) {
return Object.keys(obj).length; return Object.keys(obj).length;
} }
@ -1347,7 +1332,6 @@ export {
ResponseException, ResponseException,
setVerbosityLevel, setVerbosityLevel,
shadow, shadow,
string32,
stringToBytes, stringToBytes,
stringToPDFString, stringToPDFString,
stringToUTF8String, stringToUTF8String,

View File

@ -19,7 +19,6 @@ import {
createValidAbsoluteUrl, createValidAbsoluteUrl,
getModificationDate, getModificationDate,
getUuid, getUuid,
string32,
stringToBytes, stringToBytes,
stringToPDFString, stringToPDFString,
} from "../../src/shared/util.js"; } from "../../src/shared/util.js";
@ -72,14 +71,6 @@ describe("util", function () {
}); });
}); });
describe("string32", function () {
it("converts unsigned 32-bit integers to strings", function () {
expect(string32(0x74727565)).toEqual("true");
expect(string32(0x74797031)).toEqual("typ1");
expect(string32(0x4f54544f)).toEqual("OTTO");
});
});
describe("stringToBytes", function () { describe("stringToBytes", function () {
it("handles non-string arguments", function () { it("handles non-string arguments", function () {
expect(function () { expect(function () {