Skip to content

SVG: read a gradient <stop> without offset as offset 0 - #2164

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:svg-stop-default-offset
Nov 11, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:svg-stop-default-offset

Conversation

@RavSinghChandan

Copy link
Copy Markdown

A <stop> without an offset is skipped with the warning "Found without offset, skipping". But offset is optional: its initial value is 0, so such a stop starts the gradient.

The Hugging Face Hub logo on spaCy's website (website/src/images/logos/huggingface_hub.svg) and spaCy's pipeline-design.svg both write their first stop like this:

<stop stop-color="#00183D"/>
<stop offset="1" stop-color="#0E0E0E"/>

so the text of the Hugging Face logo comes out flat black instead of going from navy to black.

_parse_gradient_stops() now reads a missing offset as 0.

test_gradient_stop_without_offset checks that both stops are read; it fails on master. The SVG tests, black, pylint, mypy and pyright pass

@agustin18

Copy link
Copy Markdown

This matches the SVG spec: offset is optional and its initial value is 0. One edge case still slips through, not blocking: offset="" (present but empty) reaches float("") and raises ValueError, which aborts the whole SVG. A fallback to 0 would make it consistent with the missing-offset case.

@andersonhc
andersonhc merged commit a8bcddf into py-pdf:master Nov 11, 2026
23 checks passed
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.

3 participants