From bf38aa942efd7421b1ebcf91619ab5de1cdcea28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Sepp=C3=A4nen?= Date: Tue, 17 Aug 2021 17:13:57 +0300 Subject: [PATCH] Try to install the Noto Sans CJK font On Linux and Mac. Add a font_manager test that loads the font and uses it. This could be useful in testing the multi-font support (#20740 etc). I couldn't get the font installed on Windows. There is a Chocolatey installer that installs all of the Noto fonts, which takes a really long time to run. --- .circleci/config.yml | 1 + .github/workflows/tests.yml | 3 +++ azure-pipelines.yml | 3 +++ lib/matplotlib/tests/test_font_manager.py | 17 ++++++++++++++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bade4c7042a6..713b160661fd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,6 +59,7 @@ commands: fonts-crosextra-carlito \ fonts-freefont-otf \ fonts-humor-sans \ + fonts-noto-cjk \ optipng fonts-install: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 84c73e3e3289..bb7c47f888f6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -65,6 +65,7 @@ jobs: cm-super \ dvipng \ ffmpeg \ + fonts-noto-cjk \ gdb \ gir1.2-gtk-3.0 \ graphviz \ @@ -101,6 +102,8 @@ jobs: ;; macOS) brew install ccache + brew tap homebrew/cask-fonts + brew install font-noto-sans-cjk-sc ;; esac diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5d51afa86f67..13e6d709c42f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -82,6 +82,7 @@ stages: cm-super \ dvipng \ ffmpeg \ + fonts-noto-cjk \ gdb \ gir1.2-gtk-3.0 \ graphviz \ @@ -102,6 +103,8 @@ stages: darwin) brew install --cask xquartz brew install pkg-config ffmpeg imagemagick mplayer ccache + brew tap homebrew/cask-fonts + brew install font-noto-sans-cjk-sc ;; win32) ;; diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index 4cad797b3757..ee62120c1e37 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -101,7 +101,7 @@ def test_utf16m_sfnt(): entry = next(entry for entry in fontManager.ttflist if Path(entry.fname).name == "seguisbi.ttf") except StopIteration: - pytest.skip("Couldn't find font to test against.") + pytest.skip("Couldn't find seguisbi.ttf font to test against.") else: # Check that we successfully read "semibold" from the font's sfnt table # and set its weight accordingly. @@ -111,14 +111,25 @@ def test_utf16m_sfnt(): def test_find_ttc(): fp = FontProperties(family=["WenQuanYi Zen Hei"]) if Path(findfont(fp)).name != "wqy-zenhei.ttc": - pytest.skip("Font may be missing") - + pytest.skip("Font wqy-zenhei.ttc may be missing") fig, ax = plt.subplots() ax.text(.5, .5, "\N{KANGXI RADICAL DRAGON}", fontproperties=fp) for fmt in ["raw", "svg", "pdf", "ps"]: fig.savefig(BytesIO(), format=fmt) +def test_find_noto(): + fp = FontProperties(family=["Noto Sans CJK SC", "Noto Sans CJK JP"]) + name = Path(findfont(fp)).name + if name not in ("NotoSansCJKsc-Regular.otf", "NotoSansCJK-Regular.ttc"): + pytest.skip(f"Noto Sans CJK SC font may be missing (found {name})") + + fig, ax = plt.subplots() + ax.text(0.5, 0.5, 'Hello, 你好', fontproperties=fp) + for fmt in ["raw", "svg", "pdf", "ps"]: + fig.savefig(BytesIO(), format=fmt) + + def test_find_invalid(tmpdir): tmp_path = Path(tmpdir)