Skip to content

feat(annotations): correct drawing coords on rotated pages#748

Draft
kduncanhsu wants to merge 1 commit intobox:masterfrom
kduncanhsu:fix/annotation-drawing-rotation-coordinate-transform
Draft

feat(annotations): correct drawing coords on rotated pages#748
kduncanhsu wants to merge 1 commit intobox:masterfrom
kduncanhsu:fix/annotation-drawing-rotation-coordinate-transform

Conversation

@kduncanhsu
Copy link
Copy Markdown
Contributor

Summary

Adds support for live annotation drawing on rotated pages/images. This is in preparation for enabling annotation creation on rotated PDFs and images, where the annotation controls were previously hidden. Without this change, simply re-enabling annotation creation controls in the rotated state would cause the live drawing input to be offset from the user’s cursor.

This PR:

  • Applies inverse rotation to convert screen-space mouse coordinates into the annotation layer's local coordinate system
  • Uses offsetWidth/offsetHeight (pre-transform dimensions) for percentage instead of getBoundingClientRect() which returns post-transform AABB dimensions
  • Removes the isRotated guard that blocked region annotation creation on rotated files

For further clarity, here is the live pointer capture flow when drawing annotations:

  1. Mouse events provide clientX/clientY coordinates in screen space.
  2. getPosition applies the inverse rotation transform to convert screen-space coordinates into the annotation layer’s local pre-transform coordinate space (in pixels).
  3. getPoints/getShape normalize those local-space pixel coordinates into percentages using the annotation layer’s pre-transform offsetWidth/offsetHeight.”

Test plan

  • Rotate a PDF 90°, 180°, 270° counterclockwise and verify drawing annotations follow the cursor
  • Rotate an image 90°, 180°, 270° and verify region annotations follow the cursor
  • Verify annotations on unrotated (0°) files still work correctly
  • Verify stored annotations remain anchored to content when rotation changes

When the annotation layer has a CSS rotation transform, mouse coordinates
from getBoundingClientRect() are in screen space but the drawing layer
interprets them in its rotated local frame. This causes live drawing to
appear offset by the rotation angle. Fix by applying the inverse rotation
to convert screen-space coordinates into the element local coordinate
system, and use offsetWidth/offsetHeight for percentage normalization
since these report pre-transform dimensions.

Also removes the isRotated guard that previously blocked region creation
on rotated files, enabling annotations at all rotation angles.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Duncan Hsu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants