@@ -199,6 +199,10 @@ class AnnotationElement {
199
199
const container = document . createElement ( "section" ) ;
200
200
let { width, height } = getRectDims ( data . rect ) ;
201
201
202
+ const [ pageLLx , pageLLy , pageURx , pageURy ] = viewport . viewBox ;
203
+ const pageWidth = pageURx - pageLLx ;
204
+ const pageHeight = pageURy - pageLLy ;
205
+
202
206
container . setAttribute ( "data-annotation-id" , data . id ) ;
203
207
204
208
// Do *not* modify `data.rect`, since that will corrupt the annotation
@@ -210,27 +214,6 @@ class AnnotationElement {
210
214
page . view [ 3 ] - data . rect [ 3 ] + page . view [ 1 ] ,
211
215
] ) ;
212
216
213
- if ( data . hasOwnCanvas ) {
214
- const transform = viewport . transform . slice ( ) ;
215
- const [ scaleX , scaleY ] = Util . singularValueDecompose2dScale ( transform ) ;
216
- width = Math . ceil ( width * scaleX ) ;
217
- height = Math . ceil ( height * scaleY ) ;
218
- rect [ 0 ] *= scaleX ;
219
- rect [ 1 ] *= scaleY ;
220
- // Reset the scale part of the transform matrix (which must be diagonal
221
- // or anti-diagonal) in order to avoid to rescale the canvas.
222
- // The canvas for the annotation is correctly scaled when it is drawn
223
- // (see `beginAnnotation` in canvas.js).
224
- for ( let i = 0 ; i < 4 ; i ++ ) {
225
- transform [ i ] = Math . sign ( transform [ i ] ) ;
226
- }
227
- container . style . transform = `matrix(${ transform . join ( "," ) } )` ;
228
- } else {
229
- container . style . transform = `matrix(${ viewport . transform . join ( "," ) } )` ;
230
- }
231
-
232
- container . style . transformOrigin = `${ - rect [ 0 ] } px ${ - rect [ 1 ] } px` ;
233
-
234
217
if ( ! ignoreBorder && data . borderStyle . width > 0 ) {
235
218
container . style . borderWidth = `${ data . borderStyle . width } px` ;
236
219
if ( data . borderStyle . style !== AnnotationBorderStyleType . UNDERLINE ) {
@@ -286,15 +269,11 @@ class AnnotationElement {
286
269
}
287
270
}
288
271
289
- container . style . left = `${ rect [ 0 ] } px` ;
290
- container . style . top = `${ rect [ 1 ] } px` ;
272
+ container . style . left = `${ ( 100 * ( rect [ 0 ] - pageLLx ) ) / pageWidth } %` ;
273
+ container . style . top = `${ ( 100 * ( rect [ 1 ] - pageLLy ) ) / pageHeight } %` ;
274
+ container . style . width = `${ ( 100 * width ) / pageWidth } %` ;
275
+ container . style . height = `${ ( 100 * height ) / pageHeight } %` ;
291
276
292
- if ( data . hasOwnCanvas ) {
293
- container . style . width = container . style . height = "auto" ;
294
- } else {
295
- container . style . width = `${ width } px` ;
296
- container . style . height = `${ height } px` ;
297
- }
298
277
return container ;
299
278
}
300
279
@@ -464,7 +443,8 @@ class AnnotationElement {
464
443
const popup = popupElement . render ( ) ;
465
444
466
445
// Position the popup next to the annotation's container.
467
- popup . style . left = container . style . width ;
446
+ popup . style . left = "100%" ;
447
+ popup . style . top = "100%" ;
468
448
469
449
container . append ( popup ) ;
470
450
}
@@ -813,8 +793,6 @@ class TextAnnotationElement extends AnnotationElement {
813
793
this . container . className = "textAnnotation" ;
814
794
815
795
const image = document . createElement ( "img" ) ;
816
- image . style . height = this . container . style . height ;
817
- image . style . width = this . container . style . width ;
818
796
image . src =
819
797
this . imageResourcesPath +
820
798
"annotation-" +
@@ -918,21 +896,20 @@ class WidgetAnnotationElement extends AnnotationElement {
918
896
// it's instead based on the field height.
919
897
// If the height is "big" then it could lead to a too big font size
920
898
// so in this case use the one we've in the pdf (hence the min).
899
+ let computedFontSize ;
921
900
if ( this . data . multiLine ) {
922
901
const height = Math . abs ( this . data . rect [ 3 ] - this . data . rect [ 1 ] ) ;
923
902
const numberOfLines = Math . round ( height / ( LINE_FACTOR * fontSize ) ) || 1 ;
924
903
const lineHeight = height / numberOfLines ;
925
- style . fontSize = ` ${ Math . min (
904
+ computedFontSize = Math . min (
926
905
fontSize ,
927
906
Math . round ( lineHeight / LINE_FACTOR )
928
- ) } px` ;
907
+ ) ;
929
908
} else {
930
909
const height = Math . abs ( this . data . rect [ 3 ] - this . data . rect [ 1 ] ) ;
931
- style . fontSize = `${ Math . min (
932
- fontSize ,
933
- Math . round ( height / LINE_FACTOR )
934
- ) } px`;
910
+ computedFontSize = Math . min ( fontSize , Math . round ( height / LINE_FACTOR ) ) ;
935
911
}
912
+ style . fontSize = `${ computedFontSize } %` ;
936
913
937
914
style . color = Util . makeHexColor ( fontColor [ 0 ] , fontColor [ 1 ] , fontColor [ 2 ] ) ;
938
915
@@ -1221,7 +1198,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
1221
1198
const combWidth = fieldWidth / this . data . maxLen ;
1222
1199
1223
1200
element . classList . add ( "comb" ) ;
1224
- element . style . letterSpacing = `calc(${ combWidth } px - 1ch)` ;
1201
+ element . style . letterSpacing = `calc(${ combWidth } px * var(--scale-factor) - 1ch)` ;
1225
1202
}
1226
1203
} else {
1227
1204
element = document . createElement ( "div" ) ;
@@ -1449,10 +1426,6 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1449
1426
value : this . data . fieldValue ,
1450
1427
} ) ;
1451
1428
1452
- const fontSize =
1453
- this . data . defaultAppearanceData . fontSize || DEFAULT_FONT_SIZE ;
1454
- const fontSizeStyle = `calc(${ fontSize } px * var(--zoom-factor))` ;
1455
-
1456
1429
const selectElement = document . createElement ( "select" ) ;
1457
1430
GetElementsByNameSet . add ( selectElement ) ;
1458
1431
selectElement . disabled = this . data . readOnly ;
@@ -1483,9 +1456,6 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1483
1456
const optionElement = document . createElement ( "option" ) ;
1484
1457
optionElement . textContent = option . displayValue ;
1485
1458
optionElement . value = option . exportValue ;
1486
- if ( this . data . combo ) {
1487
- optionElement . style . fontSize = fontSizeStyle ;
1488
- }
1489
1459
if ( storedData . value . includes ( option . exportValue ) ) {
1490
1460
optionElement . setAttribute ( "selected" , true ) ;
1491
1461
addAnEmptyEntry = false ;
@@ -1730,9 +1700,12 @@ class PopupAnnotationElement extends AnnotationElement {
1730
1700
rect [ 0 ] + this . data . parentRect [ 2 ] - this . data . parentRect [ 0 ] ;
1731
1701
const popupTop = rect [ 1 ] ;
1732
1702
1733
- this . container . style . transformOrigin = `${ - popupLeft } px ${ - popupTop } px` ;
1734
- this . container . style . left = `${ popupLeft } px` ;
1735
- this . container . style . top = `${ popupTop } px` ;
1703
+ const [ pageLLx , pageLLy , pageURx , pageURy ] = this . viewport . viewBox ;
1704
+ const pageWidth = pageURx - pageLLx ;
1705
+ const pageHeight = pageURy - pageLLy ;
1706
+
1707
+ this . container . style . left = `${ ( 100 * ( popupLeft - pageLLx ) ) / pageWidth } %` ;
1708
+ this . container . style . top = `${ ( 100 * ( popupTop - pageLLy ) ) / pageHeight } %` ;
1736
1709
1737
1710
this . container . append ( popup . render ( ) ) ;
1738
1711
return this . container ;
@@ -1942,7 +1915,7 @@ class LineAnnotationElement extends AnnotationElement {
1942
1915
// trigger the popup, not the entire container.
1943
1916
const data = this . data ;
1944
1917
const { width, height } = getRectDims ( data . rect ) ;
1945
- const svg = this . svgFactory . create ( width , height ) ;
1918
+ const svg = this . svgFactory . create ( width , height , /* noDims = */ true ) ;
1946
1919
1947
1920
// PDF coordinates are calculated from a bottom left origin, so transform
1948
1921
// the line coordinates to a top left origin for the SVG element.
@@ -1987,7 +1960,7 @@ class SquareAnnotationElement extends AnnotationElement {
1987
1960
// popup, not the entire container.
1988
1961
const data = this . data ;
1989
1962
const { width, height } = getRectDims ( data . rect ) ;
1990
- const svg = this . svgFactory . create ( width , height ) ;
1963
+ const svg = this . svgFactory . create ( width , height , /* noDims = */ true ) ;
1991
1964
1992
1965
// The browser draws half of the borders inside the square and half of
1993
1966
// the borders outside the square by default. This behavior cannot be
@@ -2034,7 +2007,7 @@ class CircleAnnotationElement extends AnnotationElement {
2034
2007
// popup, not the entire container.
2035
2008
const data = this . data ;
2036
2009
const { width, height } = getRectDims ( data . rect ) ;
2037
- const svg = this . svgFactory . create ( width , height ) ;
2010
+ const svg = this . svgFactory . create ( width , height , /* noDims = */ true ) ;
2038
2011
2039
2012
// The browser draws half of the borders inside the circle and half of
2040
2013
// the borders outside the circle by default. This behavior cannot be
@@ -2084,7 +2057,7 @@ class PolylineAnnotationElement extends AnnotationElement {
2084
2057
// popup, not the entire container.
2085
2058
const data = this . data ;
2086
2059
const { width, height } = getRectDims ( data . rect ) ;
2087
- const svg = this . svgFactory . create ( width , height ) ;
2060
+ const svg = this . svgFactory . create ( width , height , /* noDims = */ true ) ;
2088
2061
2089
2062
// Convert the vertices array to a single points string that the SVG
2090
2063
// polyline element expects ("x1,y1 x2,y2 ..."). PDF coordinates are
@@ -2172,7 +2145,7 @@ class InkAnnotationElement extends AnnotationElement {
2172
2145
// trigger for the popup.
2173
2146
const data = this . data ;
2174
2147
const { width, height } = getRectDims ( data . rect ) ;
2175
- const svg = this . svgFactory . create ( width , height ) ;
2148
+ const svg = this . svgFactory . create ( width , height , /* noDims = */ true ) ;
2176
2149
2177
2150
for ( const inkList of data . inkLists ) {
2178
2151
// Convert the ink list to a single points string that the SVG
@@ -2496,55 +2469,27 @@ class AnnotationLayer {
2496
2469
* @memberof AnnotationLayer
2497
2470
*/
2498
2471
static update ( parameters ) {
2499
- const { page, viewport, annotations, annotationCanvasMap, div } =
2500
- parameters ;
2501
- const transform = viewport . transform ;
2502
- const matrix = `matrix(${ transform . join ( "," ) } )` ;
2503
-
2504
- let scale , ownMatrix ;
2505
- for ( const data of annotations ) {
2506
- const elements = div . querySelectorAll (
2507
- `[data-annotation-id="${ data . id } "]`
2508
- ) ;
2509
- if ( elements ) {
2510
- for ( const element of elements ) {
2511
- if ( data . hasOwnCanvas ) {
2512
- const rect = Util . normalizeRect ( [
2513
- data . rect [ 0 ] ,
2514
- page . view [ 3 ] - data . rect [ 1 ] + page . view [ 1 ] ,
2515
- data . rect [ 2 ] ,
2516
- page . view [ 3 ] - data . rect [ 3 ] + page . view [ 1 ] ,
2517
- ] ) ;
2518
-
2519
- if ( ! ownMatrix ) {
2520
- // When an annotation has its own canvas, then
2521
- // the scale has been already applied to the canvas,
2522
- // so we musn't scale it twice.
2523
- scale = Math . abs ( transform [ 0 ] || transform [ 1 ] ) ;
2524
- const ownTransform = transform . slice ( ) ;
2525
- for ( let i = 0 ; i < 4 ; i ++ ) {
2526
- ownTransform [ i ] = Math . sign ( ownTransform [ i ] ) ;
2527
- }
2528
- ownMatrix = `matrix(${ ownTransform . join ( "," ) } )` ;
2529
- }
2530
-
2531
- const left = rect [ 0 ] * scale ;
2532
- const top = rect [ 1 ] * scale ;
2533
- element . style . left = `${ left } px` ;
2534
- element . style . top = `${ top } px` ;
2535
- element . style . transformOrigin = `${ - left } px ${ - top } px` ;
2536
- element . style . transform = ownMatrix ;
2537
- } else {
2538
- element . style . transform = matrix ;
2539
- }
2540
- }
2541
- }
2542
- }
2472
+ const { annotationCanvasMap, div } = parameters ;
2543
2473
2544
2474
this . #setAnnotationCanvasMap( div , annotationCanvasMap ) ;
2545
2475
div . hidden = false ;
2546
2476
}
2547
2477
2478
+ static setDimensions ( div , viewport ) {
2479
+ const { width, height, rotation } = viewport ;
2480
+ const { style } = div ;
2481
+
2482
+ if ( rotation === 0 || rotation === 180 ) {
2483
+ style . width = `${ width } px` ;
2484
+ style . height = `${ height } px` ;
2485
+ } else {
2486
+ style . width = `${ height } px` ;
2487
+ style . height = `${ width } px` ;
2488
+ }
2489
+
2490
+ div . setAttribute ( "data-annot-rotation" , rotation ) ;
2491
+ }
2492
+
2548
2493
static #setAnnotationCanvasMap( div , annotationCanvasMap ) {
2549
2494
if ( ! annotationCanvasMap ) {
2550
2495
return ;
0 commit comments