Skip to content

Paint SVG gradient stops opaque under PDF/A-1b, and write only the visibility groups the catalog lists (#346, #351) - #386

Merged
jakejackson1 merged 3 commits into
feature/pdfa-2-conformancefrom
fix/346-svg-stop-opacity
Sep 23, 2026
Merged

jakejackson1 merged 3 commits into
feature/pdfa-2-conformancefrom
fix/346-svg-stop-opacity

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Follow-ups to #346 and #351 found by a verification pass over #330.

Changes

SVG gradient stop-opacity under PDF/A-1b and PDF/X-1a (#346). A <stop> with stop-opacity below 1 made a linear or radial gradient fade through a soft mask. veraPDF rejects that under PDF/A-1b (6.4-1). Without PDFAauto no warning was recorded, so the invalid file was written without complaint. The stop opacity now goes through Mpdf::allowedAlpha() where stops are parsed, as the other SVG opacities do: with PDFAauto the stop is painted opaque, and without it the warning is recorded. PDF/X-1a had the same problem and gets the same fix.

Optional content groups the catalog does not list (#351). Using any one of print-only, screen-only or hidden content wrote all three OCG objects and named all three in the page /Properties. /OCProperties /OCGs listed only the ones in use, but it should list every OCG in the document. OptionalContentWriter now writes only the groups in use. The page resources and the catalog both read the object numbers it records, so the bit-to-group mapping lives in one place (OptionalContentWriter::VISIBILITY_GROUPS). This applies to documents that are not PDF/A as well. veraPDF accepted the files both before and after this change, so the test checks the written objects directly.

Opaque rgba()/cmyka() under PDF/A-1. Without PDFAauto, rgba(255, 0, 0, 1) was reported as transparency dropped, though dropping an alpha of 1 changes nothing. Only an alpha below 1 is reported now. The PDF/X and CMYK-intent warning for an rgba() converted to CMYK stays, because the colour space does change.

The #351 policy of refusing printonly/screenonly under PDF/A-2/3 is unchanged.

Not changed here: in the stop parser, an rgba()/cmyka() stop colour's alpha is read with ord($col[4] / 100) (src/Image/Svg.php). That looks wrong but predates this branch.

Tests

  • PDFA1Test: linear and radial gradient stops under PDF/A-1b, PDF/A-2b and PDF/X-1a write a soft mask only under PDF/A-2b. Without PDFAauto, PDF/A-1b reports the stop opacity.
  • PdfaConformanceTest: the shared document now includes a linear and a radial gradient with a translucent stop, so veraPDF checks them at 1-B, 2-B/U and 3-B/U.
  • PdfaOptionalContentTest::testEveryGroupWrittenIsListed: every /Type /OCG object written appears in /OCGs and in the page /Properties, and nothing else does (PDF/A-2b with layers and hidden content, plain print-only, plain print-only plus hidden).
  • ColorSpaceRestrictorTest::testOpaqueAlphaIsNotReported.

Each new test failed before its fix.

Verification

  • veraPDF 1b on the repro, before: linear and radial stop-opacity failed 6.4-1, with or without PDFAauto. After: both compliant. With PDFAauto off, the warning is recorded.
  • composer test: 3375 tests, OK (5 skipped, as before).
  • composer test -- --group=snapshot: 85 OK, no fixture changes.
  • composer test -- --group=conformance: 16 OK.
  • composer cs: clean.
  • PHPStan 2.2: no errors.

🤖 Generated with Claude Code

jakejackson1 and others added 3 commits September 23, 2026 13:40
…346)

An SVG linear or radial gradient with a stop-opacity below 1 faded through a
soft mask under PDF/A-1b and PDF/X-1a, which veraPDF rejects under 6.4-1, and
without PDFAauto no warning was recorded. The stop opacity now goes through
Mpdf::allowedAlpha(), as the other SVG opacities do.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…s every group written (#351)

The print-only, screen-only and hidden optional content groups were all
written, and named in the page resources, as soon as any one was used, while
/OCProperties /OCGs listed only the ones used. /OCGs should list every group
in the document. Now the groups not used are neither written nor named.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…er PDF/A-1

Without PDFAauto, rgba(255, 0, 0, 1) was reported as an RGB colour with
transparency converted without it, though dropping an alpha of 1 changes
nothing. Only a colour whose alpha is below 1 is reported now.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1 jakejackson1 added the bug Something isn't working label Sep 23, 2026
@jakejackson1
jakejackson1 merged commit 864533b into feature/pdfa-2-conformance Sep 23, 2026
29 checks passed
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
@jakejackson1
jakejackson1 deleted the fix/346-svg-stop-opacity branch September 30, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant