Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix issue with PGF backend not falling back to default LaTeX fonts.#22111

Draft
oscargus wants to merge 1 commit intomatplotlib:mainfrom
oscargus:pgffonts
Draft

Fix issue with PGF backend not falling back to default LaTeX fonts.#22111
oscargus wants to merge 1 commit intomatplotlib:mainfrom
oscargus:pgffonts

Conversation

@oscargus
Copy link
Member

PR Summary

Fixes#20850
Closes#20945

Seems like a minor fix, so not "What's new" required?

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

@oscargusoscargus changed the titleUpdated example to actually use PGF backend.Fixed issue with PGF backend not falling back to default LaTeX fonts.Jan 5, 2022
@oscargus
Copy link
MemberAuthor

The main question is if it should fall back to LaTeX or matplotlibfonts in general. Now it will always fall back to LaTeX rather than matplotlib (which doesn't seem to work properly on my Windows machine anyway...).

@oscargusoscargus marked this pull request as draftJanuary 5, 2022 17:10
@oscargusoscargus changed the titleFixed issue with PGF backend not falling back to default LaTeX fonts.Fix issue with PGF backend not falling back to default LaTeX fonts.Jul 7, 2022
@oscargus
Copy link
MemberAuthor

I updated it, but now (I do not recall the previous status), we instead get a different warning message (and no plot shown):

https://output.circle-artifacts.com/output/job/cf13447f-3f64-4525-b922-393905dac3b6/artifacts/0/doc/build/html/gallery/userdemo/pgf_fonts.html?highlight=pgf

@anntzer
Copy link
Contributor

Good catch, the error makes sense, we need something like

diff --git i/lib/matplotlib/backends/backend_pgf.py w/lib/matplotlib/backends/backend_pgf.pyindex 255714a7ea..a8f2587b9e 100644--- i/lib/matplotlib/backends/backend_pgf.py+++ w/lib/matplotlib/backends/backend_pgf.py@@ -151,16 +151,27 @@ def _escape_and_apply_props(s, prop):     """     commands = []-    families = {"serif": r"\rmfamily", "sans": r"\sffamily",-                "sans-serif": r"\sffamily", "monospace": r"\ttfamily"}+    standard_families = {+        "serif": r"\rmfamily",+        "sans": r"\sffamily",  # Doesn't match FontManager, perhaps deprecate?+        "sans-serif": r"\sffamily",+        "sans serif": r"\sffamily",+        "monospace": r"\ttfamily",+    }     family = prop.get_family()[0]-    if family in families:-        commands.append(families[family])-    elif (any(font.name == family for font in fm.fontManager.ttflist)-          and mpl.rcParams["pgf.texsystem"] != "pdflatex"):-        commands.append(r"\setmainfont{%s}\rmfamily" % family)+    if family in standard_families:+        commands.append(standard_families[family])     else:-        _log.warning("Ignoring unknown font: %s", family)+        if family in fm.font_family_aliases:  # Only cursive & fantasy remain.+            path = fm.findfont(family)+            names = [fe.name for fe in fm.fontManager.ttflist+                     if fe.fname == path]+            family = names[0]+        if (any(font.name == family for font in fm.fontManager.ttflist)+                and mpl.rcParams["pgf.texsystem"] != "pdflatex"):+            commands.append(r"\setmainfont{%s}\rmfamily" % family)+        else:+            _log.warning("Ignoring unknown font: %s", family)      size = prop.get_size_in_points()     commands.append(r"\fontsize{%f}{%f}" % (size, size * 1.2))

(Perhaps nicer would be to have a variant of findfont which directly returns the correct FontEntry rather than just the path, as this avoids having to try to get back to the FontEntry from the path which may fail if we don't have a bijection. Also once we have both the family and the path, we can additionally explicitly set the font path for tex similarly to how it's already done in _get_preamble.)

# with backslashes.
# 2) The dirname needs to include a separator.
path = pathlib.Path(fm.findfont(family,
fallback_to_default=False))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

minor nit: only the findfont call should be wrapped in the try... except; this makes it clearer that you're catching failures of findfont and not e.g. findfont returning an invalid value for Path(). (Plus this avoids the awkward linebreak.)

@github-actions
Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actionsgithub-actionsbot added the status: inactiveMarked by the “Stale” Github Action labelDec 31, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@anntzeranntzeranntzer left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

backend: pgfstatus: inactiveMarked by the “Stale” Github Actionstatus: needs rebase

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug]: Warning: Font Family not found

2 participants

@oscargus@anntzer

[8]ページ先頭

©2009-2026 Movatter.jp