Skip to content

SVG: size a root <svg> with width or height auto like one without - #2174

Merged
andersonhc merged 5 commits into
py-pdf:masterfrom
RavSinghChandan:svg-root-size-auto
Nov 13, 2026
Merged

andersonhc merged 5 commits into
py-pdf:masterfrom
RavSinghChandan:svg-root-size-auto

Conversation

@RavSinghChandan

Copy link
Copy Markdown

Figma exports write width="auto" height="auto" on the root <svg>, with a viewBox. The country flags in the ProtonVPN apps are like that, for example proton/vpn/app/gtk/assets/icons/flags/jp.svg in ProtonVPN/proton-vpn-gtk-app:

<svg width="auto" height="auto" viewBox="0 0 24 16" fill="none" xmlns="http://www.w3.org/2000/svg">

pdf.image() fails on them:

ValueError: Unable to parse 'auto' as a length

auto is now read like a missing width or height, so the image is sized from its viewBox. With w=48 it is 48×32, keeping the flag's 3:2 ratio. Reading it as 100% would give 50×50 there.

test_document_size_auto covers both attributes, uppercase and padded with spaces; it fails without the change.

Figma writes width="auto" height="auto" with a viewBox, as in the
country flags of the ProtonVPN apps; it failed with ValueError: Unable
to parse 'auto' as a length.
@andersonhc
andersonhc merged commit 700ef78 into py-pdf:master Nov 13, 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.

2 participants