Skip to content

Commit

Permalink
Try to install the Noto Sans CJK font
Browse files Browse the repository at this point in the history
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
(matplotlib#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.
  • Loading branch information
jkseppan committed Aug 20, 2021
1 parent a4e81e7 commit bf38aa9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ commands:
fonts-crosextra-carlito \
fonts-freefont-otf \
fonts-humor-sans \
fonts-noto-cjk \
optipng
fonts-install:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
cm-super \
dvipng \
ffmpeg \
fonts-noto-cjk \
gdb \
gir1.2-gtk-3.0 \
graphviz \
Expand Down Expand Up @@ -101,6 +102,8 @@ jobs:
;;
macOS)
brew install ccache
brew tap homebrew/cask-fonts
brew install font-noto-sans-cjk-sc
;;
esac
Expand Down
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ stages:
cm-super \
dvipng \
ffmpeg \
fonts-noto-cjk \
gdb \
gir1.2-gtk-3.0 \
graphviz \
Expand All @@ -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)
;;
Expand Down
17 changes: 14 additions & 3 deletions lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

Expand Down

0 comments on commit bf38aa9

Please sign in to comment.