Prevent re-rendering of pages because of rounding errors when computing the scale value
Currently if the zoom level is reset multiple times in a row, i.e. by pressing <kbd>Ctrl</kbd>+<kbd>0</kbd>, the pages can be re-rendered each time even though their size shouldn't change. Whether this happens can depend on the size of the viewer, but documents with pages in landscape mode seem to be very susceptible to this. (An example is: https://wiki.mozilla.org/images/5/55/MobileOpportunity.pdf.) This can also effect documents with pages in portrait mode, when they are displayed in Presentation Mode. The reason for this unnecessary re-rendering is that due to limited numerical precision, the new scale value may change in *only* the last decimal place.
This commit is contained in:
parent
56e3a66c16
commit
d0c071a40d
@ -74,6 +74,18 @@ var PDFViewer = (function pdfViewer() {
|
||||
};
|
||||
}
|
||||
|
||||
function isSameScale(oldScale, newScale) {
|
||||
if (newScale === oldScale) {
|
||||
return true;
|
||||
}
|
||||
if (Math.abs(newScale - oldScale) < 1e-15) {
|
||||
// Prevent unnecessary re-rendering of all pages when the scale
|
||||
// changes only because of limited numerical precision.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructs PDFViewer
|
||||
* @param {PDFViewerOptions} options
|
||||
@ -367,7 +379,8 @@ var PDFViewer = (function pdfViewer() {
|
||||
_setScaleUpdatePages: function pdfViewer_setScaleUpdatePages(
|
||||
newScale, newValue, noScroll, preset) {
|
||||
this._currentScaleValue = newValue;
|
||||
if (newScale === this._currentScale) {
|
||||
|
||||
if (isSameScale(this._currentScale, newScale)) {
|
||||
if (preset) {
|
||||
this._setScaleDispatchEvent(newScale, newValue, true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user