Skip to content

Commit

Permalink
Add svg_usefonts themeable
Browse files Browse the repository at this point in the history
closes #756
  • Loading branch information
has2k1 committed Apr 25, 2024
1 parent 72d5595 commit 18a82c3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/_quartodoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ quartodoc:
- strip_text_x
- strip_text_y
- subplots_adjust
- svg_usefonts
- text
- title

Expand Down
5 changes: 5 additions & 0 deletions doc/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ title: Changelog
- Fixed images generated in quarto so that they have the dimensions
(taking the dpi into account) that are specified in theme. ({{< issue 773 >}})

### New

- Added themeable [](:class:`~plotnine.themes.themeable.svg_usefonts`).
({{< issue 756 >}})

### Enhancements

- Added _palmerpenguins_ dataset.
Expand Down
1 change: 1 addition & 0 deletions plotnine/themes/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def __init__(
strip_align_x=None,
strip_align_y=None,
strip_align=None,
svg_usefonts=None,
**kwargs,
):
self.themeables = Themeables()
Expand Down
27 changes: 27 additions & 0 deletions plotnine/themes/themeable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,33 @@ class strip_align(strip_align_x, strip_align_y):
"""


class svg_usefonts(themeable):
"""
How to renderer fonts for svg images
Parameters
----------
theme_element : bool
If `True`, assume fonts are installed on the machine where
the SVG will be viewed.
If `False`, embed characters as paths; this is supported by
most SVG renderers.
You should probably set this to `True` if you intend to edit
the svg file.
"""

@property
def rcParams(self) -> dict[str, Any]:
rcParams = super().rcParams

rcParams["svg.fonttype"] = (
"none" if self.properties.get("value") else "path"
)
return rcParams


# Deprecated


Expand Down

0 comments on commit 18a82c3

Please sign in to comment.