Skip to content

fix(watermark): align canvas rotation with PDF CCW convention - #15

Merged
gzz727007 merged 1 commit into
mainfrom
fix/watermark-rotation-sign
Sep 29, 2026
Merged

gzz727007 merged 1 commit into
mainfrom
fix/watermark-rotation-sign

Conversation

@gzz727007

Copy link
Copy Markdown
Member

🦭 Pull Request Description

Summary of Changes

Watermark rotation was mirrored: setting -45° in the UI produced a watermark that looked like +45° (and vice versa).

Root cause: PDF user space is Y-up — positive angles rotate counterclockwise (ISO 32000; matches Adobe Acrobat). Canvas 2D is Y-down (screen raster), so a positive angle visually rotates clockwise. The raw user-facing angle was passed to ctx.rotate() without sign conversion, while the pdf-lib fallback branch (rotate: degrees(rotation)) already followed the PDF convention — the two render paths even disagreed with each other.

Fix (sign-only, 3 sites):

  • src/tools/WatermarkTool.vue — live preview canvas: rotate((-wmAngle * π) / 180)
  • src/tools/WatermarkTool.vue — export stamping canvas: same negation
  • src/utils/pipeline/nodes/watermarkNode.js — pipeline Canvas branch: rotate((-rotation * π) / 180), now visually consistent with the degrees(rotation) fallback in the same file

After this change all paths share one convention: positive = counterclockwise, so -45° renders as \ and +45° as /, consistent with Acrobat and pdf-lib. No changes to query-param parsing (angle still clamped to -90..90) or stored settings.

Type of Change

  • 🐛 Bug fix (non-breaking change fixing an issue)

🛡️ Privacy & Quality Checklist

  • 100% Client-Side Invariant: All code runs strictly in the browser RAM / WebAssembly. No user documents or telemetry data are ever sent over the network. (sign-only change; no network/IO code touched)
  • Automated Tests: I have verified that all existing tests pass (npm test). (vitest: tests/watermark.test.js + tests/toolQueryParams.test.js, 24/24 passed)
  • New Tests Added: Canvas raster path is not executable in Node (no canvas — the pipeline node falls back to the pdf-lib branch, which was already correct and is covered). Recommend a follow-up e2e visual assertion for angle directions.
  • Responsive & Cross-Browser: Verified that UI works smoothly across desktop and mobile screens. (no layout/CSS changes; recommend a quick manual check of -45°/+45° preview before merge)
  • Self-Review: I have performed a self-review of my own code and removed unnecessary console.log statements.

Related Issues

Closes #

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
pdfseal 01f305b Commit Preview URL

Branch Preview URL
Sep 29 2026, 01:40 PM

@gzz727007
gzz727007 merged commit 90ebe5d into main Sep 29, 2026
4 checks passed
@gzz727007
gzz727007 deleted the fix/watermark-rotation-sign branch September 29, 2026 13:46
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.

1 participant