@@ -71,13 +71,11 @@ import { XfaLayerBuilder } from "./xfa_layer_builder.js";
71
71
* The default value is `AnnotationMode.ENABLE_FORMS`.
72
72
* @property {string } [imageResourcesPath] - Path for image resources, mainly
73
73
* for annotation icons. Include trailing slash.
74
- * @property {boolean } [useOnlyCssZoom] - Enables CSS only zooming. The default
75
- * value is `false`.
76
74
* @property {boolean } [isOffscreenCanvasSupported] - Allows to use an
77
75
* OffscreenCanvas if needed.
78
76
* @property {number } [maxCanvasPixels] - The maximum supported canvas size in
79
- * total pixels, i.e. width * height. Use -1 for no limit. The default value
80
- * is 4096 * 4096 (16 mega-pixels).
77
+ * total pixels, i.e. width * height. Use `-1` for no limit, or `0` for
78
+ * CSS-only zooming. The default value is 4096 * 4096 (16 mega-pixels).
81
79
* @property {Object } [pageColors] - Overwrites background and foreground colors
82
80
* with user defined ones in order to improve readability in high contrast
83
81
* mode.
@@ -112,6 +110,8 @@ const DEFAULT_LAYER_PROPERTIES = () => {
112
110
class PDFPageView {
113
111
#annotationMode = AnnotationMode . ENABLE_FORMS ;
114
112
113
+ #hasRestrictedScaling = false ;
114
+
115
115
#layerProperties = null ;
116
116
117
117
#loadingId = null ;
@@ -151,15 +151,13 @@ class PDFPageView {
151
151
this . pdfPageRotate = defaultViewport . rotation ;
152
152
this . _optionalContentConfigPromise =
153
153
options . optionalContentConfigPromise || null ;
154
- this . hasRestrictedScaling = false ;
155
154
this . #textLayerMode = options . textLayerMode ?? TextLayerMode . ENABLE ;
156
155
this . #annotationMode =
157
156
options . annotationMode ?? AnnotationMode . ENABLE_FORMS ;
158
157
this . imageResourcesPath = options . imageResourcesPath || "" ;
159
- this . useOnlyCssZoom = options . useOnlyCssZoom || false ;
160
158
this . isOffscreenCanvasSupported =
161
159
options . isOffscreenCanvasSupported ?? true ;
162
- this . maxCanvasPixels = options . maxCanvasPixels || MAX_CANVAS_PIXELS ;
160
+ this . maxCanvasPixels = options . maxCanvasPixels ?? MAX_CANVAS_PIXELS ;
163
161
this . pageColors = options . pageColors || null ;
164
162
165
163
this . eventBus = options . eventBus ;
@@ -171,6 +169,13 @@ class PDFPageView {
171
169
if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
172
170
this . _isStandalone = ! this . renderingQueue ?. hasViewer ( ) ;
173
171
this . _container = container ;
172
+
173
+ if ( options . useOnlyCssZoom ) {
174
+ console . error (
175
+ "useOnlyCssZoom was removed, please use `maxCanvasPixels = 0` instead."
176
+ ) ;
177
+ this . maxCanvasPixels = 0 ;
178
+ }
174
179
}
175
180
176
181
this . _annotationCanvasMap = null ;
@@ -586,23 +591,25 @@ class PDFPageView {
586
591
this . _container ?. style . setProperty ( "--scale-factor" , this . viewport . scale ) ;
587
592
}
588
593
589
- let isScalingRestricted = false ;
590
- if ( this . canvas && this . maxCanvasPixels > 0 ) {
591
- const { width, height } = this . viewport ;
592
- const { sx, sy } = this . outputScale ;
593
- if (
594
- ( ( Math . floor ( width ) * sx ) | 0 ) * ( ( Math . floor ( height ) * sy ) | 0 ) >
595
- this . maxCanvasPixels
596
- ) {
597
- isScalingRestricted = true ;
594
+ if ( this . canvas ) {
595
+ let onlyCssZoom = false ;
596
+ if ( this . #hasRestrictedScaling) {
597
+ if (
598
+ ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) &&
599
+ this . maxCanvasPixels === 0
600
+ ) {
601
+ onlyCssZoom = true ;
602
+ } else if ( this . maxCanvasPixels > 0 ) {
603
+ const { width, height } = this . viewport ;
604
+ const { sx, sy } = this . outputScale ;
605
+ onlyCssZoom =
606
+ ( ( Math . floor ( width ) * sx ) | 0 ) * ( ( Math . floor ( height ) * sy ) | 0 ) >
607
+ this . maxCanvasPixels ;
608
+ }
598
609
}
599
- }
600
- const onlyCssZoom =
601
- this . useOnlyCssZoom || ( this . hasRestrictedScaling && isScalingRestricted ) ;
602
- const postponeDrawing =
603
- ! onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000 ;
610
+ const postponeDrawing =
611
+ ! onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000 ;
604
612
605
- if ( this . canvas ) {
606
613
if ( postponeDrawing || onlyCssZoom ) {
607
614
if (
608
615
postponeDrawing &&
@@ -921,25 +928,25 @@ class PDFPageView {
921
928
const ctx = canvas . getContext ( "2d" , { alpha : false } ) ;
922
929
const outputScale = ( this . outputScale = new OutputScale ( ) ) ;
923
930
924
- if ( this . useOnlyCssZoom ) {
925
- const actualSizeViewport = viewport . clone ( {
926
- scale : PixelsPerInch . PDF_TO_CSS_UNITS ,
927
- } ) ;
931
+ if (
932
+ ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) &&
933
+ this . maxCanvasPixels === 0
934
+ ) {
935
+ const invScale = 1 / this . scale ;
928
936
// Use a scale that makes the canvas have the originally intended size
929
937
// of the page.
930
- outputScale . sx *= actualSizeViewport . width / width ;
931
- outputScale . sy *= actualSizeViewport . height / height ;
932
- }
933
-
934
- if ( this . maxCanvasPixels > 0 ) {
938
+ outputScale . sx *= invScale ;
939
+ outputScale . sy *= invScale ;
940
+ this . #hasRestrictedScaling = true ;
941
+ } else if ( this . maxCanvasPixels > 0 ) {
935
942
const pixelsInViewport = width * height ;
936
943
const maxScale = Math . sqrt ( this . maxCanvasPixels / pixelsInViewport ) ;
937
944
if ( outputScale . sx > maxScale || outputScale . sy > maxScale ) {
938
945
outputScale . sx = maxScale ;
939
946
outputScale . sy = maxScale ;
940
- this . hasRestrictedScaling = true ;
947
+ this . # hasRestrictedScaling = true ;
941
948
} else {
942
- this . hasRestrictedScaling = false ;
949
+ this . # hasRestrictedScaling = false ;
943
950
}
944
951
}
945
952
const sfx = approximateFraction ( outputScale . sx ) ;
0 commit comments