@@ -27,7 +27,9 @@ import {
2727} from "./test_utils.mjs" ;
2828
2929import { fileURLToPath } from "url" ;
30+ import fs from "fs" ;
3031import path from "path" ;
32+ import { PNG } from "pngjs" ;
3133
3234const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
3335
@@ -583,4 +585,90 @@ describe("Signature Editor", () => {
583585 ) ;
584586 } ) ;
585587 } ) ;
588+
589+ describe ( "Check the aspect ratio (bug 1962819)" , ( ) => {
590+ let pages , contentWidth , contentHeight ;
591+
592+ function getContentAspectRatio ( png ) {
593+ const { width, height } = png ;
594+ const buffer = new Uint32Array ( png . data . buffer ) ;
595+ let x0 = width ;
596+ let y0 = height ;
597+ let x1 = 0 ;
598+ let y1 = 0 ;
599+ for ( let i = 0 ; i < height ; i ++ ) {
600+ for ( let j = 0 ; j < width ; j ++ ) {
601+ if ( buffer [ width * i + j ] !== 0 ) {
602+ x0 = Math . min ( x0 , j ) ;
603+ y0 = Math . min ( y0 , i ) ;
604+ x1 = Math . max ( x1 , j ) ;
605+ y1 = Math . max ( y1 , i ) ;
606+ }
607+ }
608+ }
609+
610+ contentWidth = x1 - x0 ;
611+ contentHeight = y1 - y0 ;
612+ }
613+
614+ beforeAll ( ( ) => {
615+ const data = fs . readFileSync (
616+ path . join ( __dirname , "../images/samplesignature.png" )
617+ ) ;
618+ const png = PNG . sync . read ( data ) ;
619+ getContentAspectRatio ( png ) ;
620+ } ) ;
621+
622+ beforeEach ( async ( ) => {
623+ pages = await loadAndWait ( "empty.pdf" , ".annotationEditorLayer" ) ;
624+ } ) ;
625+
626+ afterEach ( async ( ) => {
627+ await closePages ( pages ) ;
628+ } ) ;
629+
630+ it ( "must check that the signature has the correct aspect ratio" , async ( ) => {
631+ await Promise . all (
632+ pages . map ( async ( [ browserName , page ] ) => {
633+ await switchToSignature ( page ) ;
634+ await page . click ( "#editorSignatureAddSignature" ) ;
635+
636+ await page . waitForSelector ( "#addSignatureDialog" , {
637+ visible : true ,
638+ } ) ;
639+
640+ await page . click ( "#addSignatureImageButton" ) ;
641+ await page . waitForSelector ( "#addSignatureImagePlaceholder" , {
642+ visible : true ,
643+ } ) ;
644+ await page . waitForSelector ( `${ addButtonSelector } :disabled` ) ;
645+
646+ const input = await page . $ ( "#addSignatureFilePicker" ) ;
647+ await input . uploadFile (
648+ `${ path . join ( __dirname , "../images/samplesignature.png" ) } `
649+ ) ;
650+ await page . waitForSelector ( `#addSignatureImage > path:not([d=""])` ) ;
651+
652+ // The save button should be enabled now.
653+ await page . waitForSelector (
654+ "#addSignatureSaveContainer > input:not(:disabled)"
655+ ) ;
656+ await page . click ( "#addSignatureAddButton" ) ;
657+ await page . waitForSelector ( "#addSignatureDialog" , {
658+ visible : false ,
659+ } ) ;
660+ const { width, height } = await getRect (
661+ page ,
662+ ".canvasWrapper > svg use[href='#path_p1_0']"
663+ ) ;
664+
665+ expect ( Math . abs ( contentWidth / width - contentHeight / height ) )
666+ . withContext (
667+ `In ${ browserName } (${ contentWidth } x${ contentHeight } vs ${ width } x${ height } )`
668+ )
669+ . toBeLessThan ( 0.25 ) ;
670+ } )
671+ ) ;
672+ } ) ;
673+ } ) ;
586674} ) ;
0 commit comments