@@ -122,7 +122,7 @@ import {
122122 PdfStampFit ,
123123 PdfAddAttachmentParams ,
124124} from '@embedpdf/models' ;
125- import { isValidCustomKey , readArrayBuffer , readString } from './helper' ;
125+ import { computeFormDrawParams , isValidCustomKey , readArrayBuffer , readString } from './helper' ;
126126import { WrappedPdfiumModule } from '@embedpdf/pdfium' ;
127127import { DocumentContext , PageContext , PdfCache } from './cache' ;
128128import { ImageDataConverter , LazyImageData } from '../converters/types' ;
@@ -155,63 +155,6 @@ export enum RenderFlag {
155155 REVERSE_BYTE_ORDER = 0x10 , // Set whether render in a reverse Byte order, this flag only.
156156}
157157
158- interface FormDrawParams {
159- startX : number ;
160- startY : number ;
161- formsWidth : number ;
162- formsHeight : number ;
163- scaleX : number ;
164- scaleY : number ;
165- }
166-
167- function computeFormDrawParams ( matrix : Matrix , rect : Rect , pageSize : Size , rotation : Rotation ) : FormDrawParams {
168- const rectLeft = rect . origin . x ;
169- const rectBottom = rect . origin . y ;
170- const rectRight = rectLeft + rect . size . width ;
171- const rectTop = rectBottom + rect . size . height ;
172- const pageWidth = pageSize . width ;
173- const pageHeight = pageSize . height ;
174-
175- // Extract the per-axis scale that the render matrix applies.
176- const scaleX = Math . hypot ( matrix . a , matrix . b ) ;
177- const scaleY = Math . hypot ( matrix . c , matrix . d ) ;
178- const swap = ( rotation & 1 ) === 1 ;
179-
180- const formsWidth = swap
181- ? Math . max ( 1 , Math . round ( pageHeight * scaleX ) )
182- : Math . max ( 1 , Math . round ( pageWidth * scaleX ) ) ;
183- const formsHeight = swap
184- ? Math . max ( 1 , Math . round ( pageWidth * scaleY ) )
185- : Math . max ( 1 , Math . round ( pageHeight * scaleY ) ) ;
186-
187- let startX : number ;
188- let startY : number ;
189- switch ( rotation ) {
190- case Rotation . Degree0 :
191- startX = - Math . round ( rectLeft * scaleX ) ;
192- startY = - Math . round ( rectBottom * scaleY ) ;
193- break ;
194- case Rotation . Degree90 :
195- startX = Math . round ( ( rectTop - pageHeight ) * scaleX ) ;
196- startY = - Math . round ( rectLeft * scaleY ) ;
197- break ;
198- case Rotation . Degree180 :
199- startX = Math . round ( ( rectRight - pageWidth ) * scaleX ) ;
200- startY = Math . round ( ( rectTop - pageHeight ) * scaleY ) ;
201- break ;
202- case Rotation . Degree270 :
203- startX = - Math . round ( rectBottom * scaleX ) ;
204- startY = Math . round ( ( rectRight - pageWidth ) * scaleY ) ;
205- break ;
206- default :
207- startX = - Math . round ( rectLeft * scaleX ) ;
208- startY = - Math . round ( rectBottom * scaleY ) ;
209- break ;
210- }
211-
212- return { startX, startY, formsWidth, formsHeight, scaleX, scaleY } ;
213- }
214-
215158const LOG_SOURCE = 'PDFiumEngine' ;
216159const LOG_CATEGORY = 'Engine' ;
217160
@@ -270,8 +213,8 @@ export const browserImageDataToBlobConverter: ImageDataConverter<Blob> = (
270213 return Promise . reject (
271214 new OffscreenCanvasError (
272215 'OffscreenCanvas is not available in this environment. ' +
273- 'This converter is intended for browser use only. ' +
274- 'Falling back to WASM-based image encoding.' ,
216+ 'This converter is intended for browser use only. ' +
217+ 'Falling back to WASM-based image encoding.' ,
275218 ) ,
276219 ) ;
277220 }
@@ -897,9 +840,9 @@ export class PdfiumEngine<T = Blob> implements PdfEngine<T> {
897840 return ok
898841 ? PdfTaskHelper . resolve ( true )
899842 : PdfTaskHelper . reject ( {
900- code : PdfErrorCode . Unknown ,
901- message : 'one or more metadata fields could not be written' ,
902- } ) ;
843+ code : PdfErrorCode . Unknown ,
844+ message : 'one or more metadata fields could not be written' ,
845+ } ) ;
903846 }
904847
905848 /**
@@ -1143,9 +1086,9 @@ export class PdfiumEngine<T = Blob> implements PdfEngine<T> {
11431086 return ok
11441087 ? PdfTaskHelper . resolve ( true )
11451088 : PdfTaskHelper . reject ( {
1146- code : PdfErrorCode . Unknown ,
1147- message : 'failed to clear bookmarks' ,
1148- } ) ;
1089+ code : PdfErrorCode . Unknown ,
1090+ message : 'failed to clear bookmarks' ,
1091+ } ) ;
11491092 }
11501093
11511094 /**
@@ -1643,9 +1586,9 @@ export class PdfiumEngine<T = Blob> implements PdfEngine<T> {
16431586 return ok
16441587 ? PdfTaskHelper . resolve < boolean > ( true )
16451588 : PdfTaskHelper . reject < boolean > ( {
1646- code : PdfErrorCode . CantSetAnnotContent ,
1647- message : 'failed to update annotation' ,
1648- } ) ;
1589+ code : PdfErrorCode . CantSetAnnotContent ,
1590+ message : 'failed to update annotation' ,
1591+ } ) ;
16491592 }
16501593
16511594 /**
@@ -7015,7 +6958,7 @@ export class PdfiumEngine<T = Blob> implements PdfEngine<T> {
70156958 const bytes = stride * hDev ;
70166959
70176960 const pageCtx = ctx . acquirePage ( page . index ) ;
7018- const shouldRenderForms = options ?. renderForms ?? false ;
6961+ const shouldRenderForms = options ?. withForms ?? false ;
70196962 const formHandle = shouldRenderForms ? pageCtx . getFormHandle ( ) : undefined ;
70206963
70216964 // ---- 2) allocate a BGRA bitmap in WASM
@@ -7842,7 +7785,7 @@ export class PdfiumEngine<T = Blob> implements PdfEngine<T> {
78427785
78437786 let cancelled = false ;
78447787 task . wait (
7845- ( ) => { } ,
7788+ ( ) => { } ,
78467789 ( err ) => {
78477790 if ( err . type === 'abort' ) cancelled = true ;
78487791 } ,
@@ -7895,12 +7838,12 @@ export class PdfiumEngine<T = Blob> implements PdfEngine<T> {
78957838
78967839 // Ensure buffer is freed if caller aborts mid-flight
78977840 task . wait (
7898- ( ) => { } ,
7841+ ( ) => { } ,
78997842 ( err ) => {
79007843 if ( err . type === 'abort' ) {
79017844 try {
79027845 this . memoryManager . free ( keywordPtr ) ;
7903- } catch { }
7846+ } catch { }
79047847 }
79057848 } ,
79067849 ) ;
0 commit comments