Skip to content

Complete mask element implementation#185

Closed
usiegj00 wants to merge 2 commits intomogest:mainfrom
aluminumio:mask
Closed

Complete mask element implementation#185
usiegj00 wants to merge 2 commits intomogest:mainfrom
aluminumio:mask

Conversation

@usiegj00
Copy link

Summary

This PR completes the partial mask element implementation that was started but not finished.

Changes

  • Fixed the apply_mask method to properly work with Prawn's soft_mask API
  • Properly structured soft_mask blocks with nested calls
  • Added proper call context management using push/pop_call_position
  • Process mask children to generate the mask pattern correctly

Problem

The previous partial implementation wasn't correctly handling the soft_mask API which expects drawing commands to be nested within the block. This caused masks to not render properly in PDFs.

Solution

The fix ensures masks work correctly by:

  1. Using save_graphics_state for proper state management
  2. Managing call contexts with push/pop_call_position
  3. Processing mask children in the correct context
  4. Properly nesting mask drawing commands within the soft_mask block

Testing

Tested with various mask types including:

  • Circular masks for QR codes
  • Rectangle masks with gradients
  • Complex mask patterns

All tests pass and masks now render correctly in PDFs.

Fixes the incomplete mask implementation from commit 8fe7d2f.

mogest and others added 2 commits February 3, 2024 18:16
This does not support maskContentUnits="objectBoundingBox" but should
support everything else.

The SVG spec supports masking using images as the mask; it does not
appear PDF is doing this but may be a bug in this code so requires
further investigation.
- Properly structure soft_mask block with nested calls
- Process mask children to generate mask pattern
- Use push/pop_call_position to manage call context
- Add save_graphics_state for proper state management

The previous partial implementation wasn't correctly handling the soft_mask
API which expects drawing commands to be nested within the block. This fix
ensures masks work correctly with circular and other mask shapes.
@mogest
Copy link
Owner

mogest commented Aug 21, 2025

Hi @usiegj00, thanks very much for finishing this off!

I noticed you've made this PR (#185) as well as #186, which look very similar. There are also quite a lot of merge conflicts. Would you be able to prepare a single PR for review? I'd be very happy to bring this work in.

@usiegj00
Copy link
Author

Closing in favor of #186, which supersedes this PR. #186 includes the 1c394d2 soft_mask fix from here and adds complete mask support (including /image-based masks), resolving #148. Let's continue review there. Thanks!

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

Comments