Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default',

* Chinese translation of the [Tuto 7 - Creating PDF/A Documents](https://py-pdf.github.io/fpdf2/Tutorial-zh.html#-pdfa) tutorial section - _cf._ [issue #267](https://github.com/py-pdf/fpdf2/issues/267) - _cf._ [PR #2138](https://github.com/py-pdf/fpdf2/pull/2138) - thanks to @zheng-guannan577*
### Fixed
* SVG: `currentColor` and `inherit` are now read regardless of case, like the color keywords, so `fill="currentcolor"`, as in the Font Awesome icons of many web pages, no longer fails with `ValueError: unsupported color specification currentcolor` - thanks to @RavSinghChandan
* SVG: black or gray text no longer fails with an `AssertionError` when it is in a `<tspan>` that has its own style, as in every text written by Inkscape: the check on the text color left out `DeviceGray`, the color fpdf2 uses for black and gray - thanks to @RavSinghChandan
* SVG: an image without an `xmlns` declaration no longer fails with `ValueError: substring not found` when it contains a tag that is not supported, such as `<title>` or `<script>`; the tag is skipped with a warning, as in an image that declares the namespace - thanks to @RavSinghChandan
* `FPDF.text()` raises a clear `ValueError` for a NaN or infinite `x` or `y`, like `FPDF.set_xy()`, instead of writing `nan` or `inf` into the page, which is not a valid PDF number - thanks to @RavSinghChandan
Expand Down
3 changes: 2 additions & 1 deletion fpdf/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ def converter(value: str) -> float:
def inheritable(
value: str, converter: Callable[[str], Any] = lambda value: value
) -> Any:
if value in ("inherit", "currentColor"):
# keywords are ASCII case-insensitive in SVG/CSS: "currentcolor" is "currentColor"
if isinstance(value, str) and value.strip().lower() in ("inherit", "currentcolor"):
return GraphicsStyle.INHERIT
return converter(value)

Expand Down
13 changes: 13 additions & 0 deletions test/svg/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,19 @@ def Gs(**kwargs):
no_error(),
id="fill color inherit",
),
# as in the Font Awesome icons of web pages
pytest.param(
'<path fill="currentcolor"/>',
Gs(fill_color=GraphicsStyle.INHERIT),
no_error(),
id="fill color currentcolor lowercase",
),
pytest.param(
'<path stroke="CurrentColor"/>',
Gs(stroke_color=GraphicsStyle.INHERIT),
no_error(),
id="stroke color CurrentColor",
),
pytest.param(
'<path fill="black"/>',
Gs(fill_color="#000"),
Expand Down
Loading