@@ -22,7 +22,6 @@ import {
22
22
AnnotationBorderStyleType ,
23
23
AnnotationEditorType ,
24
24
AnnotationType ,
25
- assert ,
26
25
FeatureTest ,
27
26
LINE_FACTOR ,
28
27
shadow ,
@@ -182,7 +181,7 @@ class AnnotationElement {
182
181
this . container = this . _createContainer ( ignoreBorder ) ;
183
182
}
184
183
if ( createQuadrilaterals ) {
185
- this . quadrilaterals = this . _createQuadrilaterals ( ignoreBorder ) ;
184
+ this . _createQuadrilaterals ( ) ;
186
185
}
187
186
}
188
187
@@ -417,26 +416,41 @@ class AnnotationElement {
417
416
* @private
418
417
* @param {boolean } ignoreBorder
419
418
* @memberof AnnotationElement
420
- * @returns {Array<HTMLElement> } An array of section elements.
421
419
*/
422
- _createQuadrilaterals ( ignoreBorder = false ) {
423
- if ( ! this . data . quadPoints ) {
424
- return null ;
420
+ _createQuadrilaterals ( ) {
421
+ const { quadPoints } = this . data ;
422
+ if ( ! quadPoints || quadPoints . length === 1 ) {
423
+ return ;
425
424
}
426
425
427
- const quadrilaterals = [ ] ;
428
- const savedRect = this . data . rect ;
429
- for ( const quadPoint of this . data . quadPoints ) {
430
- this . data . rect = [
431
- quadPoint [ 2 ] . x ,
432
- quadPoint [ 2 ] . y ,
433
- quadPoint [ 1 ] . x ,
434
- quadPoint [ 1 ] . y ,
435
- ] ;
436
- quadrilaterals . push ( this . _createContainer ( ignoreBorder ) ) ;
426
+ const { svgFactory } = this ;
427
+ const svg = svgFactory . createElement ( "svg" ) ;
428
+ svg . classList . add ( "quadrilateralsContainer" ) ;
429
+
430
+ svg . setAttribute ( "width" , 0 ) ;
431
+ svg . setAttribute ( "height" , 0 ) ;
432
+ const defs = svgFactory . createElement ( "defs" ) ;
433
+ svg . append ( defs ) ;
434
+ const clipPath = svgFactory . createElement ( "clipPath" ) ;
435
+ const id = `clippath_${ this . data . id } ` ;
436
+ clipPath . setAttribute ( "id" , id ) ;
437
+ clipPath . setAttribute ( "clipPathUnits" , "objectBoundingBox" ) ;
438
+ defs . append ( clipPath ) ;
439
+
440
+ const [ rectBlX , rectBlY , rectTrX , rectTrY ] = this . data . rect ;
441
+ const width = rectTrX - rectBlX ;
442
+ const height = rectTrY - rectBlY ;
443
+ for ( const [ , { x : trX , y : trY } , { x : blX , y : blY } ] of quadPoints ) {
444
+ const rect = svgFactory . createElement ( "rect" ) ;
445
+ rect . setAttribute ( "x" , ( blX - rectBlX ) / width ) ;
446
+ rect . setAttribute ( "y" , ( rectTrY - trY ) / height ) ;
447
+ rect . setAttribute ( "width" , ( trX - blX ) / width ) ;
448
+ rect . setAttribute ( "height" , ( trY - blY ) / height ) ;
449
+ clipPath . append ( rect ) ;
437
450
}
438
- this . data . rect = savedRect ;
439
- return quadrilaterals ;
451
+
452
+ this . container . append ( svg ) ;
453
+ this . container . style . clipPath = `url(#${ id } )` ;
440
454
}
441
455
442
456
/**
@@ -450,18 +464,8 @@ class AnnotationElement {
450
464
* @memberof AnnotationElement
451
465
*/
452
466
_createPopup ( trigger , data ) {
453
- let container = this . container ;
454
- if ( this . quadrilaterals ) {
455
- trigger ||= this . quadrilaterals ;
456
- container = this . quadrilaterals [ 0 ] ;
457
- }
458
-
459
- // If no trigger element is specified, create it.
460
- if ( ! trigger ) {
461
- trigger = document . createElement ( "div" ) ;
462
- trigger . classList . add ( "popupTriggerArea" ) ;
463
- container . append ( trigger ) ;
464
- }
467
+ const container = this . container ;
468
+ trigger ||= this . container ;
465
469
466
470
const popupElement = new PopupElement ( {
467
471
container,
@@ -481,25 +485,6 @@ class AnnotationElement {
481
485
container . append ( popup ) ;
482
486
}
483
487
484
- /**
485
- * Render the quadrilaterals of the annotation.
486
- *
487
- * @private
488
- * @param {string } className
489
- * @memberof AnnotationElement
490
- * @returns {Array<HTMLElement> } An array of section elements.
491
- */
492
- _renderQuadrilaterals ( className ) {
493
- if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) {
494
- assert ( this . quadrilaterals , "Missing quadrilaterals during rendering" ) ;
495
- }
496
-
497
- for ( const quadrilateral of this . quadrilaterals ) {
498
- quadrilateral . classList . add ( className ) ;
499
- }
500
- return this . quadrilaterals ;
501
- }
502
-
503
488
/**
504
489
* Render the annotation's HTML element(s).
505
490
*
@@ -626,16 +611,6 @@ class LinkAnnotationElement extends AnnotationElement {
626
611
}
627
612
}
628
613
629
- if ( this . quadrilaterals ) {
630
- return this . _renderQuadrilaterals ( "linkAnnotation" ) . map (
631
- ( quadrilateral , index ) => {
632
- const linkElement = index === 0 ? link : link . cloneNode ( ) ;
633
- quadrilateral . append ( linkElement ) ;
634
- return quadrilateral ;
635
- }
636
- ) ;
637
- }
638
-
639
614
this . container . classList . add ( "linkAnnotation" ) ;
640
615
if ( isBound ) {
641
616
this . container . append ( link ) ;
@@ -2411,10 +2386,6 @@ class HighlightAnnotationElement extends AnnotationElement {
2411
2386
this . _createPopup ( null , this . data ) ;
2412
2387
}
2413
2388
2414
- if ( this . quadrilaterals ) {
2415
- return this . _renderQuadrilaterals ( "highlightAnnotation" ) ;
2416
- }
2417
-
2418
2389
this . container . classList . add ( "highlightAnnotation" ) ;
2419
2390
return this . container ;
2420
2391
}
@@ -2440,10 +2411,6 @@ class UnderlineAnnotationElement extends AnnotationElement {
2440
2411
this . _createPopup ( null , this . data ) ;
2441
2412
}
2442
2413
2443
- if ( this . quadrilaterals ) {
2444
- return this . _renderQuadrilaterals ( "underlineAnnotation" ) ;
2445
- }
2446
-
2447
2414
this . container . classList . add ( "underlineAnnotation" ) ;
2448
2415
return this . container ;
2449
2416
}
@@ -2469,10 +2436,6 @@ class SquigglyAnnotationElement extends AnnotationElement {
2469
2436
this . _createPopup ( null , this . data ) ;
2470
2437
}
2471
2438
2472
- if ( this . quadrilaterals ) {
2473
- return this . _renderQuadrilaterals ( "squigglyAnnotation" ) ;
2474
- }
2475
-
2476
2439
this . container . classList . add ( "squigglyAnnotation" ) ;
2477
2440
return this . container ;
2478
2441
}
@@ -2498,10 +2461,6 @@ class StrikeOutAnnotationElement extends AnnotationElement {
2498
2461
this . _createPopup ( null , this . data ) ;
2499
2462
}
2500
2463
2501
- if ( this . quadrilaterals ) {
2502
- return this . _renderQuadrilaterals ( "strikeoutAnnotation" ) ;
2503
- }
2504
-
2505
2464
this . container . classList . add ( "strikeoutAnnotation" ) ;
2506
2465
return this . container ;
2507
2466
}
0 commit comments