Merge pull request #8673 from Snuffleupagus/api-pageMode
[api-minor] Add support for PageMode in the API and viewer (issue 8657)
This commit is contained in:
commit
af71ea7a7d
@ -102,6 +102,10 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
"disablePageMode": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
"disableTelemetry": {
|
"disableTelemetry": {
|
||||||
"title": "Disable telemetry",
|
"title": "Disable telemetry",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
@ -329,6 +329,24 @@ var Catalog = (function CatalogClosure() {
|
|||||||
return pageLabels;
|
return pageLabels;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get pageMode() {
|
||||||
|
let obj = this.catDict.get('PageMode');
|
||||||
|
let pageMode = 'UseNone'; // Default value.
|
||||||
|
|
||||||
|
if (isName(obj)) {
|
||||||
|
switch (obj.name) {
|
||||||
|
case 'UseNone':
|
||||||
|
case 'UseOutlines':
|
||||||
|
case 'UseThumbs':
|
||||||
|
case 'FullScreen':
|
||||||
|
case 'UseOC':
|
||||||
|
case 'UseAttachments':
|
||||||
|
pageMode = obj.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return shadow(this, 'pageMode', pageMode);
|
||||||
|
},
|
||||||
|
|
||||||
get attachments() {
|
get attachments() {
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
var attachments = null, nameTreeRef;
|
var attachments = null, nameTreeRef;
|
||||||
|
@ -772,6 +772,10 @@ var WorkerMessageHandler = {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
handler.on('GetPageMode', function wphSetupGetPageMode(data) {
|
||||||
|
return pdfManager.ensureCatalog('pageMode');
|
||||||
|
});
|
||||||
|
|
||||||
handler.on('GetAttachments',
|
handler.on('GetAttachments',
|
||||||
function wphSetupGetAttachments(data) {
|
function wphSetupGetAttachments(data) {
|
||||||
return pdfManager.ensureCatalog('attachments');
|
return pdfManager.ensureCatalog('attachments');
|
||||||
|
@ -568,6 +568,13 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||||||
getPageLabels: function PDFDocumentProxy_getPageLabels() {
|
getPageLabels: function PDFDocumentProxy_getPageLabels() {
|
||||||
return this.transport.getPageLabels();
|
return this.transport.getPageLabels();
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* @return {Promise} A promise that is resolved with a {string} containing
|
||||||
|
* the PageMode name.
|
||||||
|
*/
|
||||||
|
getPageMode() {
|
||||||
|
return this.transport.getPageMode();
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* @return {Promise} A promise that is resolved with a lookup table for
|
* @return {Promise} A promise that is resolved with a lookup table for
|
||||||
* mapping named attachments to their content.
|
* mapping named attachments to their content.
|
||||||
@ -1939,6 +1946,10 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
return this.messageHandler.sendWithPromise('GetPageLabels', null);
|
return this.messageHandler.sendWithPromise('GetPageLabels', null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getPageMode() {
|
||||||
|
return this.messageHandler.sendWithPromise('GetPageMode', null);
|
||||||
|
},
|
||||||
|
|
||||||
getAttachments: function WorkerTransport_getAttachments() {
|
getAttachments: function WorkerTransport_getAttachments() {
|
||||||
return this.messageHandler.sendWithPromise('GetAttachments', null);
|
return this.messageHandler.sendWithPromise('GetAttachments', null);
|
||||||
},
|
},
|
||||||
|
@ -630,6 +630,28 @@ describe('api', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('gets default page mode', function(done) {
|
||||||
|
var loadingTask = getDocument(buildGetDocumentParams('tracemonkey.pdf'));
|
||||||
|
|
||||||
|
loadingTask.promise.then(function(pdfDocument) {
|
||||||
|
return pdfDocument.getPageMode();
|
||||||
|
}).then(function(mode) {
|
||||||
|
expect(mode).toEqual('UseNone');
|
||||||
|
|
||||||
|
loadingTask.destroy().then(done);
|
||||||
|
}).catch(function (reason) {
|
||||||
|
done.fail(reason);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('gets non-default page mode', function(done) {
|
||||||
|
doc.getPageMode().then(function(mode) {
|
||||||
|
expect(mode).toEqual('UseOutlines');
|
||||||
|
done();
|
||||||
|
}).catch(function(reason) {
|
||||||
|
done.fail(reason);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('gets non-existent attachments', function(done) {
|
it('gets non-existent attachments', function(done) {
|
||||||
var promise = doc.getAttachments();
|
var promise = doc.getAttachments();
|
||||||
promise.then(function (data) {
|
promise.then(function (data) {
|
||||||
|
81
web/app.js
81
web/app.js
@ -141,6 +141,7 @@ let PDFViewerApplication = {
|
|||||||
pdfBugEnabled: false,
|
pdfBugEnabled: false,
|
||||||
showPreviousViewOnLoad: true,
|
showPreviousViewOnLoad: true,
|
||||||
defaultZoomValue: '',
|
defaultZoomValue: '',
|
||||||
|
disablePageMode: false,
|
||||||
disablePageLabels: false,
|
disablePageLabels: false,
|
||||||
renderer: 'canvas',
|
renderer: 'canvas',
|
||||||
enhanceTextSelection: false,
|
enhanceTextSelection: false,
|
||||||
@ -255,6 +256,9 @@ let PDFViewerApplication = {
|
|||||||
preferences.get('renderInteractiveForms').then(function resolved(value) {
|
preferences.get('renderInteractiveForms').then(function resolved(value) {
|
||||||
viewerPrefs['renderInteractiveForms'] = value;
|
viewerPrefs['renderInteractiveForms'] = value;
|
||||||
}),
|
}),
|
||||||
|
preferences.get('disablePageMode').then(function resolved(value) {
|
||||||
|
viewerPrefs['disablePageMode'] = value;
|
||||||
|
}),
|
||||||
preferences.get('disablePageLabels').then(function resolved(value) {
|
preferences.get('disablePageLabels').then(function resolved(value) {
|
||||||
viewerPrefs['disablePageLabels'] = value;
|
viewerPrefs['disablePageLabels'] = value;
|
||||||
}),
|
}),
|
||||||
@ -883,6 +887,11 @@ let PDFViewerApplication = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Since the `setInitialView` call below depends on this being resolved,
|
||||||
|
// fetch it early to avoid delaying initial rendering of the PDF document.
|
||||||
|
let pageModePromise = pdfDocument.getPageMode().catch(
|
||||||
|
function() { /* Avoid breaking initial rendering; ignoring errors. */ });
|
||||||
|
|
||||||
this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
||||||
this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
||||||
|
|
||||||
@ -932,37 +941,39 @@ let PDFViewerApplication = {
|
|||||||
bookmark: this.initialBookmark,
|
bookmark: this.initialBookmark,
|
||||||
hash: null,
|
hash: null,
|
||||||
};
|
};
|
||||||
let storedHash = this.viewerPrefs['defaultZoomValue'] ?
|
let storePromise = store.getMultiple({
|
||||||
('zoom=' + this.viewerPrefs['defaultZoomValue']) : null;
|
|
||||||
let sidebarView = this.viewerPrefs['sidebarViewOnLoad'];
|
|
||||||
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
if (!this.viewerPrefs['showPreviousViewOnLoad']) {
|
|
||||||
resolve();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
store.getMultiple({
|
|
||||||
exists: false,
|
exists: false,
|
||||||
page: '1',
|
page: '1',
|
||||||
zoom: DEFAULT_SCALE_VALUE,
|
zoom: DEFAULT_SCALE_VALUE,
|
||||||
scrollLeft: '0',
|
scrollLeft: '0',
|
||||||
scrollTop: '0',
|
scrollTop: '0',
|
||||||
sidebarView: SidebarView.NONE,
|
sidebarView: SidebarView.NONE,
|
||||||
}).then((values) => {
|
}).catch(() => { /* Unable to read from storage; ignoring errors. */ });
|
||||||
if (!values.exists) {
|
|
||||||
resolve();
|
Promise.all([storePromise, pageModePromise]).then(
|
||||||
return;
|
([values = {}, pageMode]) => {
|
||||||
}
|
// Initialize the default values, from user preferences.
|
||||||
storedHash = 'page=' + values.page +
|
let hash = this.viewerPrefs['defaultZoomValue'] ?
|
||||||
|
('zoom=' + this.viewerPrefs['defaultZoomValue']) : null;
|
||||||
|
let sidebarView = this.viewerPrefs['sidebarViewOnLoad'];
|
||||||
|
|
||||||
|
if (values.exists && this.viewerPrefs['showPreviousViewOnLoad']) {
|
||||||
|
hash = 'page=' + values.page +
|
||||||
'&zoom=' + (this.viewerPrefs['defaultZoomValue'] || values.zoom) +
|
'&zoom=' + (this.viewerPrefs['defaultZoomValue'] || values.zoom) +
|
||||||
',' + values.scrollLeft + ',' + values.scrollTop;
|
',' + values.scrollLeft + ',' + values.scrollTop;
|
||||||
sidebarView = this.viewerPrefs['sidebarViewOnLoad'] ||
|
sidebarView = sidebarView || (values.sidebarView | 0);
|
||||||
(values.sidebarView | 0);
|
}
|
||||||
resolve();
|
if (pageMode && !this.viewerPrefs['disablePageMode']) {
|
||||||
}).catch(resolve);
|
// Always let the user preference/history take precedence.
|
||||||
}).then(() => {
|
sidebarView = sidebarView || apiPageModeToSidebarView(pageMode);
|
||||||
this.setInitialView(storedHash, { sidebarView, scale, });
|
}
|
||||||
initialParams.hash = storedHash;
|
return {
|
||||||
|
hash,
|
||||||
|
sidebarView,
|
||||||
|
};
|
||||||
|
}).then(({ hash, sidebarView, }) => {
|
||||||
|
this.setInitialView(hash, { sidebarView, scale, });
|
||||||
|
initialParams.hash = hash;
|
||||||
|
|
||||||
// Make all navigation keys work on document load,
|
// Make all navigation keys work on document load,
|
||||||
// unless the viewer is embedded in a web page.
|
// unless the viewer is embedded in a web page.
|
||||||
@ -2293,6 +2304,30 @@ function webViewerKeyDown(evt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts API PageMode values to the format used by `PDFSidebar`.
|
||||||
|
* NOTE: There's also a "FullScreen" parameter which is not possible to support,
|
||||||
|
* since the Fullscreen API used in browsers requires that entering
|
||||||
|
* fullscreen mode only occurs as a result of a user-initiated event.
|
||||||
|
* @param {string} mode - The API PageMode value.
|
||||||
|
* @returns {number} A value from {SidebarView}.
|
||||||
|
*/
|
||||||
|
function apiPageModeToSidebarView(mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case 'UseNone':
|
||||||
|
return SidebarView.NONE;
|
||||||
|
case 'UseThumbs':
|
||||||
|
return SidebarView.THUMBS;
|
||||||
|
case 'UseOutlines':
|
||||||
|
return SidebarView.OUTLINE;
|
||||||
|
case 'UseAttachments':
|
||||||
|
return SidebarView.ATTACHMENTS;
|
||||||
|
case 'UseOC':
|
||||||
|
// Not implemented, since we don't support Optional Content Groups yet.
|
||||||
|
}
|
||||||
|
return SidebarView.NONE; // Default value.
|
||||||
|
}
|
||||||
|
|
||||||
/* Abstract factory for the print service. */
|
/* Abstract factory for the print service. */
|
||||||
let PDFPrintServiceFactory = {
|
let PDFPrintServiceFactory = {
|
||||||
instance: {
|
instance: {
|
||||||
|
@ -17,5 +17,6 @@
|
|||||||
"renderer": "canvas",
|
"renderer": "canvas",
|
||||||
"renderInteractiveForms": false,
|
"renderInteractiveForms": false,
|
||||||
"enablePrintAutoRotate": false,
|
"enablePrintAutoRotate": false,
|
||||||
|
"disablePageMode": false,
|
||||||
"disablePageLabels": false
|
"disablePageLabels": false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user