@@ -751,77 +751,6 @@ test('cropByBBox with fitTo should handle zero/negative bbox dimensions', (t) =>
751751 }
752752} )
753753
754- test ( 'cropByBBox should handle invalid padding values' , ( t ) => {
755- const svg = `<svg viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
756- <rect fill="green" x="50" y="50" width="200" height="200"/>
757- </svg>`
758- const resvg = new Resvg ( svg )
759- const bbox = resvg . getBBox ( ) !
760-
761- // Invalid values should silently use 0, not throw
762- t . notThrows ( ( ) => resvg . cropByBBox ( bbox , NaN ) )
763- t . notThrows ( ( ) => resvg . cropByBBox ( bbox , Infinity ) )
764- t . notThrows ( ( ) => resvg . cropByBBox ( bbox , - 10 ) )
765-
766- // padding >= half of dimensions should produce transparent image, not panic
767- t . notThrows ( ( ) => resvg . cropByBBox ( bbox , bbox . width ) )
768- } )
769-
770- test ( 'cropByBBox should handle zero/negative bbox dimensions' , ( t ) => {
771- const svg = `<svg viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
772- <rect fill="green" x="50" y="50" width="200" height="200"/>
773- </svg>`
774- const resvg = new Resvg ( svg )
775- const bbox = resvg . getBBox ( ) !
776-
777- // These should not panic (validation happens in Rust)
778- const zeroBbox = { ...bbox , width : 0 }
779- const negativeBbox = { ...bbox , width : - 10 }
780-
781- // napi-rs may reject invalid BBox objects at type conversion level (InvalidArg)
782- // or at Rust validation level (silently ignored). Both are acceptable.
783- try {
784- resvg . cropByBBox ( zeroBbox as any )
785- t . pass ( 'Zero width bbox handled without panic' )
786- } catch ( e : any ) {
787- t . true ( e . code === 'InvalidArg' , 'Zero width bbox rejected at type level' )
788- }
789-
790- try {
791- resvg . cropByBBox ( negativeBbox as any )
792- t . pass ( 'Negative width bbox handled without panic' )
793- } catch ( e : any ) {
794- t . true ( e . code === 'InvalidArg' , 'Negative width bbox rejected at type level' )
795- }
796- } )
797-
798- test ( 'cropByBBox with fitTo should handle zero/negative bbox dimensions' , ( t ) => {
799- const svg = `<svg viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
800- <rect fill="green" x="50" y="50" width="200" height="200"/>
801- </svg>`
802- const resvg = new Resvg ( svg , { fitTo : { mode : 'width' , value : 500 } } )
803- const bbox = resvg . getBBox ( ) !
804-
805- // Modify bbox to have zero/negative dimensions
806- const zeroBbox = { ...bbox , width : 0 }
807- const negativeBbox = { ...bbox , width : - 10 }
808-
809- // These should not panic with fitTo option
810- try {
811- resvg . cropByBBox ( zeroBbox as any )
812- t . pass ( 'Zero width bbox with fitTo handled without panic' )
813- } catch ( e : any ) {
814- t . true ( e . code === 'InvalidArg' , 'Zero width bbox rejected at type level' )
815- }
816-
817- try {
818- resvg . cropByBBox ( negativeBbox as any )
819- t . pass ( 'Negative width bbox with fitTo handled without panic' )
820- } catch ( e : any ) {
821- t . true ( e . code === 'InvalidArg' , 'Negative width bbox rejected at type level' )
822- }
823- } )
824-
825754test ( 'should render using font buffer provided by options' , async ( t ) => {
826755 const svg = `<svg width='480' height='150' viewBox='-20 -80 550 100' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>
827756 <text x='0' y='0' font-size='100' fill='#000'>Font Buffer</text>
0 commit comments