@@ -270,18 +270,11 @@ const normalizeCaptureRect = (value: unknown): PreviewAnnotationRect | null => {
270270 ) {
271271 return null ;
272272 }
273- return {
274- x : Math . floor ( x ) ,
275- y : Math . floor ( y ) ,
276- width : Math . max ( 1 , Math . ceil ( width ) ) ,
277- height : Math . max ( 1 , Math . ceil ( height ) ) ,
278- } ;
273+ return { x, y, width, height } ;
279274} ;
280275
281- /**
282- * Crops a viewport capture to a picked annotation. `cropRect` is in CSS px;
283- * the capture's pixels are CSS px × the guest's `devicePixelRatio`.
284- */
276+ // capturePage returns a 1x NativeImage containing device pixels, so crop() uses
277+ // CSS coordinates scaled by the guest's devicePixelRatio (including page zoom).
285278const cropAnnotationScreenshot = (
286279 image : Electron . NativeImage ,
287280 cropRect : PreviewAnnotationRect | null ,
@@ -291,17 +284,17 @@ const cropAnnotationScreenshot = (
291284 const full = image . getSize ( ) ;
292285 if ( full . width <= 0 || full . height <= 0 ) return null ;
293286 const scale = Number . isFinite ( devicePixelRatio ) && devicePixelRatio > 0 ? devicePixelRatio : 1 ;
294- // Padding and unions can overlap the viewport without any selected target.
295- // Check the individual unpadded bounds before accepting even a full capture.
296- // Zero-size bounds stay eligible: a stroked SVG line reports zero height.
287+ // Padding or a union of offscreen targets can overlap an empty viewport area.
288+ // A zero-width/height SVG line can still paint at the top or left edge.
297289 if (
298290 targetRects . length > 0 &&
299291 ! targetRects . some (
300292 ( rect ) =>
293+ ( rect . width > 0 || rect . height > 0 ) &&
301294 rect . x * scale < full . width &&
302295 rect . y * scale < full . height &&
303- ( rect . x + rect . width ) * scale > 0 &&
304- ( rect . y + rect . height ) * scale > 0 ,
296+ ( rect . width === 0 ? rect . x >= 0 : rect . x + rect . width > 0 ) &&
297+ ( rect . height === 0 ? rect . y >= 0 : rect . y + rect . height > 0 ) ,
305298 )
306299 ) {
307300 return null ;
@@ -328,6 +321,7 @@ const cropAnnotationScreenshot = (
328321 height : bottom - y ,
329322 } ) ;
330323 const size = cropped . getSize ( ) ;
324+ if ( size . width <= 0 || size . height <= 0 ) return null ;
331325 return { dataUrl : cropped . toDataURL ( ) , width : size . width , height : size . height , cropRect } ;
332326} ;
333327
0 commit comments