Repository navigation
Read the alpha of #rgba and #rrggbbaa, and clamp colour channels instead of wrapping them - #570
Merged
Merged
Conversation
jakejackson1
force-pushed
the
fix/552-colour-values
branch
from
September 29, 2026 08:29
9e129af to
eaf8d98
Compare
This was referenced Sep 29, 2026
jakejackson1
force-pushed
the
fix/552-space-syntax-colours
branch
from
September 29, 2026 22:26
f92feed to
a56cfee
Compare
jakejackson1
force-pushed
the
fix/552-colour-values
branch
2 times, most recently
from
September 29, 2026 23:03
a033a72 to
b4398f2
Compare
jakejackson1
changed the base branch from
fix/552-space-syntax-colours
to
gravitypdf
September 29, 2026 23:03
jakejackson1
force-pushed
the
fix/552-colour-values
branch
from
September 29, 2026 23:45
b4398f2 to
6a4a5f5
Compare
…ead of wrapping them `#f008` was read from the wrong digits and `#rrggbbaa` lost its alpha. A channel outside its range was masked into a byte, so rgb(255.5, 0, 0) drew black and rgb(300, 0, 0) dark red. Read both hex forms with their alpha, let the background shorthand take an eight-digit colour, clamp channels, alphas and hsl() saturation and lightness to their range, and add rebeccapurple. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakejackson1
force-pushed
the
fix/552-colour-values
branch
from
September 30, 2026 00:17
6a4a5f5 to
fc11cbb
Compare
jakejackson1
added a commit
that referenced
this pull request
Sep 30, 2026
The three sub-bullets under #563's rgb()/hsl() space-syntax entry and the three under #570's colour-values entry lost their two-space indent in later merges, so each read as a bugfix of its own. They are indented under their entries again, as #563 and #570 wrote them. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some colour values were read as a different colour:
background: #f008rgb(240, 8, 0), opaquebackground: #ff000080color: rgb(255.5, 0, 0)color: rgb(300, 0, 0)rgb(44, 0, 0)rgba(0, 0, 255, 1.5)/ca 1.5, outside the range PDF allowscmyk(150, 0, 0, 0)color: rebeccapurple#663399These are the causes:
processHashColor()handled only 3 and 6 digits. The background shorthand also only recognised a hex colour of up to 6 digits.convert()packed each channel withround(...) & 0xFF, which wraps a value outside 0–255 instead of clamping it. For example, 255.5 rounds to 256 and wraps to 0.rebeccapurplewas not inNamedColors.Change
#rgbaand#rrggbbaaare read with their alpha, asrgba()is.rgb()channels are clamped to 0–255,cmyk()components to 0–100, and alphas to 0–1.hsl()saturation and lightness are clamped to 0–100%, and a bare grey number is clamped to 255. This happens inprocessModeColor(), before the PDF/A and PDF/X colour space restrictor sees the colour.backgroundshorthand recognises a hex colour of up to 8 digits.rebeccapurpleis added.violetredis not a CSS colour, but mPDF has always accepted it, so it stays. Removing it would turn existing documents that use it black.Colours inside their range draw the same as before. No existing snapshot fixture changed.
The percentage alpha from #552 (
rgba(255, 0, 0, 50%)writing/ca 1.36) is fixed in #563, because the slash syntax there needs it.Tests
ColorConverterTest::testConvertColorValueschecks the binary colour for each of these:#rgbaand#rrggbbaa, including uppercase, fully opaque and fully transparenthsl()saturation and lightness above 100%cmyk()andcmyka()values out of rangerebeccapurple, andvioletredkeptColorValueTestrenders each case in a paragraph. It asserts the colour operator and opacity drawn, that no/caabove 1 is written, and that nothing warns. It covers#rgbaand#rrggbbaain thebackgroundshorthand and inbackground-color, which exercises the shorthand regex. With theNormalizePropertieschange alone reverted, the shorthand#rrggbbaacase fails. With all source changes reverted, all seven cases fail.ColorValueSnapshotTest(color-value) puts each case under a caption saying what should be seen:rebeccapurpleandvioletredtextRendered before this change:
#f008band is an opaque orange-red and the#0000ff80band is opaque bluerebeccapurpleline is blackChecks
composer test: OK. 4522 tests, 31 skipped for missing optional packages or ungenerated data. The snapshot suite ran with Imagick and Ghostscript.composer cs: clean.--memory-limit=2G).Part of #552. Part of #520.
🤖 Generated with Claude Code