Re-factor how the viewer title is determined, based on the Info/Metadata data

With these changes we'll always set the `pdfTitle` to the `Info` dictionary entry *first* (assuming it exists and isn't empty), before attempting to override it with the `Metadata` stream entry (assuming it exists, is non-empty *and* valid).

There should be no functional changes with this patch, but it will simplify the following patch somewhat.
This commit is contained in:
Jonas Jenwald 2019-12-21 17:43:53 +01:00
parent 6316b2a195
commit eeaea85294

View File

@ -1117,16 +1117,18 @@ let PDFViewerApplication = {
(AppOptions.get('enableWebGL') ? ' [WebGL]' : '') + ')');
let pdfTitle;
if (metadata && metadata.has('dc:title')) {
let title = metadata.get('dc:title');
// Ghostscript sometimes return 'Untitled', sets the title to 'Untitled'
if (title !== 'Untitled') {
pdfTitle = title;
}
}
if (!pdfTitle && info && info['Title']) {
pdfTitle = info['Title'];
const infoTitle = info && info['Title'];
if (infoTitle) {
pdfTitle = infoTitle;
}
const metadataTitle = metadata && metadata.get('dc:title');
if (metadataTitle) {
// Ghostscript can produce invalid 'dc:title' Metadata entries:
// - The title may be "Untitled" (fixes bug 1031612).
if (metadataTitle !== 'Untitled') {
pdfTitle = metadataTitle;
}
}
if (pdfTitle) {