1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[api-minor] Fix various issues related to the pageSize information

The `getPageSizeInches` method was implemented on `PDFDocumentProxy`, which seems conceptually wrong since the size property isn't global to the document but rather specific to each page. Hence the method is moved into `PDFPageProxy`, as `get pageSizeInches` instead to address this.

Despite the fact that new API functionality was implemented, no unit-tests were added. To prevent issues later on, we should *always* ensure that new functionality has at least some test-coverage; something that this patch also takes care of.

The new `PDFDocumentProperties._parsePageSize` method seemed unnecessary convoluted. Furthermore, in the "no data provided"-case it even returned incorrect data (an array, rather than the expected object).
Finally, the fallback strings didn't actually agree with the `en-US` locale. This inconsistency doesn't look too great, and it's thus addressed here as well.
This commit is contained in:
Jonas Jenwald 2018-03-17 17:10:37 +01:00
parent db6e316efd
commit e0ae157582
3 changed files with 45 additions and 41 deletions

View file

@ -692,23 +692,6 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
getMetadata: function PDFDocumentProxy_getMetadata() {
return this.transport.getMetadata();
},
/**
* @param {number} pageNumber The page number to get the page size from.
* The first page is 1, which is also the default page used.
* @return {Promise} A promise that is resolved with an dict containing the
* width and height in inches.
*/
getPageSizeInches(pageNumber) {
pageNumber = pageNumber || 1;
return this.getPage(pageNumber).then((page) => {
const [x1, y1, x2, y2] = page.view;
// convert values from user units to inches
return {
width: (x2 - x1) / 72 * page.userUnit,
height: (y2 - y1) / 72 * page.userUnit,
};
});
},
/**
* @return {Promise} A promise that is resolved with a TypedArray that has
* the raw data from the PDF.
@ -890,6 +873,20 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
get view() {
return this.pageInfo.view;
},
/**
* The size of the current page, converted from PDF units to inches.
* @return {Object} An Object containing the properties: {number} `width`
* and {number} `height`, given in inches.
*/
get pageSizeInches() {
const [x1, y1, x2, y2] = this.view, userUnit = this.userUnit;
return {
width: (x2 - x1) / 72 * userUnit,
height: (y2 - y1) / 72 * userUnit,
};
},
/**
* @param {number} scale The desired scale of the viewport.
* @param {number} rotate Degrees to rotate the viewport. If omitted this