-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Watermark functionality enhancements for #3421 #4758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Watermark functionality enhancements for #3421 #4758
Conversation
- Grid layout and random positioning of watermarks per page - Random orientation - Per watermark font randomization of color and size - Text watermark per-letter randomization of font, color, size, and orientation - Sharing - Random mirroring of image watermarks - Add `WatermarkRandomizer` utility and enhance watermark request handling with new validations and randomization features
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive watermark validation and randomization capabilities to the PDF watermarking feature. The changes introduce extensive input validation, advanced watermark customization options (random positioning, rotation ranges, per-letter variations, mirroring, etc.), and deterministic randomness for testing purposes.
Key Changes:
- Added request validation with detailed error messages for watermark parameters
- Introduced
WatermarkRandomizerutility class for deterministic random watermark attributes - Extended watermark request model with 20+ new configuration fields for advanced customization
- Enhanced HTML template with collapsible advanced options and client-side validation
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| WatermarkController.java | Added comprehensive validation logic and refactored watermark rendering to support advanced features |
| AddWatermarkRequest.java | Extended model with validation annotations and new fields for enhanced watermark control |
| WatermarkRandomizer.java | New utility class providing deterministic randomization for watermark attributes |
| add-watermark.html | Enhanced UI with advanced options panel and client-side validation |
| WatermarkValidationTest.java | New test suite validating watermark parameter constraints |
| WatermarkControllerIntegrationTest.java | New integration tests covering various watermark scenarios |
| WatermarkRandomizerTest.java | Comprehensive unit tests for randomizer utility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/resources/templates/security/add-watermark.html
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
…ecurity/WatermarkController.java remove unused variable Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ecurity/WatermarkController.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ecurity/WatermarkController.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ecurity/WatermarkController.java save handling of bound parameters Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ecurity/WatermarkController.java safe handling of bounds Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/prdeploy |
🚀 PR Test DeploymentYour PR has been deployed for testing! 🔗 Test URL: http://185.252.234.121:4758 This deployment will be automatically cleaned up when the PR is closed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I took quick look, made some suggestions.
app/core/src/main/resources/templates/security/add-watermark.html
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Outdated
Show resolved
Hide resolved
app/core/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java
Show resolved
Hide resolved
...re/src/test/java/stirling/software/SPDF/controller/api/security/WatermarkValidationTest.java
Show resolved
Hide resolved
.../java/stirling/software/SPDF/controller/api/security/WatermarkControllerIntegrationTest.java
Show resolved
Hide resolved
balazs-szucs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more suggestions.
app/core/src/main/resources/templates/security/add-watermark.html
Outdated
Show resolved
Hide resolved
app/core/src/main/resources/templates/security/add-watermark.html
Outdated
Show resolved
Hide resolved
app/core/src/main/resources/templates/security/add-watermark.html
Outdated
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/WatermarkRandomizer.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/WatermarkRandomizer.java
Outdated
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/WatermarkRandomizer.java
Show resolved
Hide resolved
app/common/src/main/java/stirling/software/common/util/WatermarkRandomizer.java
Outdated
Show resolved
Hide resolved
…atermarkController
…in WatermarkController
…enable random positioning by default
- Introduced support for translations in watermark advanced options.
- Simplified random position generation by removing `margin` and `bounds` parameters. - Updated `WatermarkRandomizer` to avoid use of obsolete constraints. - Refactored tests to validate new approach while ensuring watermarks stay within page boundaries. - Adjusted UI and localization files to remove unused margin and bounds options.
…transformations - Enhanced text watermark rendering to calculate accurate dimensions for center-point rotation. - Added precise positioning and rotation for individual characters in per-letter variations. - Updated baseline transformations to ensure proper alignment and spacing of characters and lines.
- Introduced `generateRandomPositions` with collision detection and spacing constraints in `WatermarkRandomizer`. - Updated `WatermarkController` to use new method for generating random positions. - Added extensive test coverage for collision detection scenarios in `WatermarkRandomizerTest`.
- Implemented `PDFormXObject` to cache and reuse watermarks across PDF pages. - Adjusted `WatermarkController` to create appearance streams and handle transparency within cached objects. - Improved rendering efficiency by minimizing repetitive operations for each page.
- Moved hardcoded color palette to a static constant `PALETTE`. - Updated methods to use `PALETTE` for consistency and maintainability.
🚀 Translation Verification Summary🔄 Reference Branch:
|
|
/prdeploy |
|
@antonarhipov Is this PR ready? Just looking through the suggested comments from @balazs-szucs and its hard to see which you have addressed as they not been closed/commented on |
🚀 PR Test DeploymentYour PR has been deployed for testing! 🔗 Test URL: http://185.252.234.121:4758 This deployment will be automatically cleaned up when the PR is closed. |
|
@Frooodle, the PR is ready. I'm in doubt about the readability of the WatermarkController logic, though. Let me know if you'd like to refactor it. |
WatermarkRandomizerutility and enhance watermark request handling with new validations and randomization featuresDescription of Changes
Checklist
General
Documentation
UI Changes (if applicable)
Testing (if applicable)