From 0c1fb4e740ba605138d743c9e437184b62edf727 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 1 Jan 2023 16:33:55 +0100 Subject: [PATCH] [api-minor] Remove the `PDFDocumentProxy.stats` getter (PR 15758 follow-up) This was deprecated in PR 15758 and given that it's quite unlikely that any third-party users are relying on this functionality, since it was only ever added to support telemetry reporting in the Firefox PDF Viewer, it should hopefully be fine to remove this fairly quickly. These changes reduce the bundle size of the Firefox PDF Viewer by 4.5 kB in total. --- src/core/core_utils.js | 52 ----------------------------------------- src/core/evaluator.js | 19 +-------------- src/core/fonts.js | 10 +------- src/core/fonts_utils.js | 29 +---------------------- src/core/parser.js | 11 --------- src/core/xref.js | 4 +--- src/display/api.js | 39 ------------------------------- src/shared/util.js | 30 ------------------------ test/unit/api_spec.js | 25 -------------------- test/unit/test_utils.js | 2 -- 10 files changed, 4 insertions(+), 217 deletions(-) diff --git a/src/core/core_utils.js b/src/core/core_utils.js index a4c23b7c2..af1d01246 100644 --- a/src/core/core_utils.js +++ b/src/core/core_utils.js @@ -17,9 +17,7 @@ import { AnnotationEditorPrefix, assert, BaseException, - FontType, objectSize, - StreamType, stringToPDFString, warn, } from "../shared/util.js"; @@ -82,55 +80,6 @@ class XRefParseException extends BaseException { } } -class DocStats { - constructor(handler) { - this._handler = handler; - - this._streamTypes = new Set(); - this._fontTypes = new Set(); - } - - _send() { - const streamTypes = Object.create(null), - fontTypes = Object.create(null); - for (const type of this._streamTypes) { - streamTypes[type] = true; - } - for (const type of this._fontTypes) { - fontTypes[type] = true; - } - this._handler.send("DocStats", { streamTypes, fontTypes }); - } - - addStreamType(type) { - if ( - typeof PDFJSDev === "undefined" || - PDFJSDev.test("!PRODUCTION || TESTING") - ) { - assert(StreamType[type] === type, 'addStreamType: Invalid "type" value.'); - } - if (this._streamTypes.has(type)) { - return; - } - this._streamTypes.add(type); - this._send(); - } - - addFontType(type) { - if ( - typeof PDFJSDev === "undefined" || - PDFJSDev.test("!PRODUCTION || TESTING") - ) { - assert(FontType[type] === type, 'addFontType: Invalid "type" value.'); - } - if (this._fontTypes.has(type)) { - return; - } - this._fontTypes.add(type); - this._send(); - } -} - /** * Get the value of an inheritable property. * @@ -631,7 +580,6 @@ function getRotationMatrix(rotation, width, height) { export { collectActions, - DocStats, encodeToXmlString, escapePDFName, escapeString, diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 4b540ac07..4c3aad6d1 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -35,7 +35,6 @@ import { import { CMapFactory, IdentityCMap } from "./cmap.js"; import { Cmd, Dict, EOF, isName, Name, Ref, RefSet } from "./primitives.js"; import { ErrorFont, Font } from "./fonts.js"; -import { FontFlags, getFontType } from "./fonts_utils.js"; import { getEncoding, MacRomanEncoding, @@ -67,6 +66,7 @@ import { BaseStream } from "./base_stream.js"; import { bidi } from "./bidi.js"; import { ColorSpace } from "./colorspace.js"; import { DecodeStream } from "./decode_stream.js"; +import { FontFlags } from "./fonts_utils.js"; import { getGlyphsUnicode } from "./glyphlist.js"; import { getLookupTableFactory } from "./core_utils.js"; import { getMetrics } from "./metrics.js"; @@ -1302,10 +1302,6 @@ class PartialEvaluator { this.translateFont(preEvaluatedFont) .then(translatedFont => { - if (translatedFont.fontType !== undefined) { - xref.stats.addFontType(translatedFont.fontType); - } - fontCapability.resolve( new TranslatedFont({ loadedName: font.loadedName, @@ -1323,19 +1319,6 @@ class PartialEvaluator { }); warn(`loadFont - translateFont failed: "${reason}".`); - try { - // error, but it's still nice to have font type reported - const fontFile3 = descriptor && descriptor.get("FontFile3"); - const subtype = fontFile3 && fontFile3.get("Subtype"); - const fontType = getFontType( - preEvaluatedFont.type, - subtype && subtype.name - ); - if (fontType !== undefined) { - xref.stats.addFontType(fontType); - } - } catch (ex) {} - fontCapability.resolve( new TranslatedFont({ loadedName: font.loadedName, diff --git a/src/core/fonts.js b/src/core/fonts.js index 8d02b5d0f..4d09e7234 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -17,7 +17,6 @@ import { assert, bytesToString, FONT_IDENTITY_MATRIX, - FontType, FormatError, info, shadow, @@ -27,7 +26,6 @@ import { import { CFFCompiler, CFFParser } from "./cff_parser.js"; import { FontFlags, - getFontType, MacStandardGlyphOrdering, normalizeFontName, recoverGlyphName, @@ -92,7 +90,6 @@ const EXPORT_DATA_PROPERTIES = [ "descent", "fallbackName", "fontMatrix", - "fontType", "isInvalidPDFjsFont", "isType3Font", "italic", @@ -986,7 +983,6 @@ class Font { this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode]; } - this.fontType = FontType.TYPE3; return; } @@ -1066,7 +1062,6 @@ class Font { amendFallbackToUnicode(properties); this.data = data; - this.fontType = getFontType(type, subtype, properties.isStandardFont); // Transfer some properties again that could change during font conversion this.fontMatrix = properties.fontMatrix; @@ -1102,9 +1097,7 @@ class Font { this.missingFile = true; // The file data is not specified. Trying to fix the font name // to be used with the canvas.font. - const name = this.name; - const type = this.type; - const subtype = this.subtype; + const { name, type } = this; let fontName = normalizeFontName(name); const stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap(); @@ -1252,7 +1245,6 @@ class Font { amendFallbackToUnicode(properties); this.loadedName = fontName.split("-")[0]; - this.fontType = getFontType(type, subtype, properties.isStandardFont); } checkAndRepair(name, font, properties) { diff --git a/src/core/fonts_utils.js b/src/core/fonts_utils.js index b67dfe01d..6287786f3 100644 --- a/src/core/fonts_utils.js +++ b/src/core/fonts_utils.js @@ -13,10 +13,10 @@ * limitations under the License. */ -import { FontType, info } from "../shared/util.js"; import { getEncoding, StandardEncoding } from "./encodings.js"; import { getGlyphsUnicode } from "./glyphlist.js"; import { getUnicodeForGlyph } from "./unicode.js"; +import { info } from "../shared/util.js"; // Accented characters have issues on Windows and Linux. When this flag is // enabled glyphs that use seac and seac style endchar operators are truncated @@ -78,32 +78,6 @@ const MacStandardGlyphOrdering = [ "threequarters", "franc", "Gbreve", "gbreve", "Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", "ccaron", "dcroat"]; -function getFontType(type, subtype, isStandardFont = false) { - switch (type) { - case "Type1": - if (isStandardFont) { - return FontType.TYPE1STANDARD; - } - return subtype === "Type1C" ? FontType.TYPE1C : FontType.TYPE1; - case "CIDFontType0": - return subtype === "CIDFontType0C" - ? FontType.CIDFONTTYPE0C - : FontType.CIDFONTTYPE0; - case "OpenType": - return FontType.OPENTYPE; - case "TrueType": - return FontType.TRUETYPE; - case "CIDFontType2": - return FontType.CIDFONTTYPE2; - case "MMType1": - return FontType.MMTYPE1; - case "Type0": - return FontType.TYPE0; - default: - return FontType.UNKNOWN; - } -} - // Some bad PDF generators, e.g. Scribus PDF, include glyph names // in a 'uniXXXX' format -- attempting to recover proper ones. function recoverGlyphName(name, glyphsUnicodeMap) { @@ -212,7 +186,6 @@ function normalizeFontName(name) { export { FontFlags, - getFontType, MacStandardGlyphOrdering, normalizeFontName, recoverGlyphName, diff --git a/src/core/parser.js b/src/core/parser.js index 118c42633..0b046adfc 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -18,7 +18,6 @@ import { bytesToString, FormatError, info, - StreamType, warn, } from "../shared/util.js"; import { Cmd, Dict, EOF, isCmd, Name, Ref } from "./primitives.js"; @@ -732,13 +731,11 @@ class Parser { warn(`Empty "${name}" stream.`); return new NullStream(); } - const xrefStats = this.xref.stats; try { switch (name) { case "Fl": case "FlateDecode": - xrefStats.addStreamType(StreamType.FLATE); if (params) { return new PredictorStream( new FlateStream(stream, maybeLength), @@ -749,7 +746,6 @@ class Parser { return new FlateStream(stream, maybeLength); case "LZW": case "LZWDecode": - xrefStats.addStreamType(StreamType.LZW); let earlyChange = 1; if (params) { if (params.has("EarlyChange")) { @@ -764,30 +760,23 @@ class Parser { return new LZWStream(stream, maybeLength, earlyChange); case "DCT": case "DCTDecode": - xrefStats.addStreamType(StreamType.DCT); return new JpegStream(stream, maybeLength, params); case "JPX": case "JPXDecode": - xrefStats.addStreamType(StreamType.JPX); return new JpxStream(stream, maybeLength, params); case "A85": case "ASCII85Decode": - xrefStats.addStreamType(StreamType.A85); return new Ascii85Stream(stream, maybeLength); case "AHx": case "ASCIIHexDecode": - xrefStats.addStreamType(StreamType.AHX); return new AsciiHexStream(stream, maybeLength); case "CCF": case "CCITTFaxDecode": - xrefStats.addStreamType(StreamType.CCF); return new CCITTFaxStream(stream, maybeLength, params); case "RL": case "RunLengthDecode": - xrefStats.addStreamType(StreamType.RLX); return new RunLengthStream(stream, maybeLength); case "JBIG2Decode": - xrefStats.addStreamType(StreamType.JBIG); return new Jbig2Stream(stream, maybeLength, params); } warn(`Filter "${name}" is not supported.`); diff --git a/src/core/xref.js b/src/core/xref.js index a15cf4d09..c55715463 100644 --- a/src/core/xref.js +++ b/src/core/xref.js @@ -22,14 +22,13 @@ import { warn, } from "../shared/util.js"; import { CIRCULAR_REF, Cmd, Dict, isCmd, Ref, RefSet } from "./primitives.js"; +import { Lexer, Parser } from "./parser.js"; import { - DocStats, MissingDataException, ParserEOFException, XRefEntryException, XRefParseException, } from "./core_utils.js"; -import { Lexer, Parser } from "./parser.js"; import { BaseStream } from "./base_stream.js"; import { CipherTransformFactory } from "./crypto.js"; @@ -41,7 +40,6 @@ class XRef { this.xrefstms = Object.create(null); this._cacheMap = new Map(); // Prepare the XRef cache. this._pendingRefs = new RefSet(); - this.stats = new DocStats(pdfManager.msgHandler); this._newPersistentRefNum = null; this._newTemporaryRefNum = null; } diff --git a/src/display/api.js b/src/display/api.js index 2dca8fb07..de9ed3f5c 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -758,27 +758,6 @@ class PDFDocumentProxy { return this._pdfInfo.fingerprints; } - /** - * @typedef {Object} PDFDocumentStats - * @property {Object} streamTypes - Used stream types in the - * document (an item is set to true if specific stream ID was used in the - * document). - * @property {Object} fontTypes - Used font types in the - * document (an item is set to true if specific font ID was used in the - * document). - */ - - /** - * @type {PDFDocumentStats | null} The current statistics about document - * structures, or `null` when no statistics exists. - */ - get stats() { - deprecated( - "The PDFDocumentProxy stats property will be removed in the future." - ); - return this._transport.stats; - } - /** * @type {boolean} True if only XFA form. */ @@ -2296,8 +2275,6 @@ class PDFWorker { * @ignore */ class WorkerTransport { - #docStats = null; - #pageCache = new Map(); #pagePromises = new Map(); @@ -2341,10 +2318,6 @@ class WorkerTransport { return shadow(this, "annotationStorage", new AnnotationStorage()); } - get stats() { - return this.#docStats; - } - getRenderingIntent( intent, annotationMode = AnnotationMode.ENABLE, @@ -2775,18 +2748,6 @@ class WorkerTransport { }); }); - messageHandler.on("DocStats", data => { - if (this.destroyed) { - return; // Ignore any pending requests if the worker was terminated. - } - // Ensure that a `PDFDocumentProxy.stats` call-site cannot accidentally - // modify this internal data. - this.#docStats = Object.freeze({ - streamTypes: Object.freeze(data.streamTypes), - fontTypes: Object.freeze(data.fontTypes), - }); - }); - messageHandler.on( "UnsupportedFeature", this._onUnsupportedFeature.bind(this) diff --git a/src/shared/util.js b/src/shared/util.js index c45ce201f..d898582db 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -236,34 +236,6 @@ const PageActionEventType = { C: "PageClose", }; -const StreamType = { - UNKNOWN: "UNKNOWN", - FLATE: "FLATE", - LZW: "LZW", - DCT: "DCT", - JPX: "JPX", - JBIG: "JBIG", - A85: "A85", - AHX: "AHX", - CCF: "CCF", - RLX: "RLX", // PDF short name is 'RL', but telemetry requires three chars. -}; - -const FontType = { - UNKNOWN: "UNKNOWN", - TYPE1: "TYPE1", - TYPE1STANDARD: "TYPE1STANDARD", - TYPE1C: "TYPE1C", - CIDFONTTYPE0: "CIDFONTTYPE0", - CIDFONTTYPE0C: "CIDFONTTYPE0C", - TRUETYPE: "TRUETYPE", - CIDFONTTYPE2: "CIDFONTTYPE2", - TYPE3: "TYPE3", - OPENTYPE: "OPENTYPE", - TYPE0: "TYPE0", - MMTYPE1: "MMTYPE1", -}; - const VerbosityLevel = { ERRORS: 0, WARNINGS: 1, @@ -1152,7 +1124,6 @@ export { DocumentActionEventType, FeatureTest, FONT_IDENTITY_MATRIX, - FontType, FormatError, getModificationDate, getVerbosityLevel, @@ -1175,7 +1146,6 @@ export { RenderingIntentFlag, setVerbosityLevel, shadow, - StreamType, string32, stringToBytes, stringToPDFString, diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 4e84f5f76..933cd6130 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -17,7 +17,6 @@ import { AnnotationMode, AnnotationType, createPromiseCapability, - FontType, ImageKind, InvalidPDFException, MissingPDFException, @@ -25,7 +24,6 @@ import { PasswordException, PasswordResponses, PermissionFlag, - StreamType, UnknownErrorException, } from "../../src/shared/util.js"; import { @@ -1846,11 +1844,6 @@ describe("api", function () { expect(downloadInfo).toEqual({ length: basicApiFileLength }); }); - it("gets document stats", async function () { - const stats = pdfDocument.stats; - expect(stats).toEqual(null); - }); - it("cleans up document resources", async function () { await pdfDocument.cleanup(); @@ -2761,24 +2754,6 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`) await loadingTask.destroy(); }); - it("gets document stats after parsing page", async function () { - await page.getOperatorList(); - const stats = pdfDocument.stats; - - const expectedStreamTypes = { - [StreamType.FLATE]: true, - }; - const expectedFontTypes = { - [FontType.TYPE1STANDARD]: true, - [FontType.CIDFONTTYPE2]: true, - }; - - expect(stats).toEqual({ - streamTypes: expectedStreamTypes, - fontTypes: expectedFontTypes, - }); - }); - it("gets page stats after parsing page, without `pdfBug` set", async function () { await page.getOperatorList(); expect(page.stats).toEqual(null); diff --git a/test/unit/test_utils.js b/test/unit/test_utils.js index 0987ed32a..846c2b6c8 100644 --- a/test/unit/test_utils.js +++ b/test/unit/test_utils.js @@ -16,7 +16,6 @@ import { NullStream, StringStream } from "../../src/core/stream.js"; import { Page, PDFDocument } from "../../src/core/document.js"; import { assert } from "../../src/shared/util.js"; -import { DocStats } from "../../src/core/core_utils.js"; import { isNodeJS } from "../../src/shared/is_node.js"; import { Ref } from "../../src/core/primitives.js"; @@ -77,7 +76,6 @@ function buildGetDocumentParams(filename, options) { class XRefMock { constructor(array) { this._map = Object.create(null); - this.stats = new DocStats({ send: () => {} }); this._newTemporaryRefNum = null; this._newPersistentRefNum = null; this.stream = new NullStream();