mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-27 17:37:22 +02:00
Compare commits
No commits in common. "b070a502c33aa08788e31e8f2afb675df1405374" and "d4d0081ac920fa5fa7ba98eae4fe8b90042375be" have entirely different histories.
b070a502c3
...
d4d0081ac9
@ -1,97 +0,0 @@
|
||||
/* Copyright 2024 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { closePages, FSI, loadAndWait, PDI } from "./test_utils.mjs";
|
||||
|
||||
const FIELDS = [
|
||||
"fileName",
|
||||
"fileSize",
|
||||
"title",
|
||||
"author",
|
||||
"subject",
|
||||
"keywords",
|
||||
"creationDate",
|
||||
"modificationDate",
|
||||
"creator",
|
||||
"producer",
|
||||
"version",
|
||||
"pageCount",
|
||||
"pageSize",
|
||||
"linearized",
|
||||
];
|
||||
|
||||
describe("PDFDocumentProperties", () => {
|
||||
async function getFieldProperties(page) {
|
||||
const promises = [];
|
||||
|
||||
for (const name of FIELDS) {
|
||||
promises.push(
|
||||
page.evaluate(
|
||||
n => [n, document.getElementById(`${n}Field`).textContent],
|
||||
name
|
||||
)
|
||||
);
|
||||
}
|
||||
return Object.fromEntries(await Promise.all(promises));
|
||||
}
|
||||
|
||||
describe("Document with both /Info and /Metadata", () => {
|
||||
let pages;
|
||||
|
||||
beforeEach(async () => {
|
||||
pages = await loadAndWait("basicapi.pdf", ".textLayer .endOfContent");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check that the document properties dialog has the correct information", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.click("#secondaryToolbarToggleButton");
|
||||
await page.waitForSelector("#secondaryToolbar", { hidden: false });
|
||||
|
||||
await page.click("#documentProperties");
|
||||
await page.waitForSelector("#documentPropertiesDialog", {
|
||||
hidden: false,
|
||||
});
|
||||
|
||||
await page.waitForFunction(
|
||||
`document.getElementById("fileSizeField").textContent !== "-"`
|
||||
);
|
||||
const props = await getFieldProperties(page);
|
||||
|
||||
expect(props).toEqual({
|
||||
fileName: "basicapi.pdf",
|
||||
fileSize: `${FSI}103${PDI} KB (${FSI}105,779${PDI} bytes)`,
|
||||
title: "Basic API Test",
|
||||
author: "Brendan Dahl",
|
||||
subject: "-",
|
||||
keywords: "TCPDF",
|
||||
creationDate: "4/10/12, 7:30:26 AM",
|
||||
modificationDate: "4/10/12, 7:30:26 AM",
|
||||
creator: "TCPDF",
|
||||
producer: "TCPDF 5.9.133 (http://www.tcpdf.org)",
|
||||
version: "1.7",
|
||||
pageCount: "3",
|
||||
pageSize: `${FSI}8.27${PDI} × ${FSI}11.69${PDI} ${FSI}in${PDI} (${FSI}A4${PDI}, ${FSI}portrait${PDI})`,
|
||||
linearized: "No",
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { closePages, FSI, loadAndWait, PDI } from "./test_utils.mjs";
|
||||
import { closePages, loadAndWait } from "./test_utils.mjs";
|
||||
|
||||
function fuzzyMatch(a, b, browserName, pixelFuzz = 3) {
|
||||
expect(a)
|
||||
@ -110,6 +110,10 @@ describe("find bar", () => {
|
||||
);
|
||||
const resultElement = await page.waitForSelector("#findResultsCount");
|
||||
const resultText = await resultElement.evaluate(el => el.textContent);
|
||||
/** Unicode bidi isolation characters. */
|
||||
const FSI = "\u2068";
|
||||
const PDI = "\u2069";
|
||||
// Fluent adds these markers to the result text.
|
||||
expect(resultText).toEqual(`${FSI}1${PDI} of ${FSI}1${PDI} match`);
|
||||
const selectedElement = await page.waitForSelector(
|
||||
".highlight.selected"
|
||||
|
||||
@ -31,7 +31,6 @@ async function runTests(results) {
|
||||
"autolinker_spec.mjs",
|
||||
"caret_browsing_spec.mjs",
|
||||
"copy_paste_spec.mjs",
|
||||
"document_properties_spec.mjs",
|
||||
"find_spec.mjs",
|
||||
"freetext_editor_spec.mjs",
|
||||
"highlight_editor_spec.mjs",
|
||||
|
||||
@ -17,12 +17,10 @@ import {
|
||||
awaitPromise,
|
||||
closePages,
|
||||
copy,
|
||||
FSI,
|
||||
getEditorSelector,
|
||||
getRect,
|
||||
loadAndWait,
|
||||
paste,
|
||||
PDI,
|
||||
switchToEditor,
|
||||
waitForPointerUp,
|
||||
waitForTimeout,
|
||||
@ -190,7 +188,7 @@ describe("Signature Editor", () => {
|
||||
|
||||
// Check the aria description.
|
||||
await page.waitForSelector(
|
||||
`${editorSelector}[aria-description="Signature editor: ${FSI}Hello World${PDI}"]`
|
||||
`${editorSelector}[aria-description="Signature editor: \u2068Hello World\u2069"]`
|
||||
);
|
||||
|
||||
// Edit the description.
|
||||
|
||||
@ -882,10 +882,6 @@ async function moveEditor(page, selector, n, pressKey) {
|
||||
}
|
||||
}
|
||||
|
||||
// Unicode bidi isolation characters, Fluent adds these markers to the text.
|
||||
const FSI = "\u2068";
|
||||
const PDI = "\u2069";
|
||||
|
||||
export {
|
||||
applyFunctionToEditor,
|
||||
awaitPromise,
|
||||
@ -898,7 +894,6 @@ export {
|
||||
createPromise,
|
||||
dragAndDrop,
|
||||
firstPageOnTop,
|
||||
FSI,
|
||||
getAnnotationSelector,
|
||||
getAnnotationStorage,
|
||||
getComputedStyleSelector,
|
||||
@ -934,7 +929,6 @@ export {
|
||||
moveEditor,
|
||||
paste,
|
||||
pasteFromClipboard,
|
||||
PDI,
|
||||
scrollIntoView,
|
||||
selectEditor,
|
||||
selectEditors,
|
||||
|
||||
41
web/app.js
41
web/app.js
@ -598,8 +598,7 @@ const PDFViewerApplication = {
|
||||
overlayManager,
|
||||
eventBus,
|
||||
l10n,
|
||||
/* fileNameLookup = */ () => this._docFilename,
|
||||
/* titleLookup = */ () => this._docTitle
|
||||
/* fileNameLookup = */ () => this._docFilename
|
||||
);
|
||||
}
|
||||
|
||||
@ -1004,23 +1003,6 @@ const PDFViewerApplication = {
|
||||
return this._contentDispositionFilename || getPdfFilenameFromUrl(this.url);
|
||||
},
|
||||
|
||||
get _docTitle() {
|
||||
const { documentInfo, metadata } = this;
|
||||
|
||||
const title = metadata?.get("dc:title");
|
||||
if (title) {
|
||||
// Ghostscript can produce invalid 'dc:title' Metadata entries:
|
||||
// - The title may be "Untitled" (fixes bug 1031612).
|
||||
// - The title may contain incorrectly encoded characters, which thus
|
||||
// looks broken, hence we ignore the Metadata entry when it contains
|
||||
// characters from the Specials Unicode block (fixes bug 1605526).
|
||||
if (title !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(title)) {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
return documentInfo.Title;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@ -1639,12 +1621,25 @@ const PDFViewerApplication = {
|
||||
// Provides some basic debug information
|
||||
console.log(
|
||||
`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` +
|
||||
`${(metadata?.get("pdf:producer") || info.Producer || "-").trim()} / ` +
|
||||
`${(metadata?.get("xmp:creatortool") || info.Creator || "-").trim()}` +
|
||||
`] (PDF.js: ${version || "?"} [${build || "?"}])`
|
||||
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
|
||||
`(PDF.js: ${version || "?"} [${build || "?"}])`
|
||||
);
|
||||
const pdfTitle = this._docTitle;
|
||||
let pdfTitle = info.Title;
|
||||
|
||||
const metadataTitle = metadata?.get("dc:title");
|
||||
if (metadataTitle) {
|
||||
// Ghostscript can produce invalid 'dc:title' Metadata entries:
|
||||
// - The title may be "Untitled" (fixes bug 1031612).
|
||||
// - The title may contain incorrectly encoded characters, which thus
|
||||
// looks broken, hence we ignore the Metadata entry when it contains
|
||||
// characters from the Specials Unicode block (fixes bug 1605526).
|
||||
if (
|
||||
metadataTitle !== "Untitled" &&
|
||||
!/[\uFFF0-\uFFFF]/g.test(metadataTitle)
|
||||
) {
|
||||
pdfTitle = metadataTitle;
|
||||
}
|
||||
}
|
||||
if (pdfTitle) {
|
||||
this.setTitle(
|
||||
`${pdfTitle} - ${this._contentDispositionFilename || this._title}`
|
||||
|
||||
@ -67,15 +67,13 @@ class PDFDocumentProperties {
|
||||
overlayManager,
|
||||
eventBus,
|
||||
l10n,
|
||||
fileNameLookup,
|
||||
titleLookup
|
||||
fileNameLookup
|
||||
) {
|
||||
this.dialog = dialog;
|
||||
this.fields = fields;
|
||||
this.overlayManager = overlayManager;
|
||||
this.l10n = l10n;
|
||||
this._fileNameLookup = fileNameLookup;
|
||||
this._titleLookup = titleLookup;
|
||||
|
||||
this.#reset();
|
||||
// Bind the event listener for the Close button.
|
||||
@ -115,7 +113,7 @@ class PDFDocumentProperties {
|
||||
|
||||
// Get the document properties.
|
||||
const [
|
||||
{ info, metadata, /* contentDispositionFilename, */ contentLength },
|
||||
{ info, /* metadata, contentDispositionFilename, */ contentLength },
|
||||
pdfPage,
|
||||
] = await Promise.all([
|
||||
this.pdfDocument.getMetadata(),
|
||||
@ -125,7 +123,6 @@ class PDFDocumentProperties {
|
||||
const [
|
||||
fileName,
|
||||
fileSize,
|
||||
title,
|
||||
creationDate,
|
||||
modificationDate,
|
||||
pageSize,
|
||||
@ -133,9 +130,8 @@ class PDFDocumentProperties {
|
||||
] = await Promise.all([
|
||||
this._fileNameLookup(),
|
||||
this.#parseFileSize(contentLength),
|
||||
this._titleLookup(),
|
||||
this.#parseDate(metadata?.get("xmp:createdate"), info.CreationDate),
|
||||
this.#parseDate(metadata?.get("xmp:modifydate"), info.ModDate),
|
||||
this.#parseDate(info.CreationDate),
|
||||
this.#parseDate(info.ModDate),
|
||||
this.#parsePageSize(getPageSizeInches(pdfPage), pagesRotation),
|
||||
this.#parseLinearization(info.IsLinearized),
|
||||
]);
|
||||
@ -143,14 +139,14 @@ class PDFDocumentProperties {
|
||||
this.#fieldData = Object.freeze({
|
||||
fileName,
|
||||
fileSize,
|
||||
title,
|
||||
author: metadata?.get("dc:creator")?.join("\n") || info.Author,
|
||||
subject: metadata?.get("dc:subject")?.join("\n") || info.Subject,
|
||||
keywords: metadata?.get("pdf:keywords") || info.Keywords,
|
||||
title: info.Title,
|
||||
author: info.Author,
|
||||
subject: info.Subject,
|
||||
keywords: info.Keywords,
|
||||
creationDate,
|
||||
modificationDate,
|
||||
creator: metadata?.get("xmp:creatortool") || info.Creator,
|
||||
producer: metadata?.get("pdf:producer") || info.Producer,
|
||||
creator: info.Creator,
|
||||
producer: info.Producer,
|
||||
version: info.PDFFormatVersion,
|
||||
pageCount: this.pdfDocument.numPages,
|
||||
pageSize,
|
||||
@ -328,9 +324,8 @@ class PDFDocumentProperties {
|
||||
);
|
||||
}
|
||||
|
||||
async #parseDate(metadataDate, infoDate) {
|
||||
const dateObj =
|
||||
Date.parse(metadataDate) || PDFDateString.toDateObject(infoDate);
|
||||
async #parseDate(inputDate) {
|
||||
const dateObj = PDFDateString.toDateObject(inputDate);
|
||||
return dateObj
|
||||
? this.l10n.get("pdfjs-document-properties-date-time-string", {
|
||||
dateObj: dateObj.valueOf(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user