Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf38aa9

Browse files
committed
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.
1 parent a4e81e7 commit bf38aa9

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ commands:
5959
fonts-crosextra-carlito \
6060
fonts-freefont-otf \
6161
fonts-humor-sans \
62+
fonts-noto-cjk \
6263
optipng
6364
6465
fonts-install:

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
cm-super \
6666
dvipng \
6767
ffmpeg \
68+
fonts-noto-cjk \
6869
gdb \
6970
gir1.2-gtk-3.0 \
7071
graphviz \
@@ -101,6 +102,8 @@ jobs:
101102
;;
102103
macOS)
103104
brew install ccache
105+
brew tap homebrew/cask-fonts
106+
brew install font-noto-sans-cjk-sc
104107
;;
105108
esac
106109

azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ stages:
8282
cm-super \
8383
dvipng \
8484
ffmpeg \
85+
fonts-noto-cjk \
8586
gdb \
8687
gir1.2-gtk-3.0 \
8788
graphviz \
@@ -102,6 +103,8 @@ stages:
102103
darwin)
103104
brew install --cask xquartz
104105
brew install pkg-config ffmpeg imagemagick mplayer ccache
106+
brew tap homebrew/cask-fonts
107+
brew install font-noto-sans-cjk-sc
105108
;;
106109
win32)
107110
;;

lib/matplotlib/tests/test_font_manager.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_utf16m_sfnt():
101101
entry = next(entry for entry in fontManager.ttflist
102102
if Path(entry.fname).name == "seguisbi.ttf")
103103
except StopIteration:
104-
pytest.skip("Couldn't find font to test against.")
104+
pytest.skip("Couldn't find seguisbi.ttf font to test against.")
105105
else:
106106
# Check that we successfully read "semibold" from the font's sfnt table
107107
# and set its weight accordingly.
@@ -111,14 +111,25 @@ def test_utf16m_sfnt():
111111
def test_find_ttc():
112112
fp = FontProperties(family=["WenQuanYi Zen Hei"])
113113
if Path(findfont(fp)).name != "wqy-zenhei.ttc":
114-
pytest.skip("Font may be missing")
115-
114+
pytest.skip("Font wqy-zenhei.ttc may be missing")
116115
fig, ax = plt.subplots()
117116
ax.text(.5, .5, "\N{KANGXI RADICAL DRAGON}", fontproperties=fp)
118117
for fmt in ["raw", "svg", "pdf", "ps"]:
119118
fig.savefig(BytesIO(), format=fmt)
120119

121120

121+
def test_find_noto():
122+
fp = FontProperties(family=["Noto Sans CJK SC", "Noto Sans CJK JP"])
123+
name = Path(findfont(fp)).name
124+
if name not in ("NotoSansCJKsc-Regular.otf", "NotoSansCJK-Regular.ttc"):
125+
pytest.skip(f"Noto Sans CJK SC font may be missing (found {name})")
126+
127+
fig, ax = plt.subplots()
128+
ax.text(0.5, 0.5, 'Hello, 你好', fontproperties=fp)
129+
for fmt in ["raw", "svg", "pdf", "ps"]:
130+
fig.savefig(BytesIO(), format=fmt)
131+
132+
122133
def test_find_invalid(tmpdir):
123134
tmp_path = Path(tmpdir)
124135

0 commit comments

Comments
 (0)