Repository navigation
SVG: read rgb() with a fractional or percentage alpha - #2197
Merged
andersonhc merged 4 commits intoNov 14, 2026
Merged
Conversation
The 4th value of fpdf2's own rgb(R, G, B, A) is an alpha from 0 to 255, so rgb(0,0,0, 0.5), which Mermaid writes in sequence diagrams, failed with ValueError. A fraction or a percentage can only be the 0-1 alpha that CSS Color 4 allows in rgb().
andersonhc
requested changes
Nov 13, 2026
andersonhc
left a comment
Collaborator
There was a problem hiding this comment.
One small compatibility question: +100 previously used the legacy 0–255 alpha scale, but now becomes fully opaque because isdigit() rejects the leading +. The new result matches CSS, so this may be intentional. Should signed integers retain the legacy behavior too? A test would help make that choice explicit.
andersonhc
approved these changes
Nov 14, 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.
Mermaid writes
stroke="rgb(0,0,0, 0.5)"around therectblocks of sequence diagrams, as in the diagrams of the Making Embedded Systems repository. It fails withValueError: invalid literal for int() with base 10: '0.5'.svgcolor()sends anrgb()with commas to fpdf2's ownrgb(R, G, B, A), whose 4th value is an alpha from 0 to 255, as in thergb(200, 240, 255, 100)of issue #480. A fraction or a percentage can only be the 0-1 alpha that CSS Color 4 allows inrgb(), so such a color is now read likergba(). An integer alpha is still read from 0 to 255.New cases in
parameters.pycoverrgb(0,0,0, 0.5)andrgb(255, 0, 0, 25%); both fail without the change.