mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Merge pull request #9586 from Snuffleupagus/pageSize-api-rotate
Ensure that `PDFPageProxy.pageSizeInches` handles non-default /Rotate entries correctly
This commit is contained in:
commit
5c1a16ba6e
5 changed files with 56 additions and 25 deletions
|
@ -269,6 +269,27 @@ function roundToDivide(x, div) {
|
|||
return r === 0 ? x : Math.round(x - r + div);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the specified page, converted from PDF units to inches.
|
||||
* @param {Object} An Object containing the properties: {Array} `view`,
|
||||
* {number} `userUnit`, and {number} `rotate`.
|
||||
* @return {Object} An Object containing the properties: {number} `width`
|
||||
* and {number} `height`, given in inches.
|
||||
*/
|
||||
function getPageSizeInches({ view, userUnit, rotate, }) {
|
||||
const [x1, y1, x2, y2] = view;
|
||||
// We need to take the page rotation into account as well.
|
||||
const changeOrientation = rotate % 180 !== 0;
|
||||
|
||||
const width = (x2 - x1) / 72 * userUnit;
|
||||
const height = (y2 - y1) / 72 * userUnit;
|
||||
|
||||
return {
|
||||
width: (changeOrientation ? height : width),
|
||||
height: (changeOrientation ? width : height),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic helper to find out what elements are visible within a scroll pane.
|
||||
*/
|
||||
|
@ -634,6 +655,7 @@ export {
|
|||
parseQueryString,
|
||||
getVisibleElements,
|
||||
roundToDivide,
|
||||
getPageSizeInches,
|
||||
approximateFraction,
|
||||
getOutputScale,
|
||||
scrollIntoView,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue