@@ -40,6 +40,13 @@ import { XfaLayer } from "./xfa_layer.js";
40
40
const DEFAULT_TAB_INDEX = 1000 ;
41
41
const GetElementsByNameSet = new WeakSet ( ) ;
42
42
43
+ function getRectDims ( rect ) {
44
+ return {
45
+ width : rect [ 2 ] - rect [ 0 ] ,
46
+ height : rect [ 3 ] - rect [ 1 ] ,
47
+ } ;
48
+ }
49
+
43
50
/**
44
51
* @typedef {Object } AnnotationElementParameters
45
52
* @property {Object } data
@@ -189,8 +196,7 @@ class AnnotationElement {
189
196
page = this . page ,
190
197
viewport = this . viewport ;
191
198
const container = document . createElement ( "section" ) ;
192
- let width = data . rect [ 2 ] - data . rect [ 0 ] ;
193
- let height = data . rect [ 3 ] - data . rect [ 1 ] ;
199
+ let { width, height } = getRectDims ( data . rect ) ;
194
200
195
201
container . setAttribute ( "data-annotation-id" , data . id ) ;
196
202
@@ -1842,8 +1848,7 @@ class LineAnnotationElement extends AnnotationElement {
1842
1848
// that acts as the trigger for the popup. Only the line itself should
1843
1849
// trigger the popup, not the entire container.
1844
1850
const data = this . data ;
1845
- const width = data . rect [ 2 ] - data . rect [ 0 ] ;
1846
- const height = data . rect [ 3 ] - data . rect [ 1 ] ;
1851
+ const { width, height } = getRectDims ( data . rect ) ;
1847
1852
const svg = this . svgFactory . create ( width , height ) ;
1848
1853
1849
1854
// PDF coordinates are calculated from a bottom left origin, so transform
@@ -1888,8 +1893,7 @@ class SquareAnnotationElement extends AnnotationElement {
1888
1893
// trigger for the popup. Only the square itself should trigger the
1889
1894
// popup, not the entire container.
1890
1895
const data = this . data ;
1891
- const width = data . rect [ 2 ] - data . rect [ 0 ] ;
1892
- const height = data . rect [ 3 ] - data . rect [ 1 ] ;
1896
+ const { width, height } = getRectDims ( data . rect ) ;
1893
1897
const svg = this . svgFactory . create ( width , height ) ;
1894
1898
1895
1899
// The browser draws half of the borders inside the square and half of
@@ -1936,8 +1940,7 @@ class CircleAnnotationElement extends AnnotationElement {
1936
1940
// trigger for the popup. Only the circle itself should trigger the
1937
1941
// popup, not the entire container.
1938
1942
const data = this . data ;
1939
- const width = data . rect [ 2 ] - data . rect [ 0 ] ;
1940
- const height = data . rect [ 3 ] - data . rect [ 1 ] ;
1943
+ const { width, height } = getRectDims ( data . rect ) ;
1941
1944
const svg = this . svgFactory . create ( width , height ) ;
1942
1945
1943
1946
// The browser draws half of the borders inside the circle and half of
@@ -1987,8 +1990,7 @@ class PolylineAnnotationElement extends AnnotationElement {
1987
1990
// trigger for the popup. Only the polyline itself should trigger the
1988
1991
// popup, not the entire container.
1989
1992
const data = this . data ;
1990
- const width = data . rect [ 2 ] - data . rect [ 0 ] ;
1991
- const height = data . rect [ 3 ] - data . rect [ 1 ] ;
1993
+ const { width, height } = getRectDims ( data . rect ) ;
1992
1994
const svg = this . svgFactory . create ( width , height ) ;
1993
1995
1994
1996
// Convert the vertices array to a single points string that the SVG
@@ -2076,8 +2078,7 @@ class InkAnnotationElement extends AnnotationElement {
2076
2078
// Create an invisible polyline with the same points that acts as the
2077
2079
// trigger for the popup.
2078
2080
const data = this . data ;
2079
- const width = data . rect [ 2 ] - data . rect [ 0 ] ;
2080
- const height = data . rect [ 3 ] - data . rect [ 1 ] ;
2081
+ const { width, height } = getRectDims ( data . rect ) ;
2081
2082
const svg = this . svgFactory . create ( width , height ) ;
2082
2083
2083
2084
for ( const inkList of data . inkLists ) {
@@ -2337,6 +2338,10 @@ class AnnotationLayer {
2337
2338
if ( ! data ) {
2338
2339
continue ;
2339
2340
}
2341
+ const { width, height } = getRectDims ( data . rect ) ;
2342
+ if ( width <= 0 || height <= 0 ) {
2343
+ continue ;
2344
+ }
2340
2345
if ( data . annotationType === AnnotationType . POPUP ) {
2341
2346
popupAnnotations . push ( data ) ;
2342
2347
continue ;
0 commit comments