@@ -1799,6 +1799,77 @@ describe("FreeText Editor", () => {
17991799 } ) ;
18001800 } ) ;
18011801
1802+ describe ( "FreeText (open existing generated with Cairo)" , ( ) => {
1803+ let pages ;
1804+
1805+ beforeEach ( async ( ) => {
1806+ pages = await loadAndWait (
1807+ "issue20504.pdf" ,
1808+ ".annotationEditorLayer" ,
1809+ 100
1810+ ) ;
1811+ } ) ;
1812+
1813+ afterEach ( async ( ) => {
1814+ await closePages ( pages ) ;
1815+ } ) ;
1816+
1817+ it ( "must open some existing annotations" , async ( ) => {
1818+ await Promise . all (
1819+ pages . map ( async ( [ browserName , page ] ) => {
1820+ const boxes = [ ] ;
1821+ for ( const num of [ 48 , 49 , 50 , 51 , 52 ] ) {
1822+ const id = `${ num } R` ;
1823+ await page . waitForSelector ( getAnnotationSelector ( id ) , {
1824+ visible : true ,
1825+ } ) ;
1826+ const rect = await getRect ( page , getAnnotationSelector ( id ) ) ;
1827+ boxes . push ( rect ) ;
1828+ }
1829+
1830+ await switchToFreeText ( page ) ;
1831+
1832+ // The font sizes extracted from the Cairo appearance streams.
1833+ const expectedFontSizes = [ 61 , 38 , 38 , 38 , 56 ] ;
1834+ const PRECISION = 0.3 ;
1835+
1836+ for ( let i = 0 ; i < boxes . length ; i ++ ) {
1837+ const rect = await getRect ( page , `#pdfjs_internal_editor_${ i } ` ) ;
1838+
1839+ // The default used font can be different from a platform to another
1840+ // hence we just check that the dimensions have the some order of
1841+ // magnitude as the annotation rect.
1842+ expect ( Math . abs ( rect . width / boxes [ i ] . width - 1 ) )
1843+ . withContext ( `In ${ browserName } , editor ${ i } width` )
1844+ . toBeLessThan ( PRECISION ) ;
1845+ expect ( Math . abs ( rect . height / boxes [ i ] . height - 1 ) )
1846+ . withContext ( `In ${ browserName } , editor ${ i } height` )
1847+ . toBeLessThan ( PRECISION ) ;
1848+ expect ( Math . abs ( rect . x / boxes [ i ] . x - 1 ) )
1849+ . withContext ( `In ${ browserName } , editor ${ i } x` )
1850+ . toBeLessThan ( PRECISION ) ;
1851+ expect ( Math . abs ( rect . y / boxes [ i ] . y - 1 ) )
1852+ . withContext ( `In ${ browserName } , editor ${ i } y` )
1853+ . toBeLessThan ( PRECISION ) ;
1854+
1855+ // Verify that the font size is correctly extracted from the Cairo
1856+ // appearance stream (font size is encoded in the cm operator).
1857+ const fontSize = await page . evaluate ( N => {
1858+ const editorDiv = document . getElementById (
1859+ `pdfjs_internal_editor_${ N } -editor`
1860+ ) ;
1861+ const match = editorDiv ?. style . fontSize . match ( / c a l c \( ( \d + ) p x / ) ;
1862+ return match ? parseInt ( match [ 1 ] ) : 0 ;
1863+ } , i ) ;
1864+ expect ( fontSize )
1865+ . withContext ( `In ${ browserName } , editor ${ i } fontSize` )
1866+ . toEqual ( expectedFontSizes [ i ] ) ;
1867+ }
1868+ } )
1869+ ) ;
1870+ } ) ;
1871+ } ) ;
1872+
18021873 describe ( "Keyboard shortcuts when the editor layer isn't focused" , ( ) => {
18031874 let pages ;
18041875
0 commit comments