Skip to content

Commit 64ff405

Browse files
committed
Use area-based stroke scaling for ink resize
Replace the previous min-based uniform scale with an area-based stroke scaling to make side-handle resizes reversible. Compute separate width/height scales with safety guards against zero dimensions, derive strokeScale via sqrt(widthScale*heightScale), and remove integer rounding when computing newStrokeWidth (still clamped to a minimum of 1). Adds explanatory comment and avoids division-by-zero by using Math.max on denominators.
1 parent e2563ef commit 64ff405

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • packages/plugin-annotation/src/lib/patching/patches

packages/plugin-annotation/src/lib/patching/patches/ink.patch.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ export const patchInk: PatchFunction<PdfInkAnnoObject> = (original, ctx) => {
4848
},
4949
});
5050

51-
const strokeScale = Math.min(
52-
resolvedRect.size.width / oldRect.size.width,
53-
resolvedRect.size.height / oldRect.size.height,
54-
);
55-
const newStrokeWidth = Math.max(1, Math.round(original.strokeWidth * strokeScale));
51+
const widthScale = resolvedRect.size.width / Math.max(oldRect.size.width, 1e-6);
52+
const heightScale = resolvedRect.size.height / Math.max(oldRect.size.height, 1e-6);
53+
// Area-based stroke scaling keeps side-handle resize reversible:
54+
// shrinking on one axis thins the stroke, and growing that axis restores it.
55+
const strokeScale = Math.sqrt(Math.max(widthScale, 1e-6) * Math.max(heightScale, 1e-6));
56+
const newStrokeWidth = Math.max(1, original.strokeWidth * strokeScale);
5657

5758
const innerOld = inset(oldRect, original.strokeWidth / 2);
5859
const innerNew = inset(resolvedRect, newStrokeWidth / 2);

0 commit comments

Comments
 (0)