@@ -78,12 +78,14 @@ import { XfaLayerBuilder } from "./xfa_layer_builder.js";
78
78
* @property {number } [maxCanvasPixels] - The maximum supported canvas size in
79
79
* total pixels, i.e. width * height. Use `-1` for no limit, or `0` for
80
80
* CSS-only zooming. The default value is 4096 * 8192 (32 mega-pixels).
81
+ * @property {number } [maxCanvasDim] - The maximum supported canvas dimension,
82
+ * in either width or height. Use `-1` for no limit.
83
+ * The default value is 32767.
81
84
* @property {boolean } [enableDetailCanvas] - When enabled, if the rendered
82
- * pages would need a canvas that is larger than `maxCanvasPixels`, it will
83
- * draw a second canvas on top of the CSS-zoomed one, that only renders the
84
- * part of the page that is close to the viewport. The default value is
85
- * `true`.
86
-
85
+ * pages would need a canvas that is larger than `maxCanvasPixels` or
86
+ * `maxCanvasDim`, it will draw a second canvas on top of the CSS-zoomed one,
87
+ * that only renders the part of the page that is close to the viewport.
88
+ * The default value is `true`.
87
89
* @property {Object } [pageColors] - Overwrites background and foreground colors
88
90
* with user defined ones in order to improve readability in high contrast
89
91
* mode.
@@ -185,6 +187,7 @@ class PDFPageView extends BasePDFPageView {
185
187
this . enableDetailCanvas = options . enableDetailCanvas ?? true ;
186
188
this . maxCanvasPixels =
187
189
options . maxCanvasPixels ?? AppOptions . get ( "maxCanvasPixels" ) ;
190
+ this . maxCanvasDim = options . maxCanvasDim || AppOptions . get ( "maxCanvasDim" ) ;
188
191
this . #enableAutoLinking = options . enableAutoLinking || false ;
189
192
190
193
this . l10n = options . l10n ;
@@ -772,9 +775,21 @@ class PDFPageView extends BasePDFPageView {
772
775
outputScale . sx *= invScale ;
773
776
outputScale . sy *= invScale ;
774
777
this . #needsRestrictedScaling = true ;
775
- } else if ( this . maxCanvasPixels > 0 ) {
776
- const pixelsInViewport = width * height ;
777
- const maxScale = Math . sqrt ( this . maxCanvasPixels / pixelsInViewport ) ;
778
+ } else if ( this . maxCanvasPixels > 0 || this . maxCanvasDim !== - 1 ) {
779
+ let maxAreaScale = Infinity ,
780
+ maxWidthScale = Infinity ,
781
+ maxHeightScale = Infinity ;
782
+
783
+ if ( this . maxCanvasPixels > 0 ) {
784
+ const pixelsInViewport = width * height ;
785
+ maxAreaScale = Math . sqrt ( this . maxCanvasPixels / pixelsInViewport ) ;
786
+ }
787
+ if ( this . maxCanvasDim !== - 1 ) {
788
+ maxWidthScale = this . maxCanvasDim / width ;
789
+ maxHeightScale = this . maxCanvasDim / height ;
790
+ }
791
+ const maxScale = Math . min ( maxAreaScale , maxWidthScale , maxHeightScale ) ;
792
+
778
793
if ( outputScale . sx > maxScale || outputScale . sy > maxScale ) {
779
794
outputScale . sx = maxScale ;
780
795
outputScale . sy = maxScale ;
0 commit comments