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

Commitb67da2b

Browse files
committed
Support (first font of) TTC files.
TTC is a TrueType Collection file (a collection of TTFs). Currently,ft2font only supports getting the first font from the collection, andneither the pdf nor ps backends are able to use them (due to limitationsof ttconv). Still, it seems better than nothing to support them for Aggand SVG (that comes for free via FreeType).
1 parent2ac048b commitb67da2b

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

‎.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ addons:
4040
-texlive-latex-recommended
4141
-texlive-xetex
4242
-texlive-luatex
43+
-ttf-wqy-zenhei
4344

4445
env:
4546
global:

‎lib/matplotlib/backends/backend_pdf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,13 @@ def get_char_width(charcode):
968968

969969
# Make the charprocs array (using ttconv to generate the
970970
# actual outlines)
971-
rawcharprocs=ttconv.get_pdf_charprocs(
972-
os.fsencode(filename),glyph_ids)
971+
try:
972+
rawcharprocs=ttconv.get_pdf_charprocs(
973+
os.fsencode(filename),glyph_ids)
974+
exceptRuntimeError:
975+
_log.warning("The PDF backend does not currently support the "
976+
"selected font.")
977+
raise
973978
charprocs= {}
974979
forcharnameinsorted(rawcharprocs):
975980
stream=rawcharprocs[charname]

‎lib/matplotlib/backends/backend_ps.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,14 @@ def print_figure_impl(fh):
11411141
"time; consider using the Cairo backend")
11421142
else:
11431143
fh.flush()
1144-
convert_ttf_to_ps(os.fsencode(font_filename),
1145-
fh,fonttype,glyph_ids)
1144+
try:
1145+
convert_ttf_to_ps(os.fsencode(font_filename),
1146+
fh,fonttype,glyph_ids)
1147+
exceptRuntimeError:
1148+
_log.warning("The PostScript backend does not "
1149+
"currently support the selected "
1150+
"font.")
1151+
raise
11461152
print("end",file=fh)
11471153
print("%%EndProlog",file=fh)
11481154

‎lib/matplotlib/font_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def get_fontext_synonyms(fontext):
142142
Return a list of file extensions extensions that are synonyms for
143143
the given file extension *fileext*.
144144
"""
145-
return {'ttf':('ttf','otf'),
146-
'otf':('ttf','otf'),
147-
'afm':('afm',)}[fontext]
145+
return {'ttf':['ttf','ttc','otf'],
146+
'otf':['ttf','otf'],
147+
'afm':['afm']}[fontext]
148148

149149

150150
deflist_fonts(directory,extensions):

‎lib/matplotlib/tests/test_font_manager.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
fromioimportBytesIO
12
importos
23
importshutil
34
importtempfile
@@ -9,7 +10,7 @@
910
frommatplotlib.font_managerimport (
1011
findfont,FontProperties,fontManager,json_dump,json_load,get_font,
1112
get_fontconfig_fonts,is_opentype_cff_font)
12-
frommatplotlibimportrc_context
13+
frommatplotlibimportpyplotasplt,rc_context
1314

1415
has_fclist=shutil.which('fc-list')isnotNone
1516

@@ -96,3 +97,19 @@ def test_hinting_factor(factor):
9697
# Check that hinting only changes text layout by a small (10%) amount.
9798
np.testing.assert_allclose(hinted_font.get_width_height(),expected,
9899
rtol=0.1)
100+
101+
102+
@pytest.mark.xfail(notos.environ.get("TRAVIS"),reason="Font may be missing.")
103+
deftest_find_ttc():
104+
fp=FontProperties(family=["WenQuanYi Zen Hei"])
105+
font=findfont(fp)
106+
assertos.path.basename(font)=="wqy-zenhei.ttc"
107+
108+
fig,ax=plt.subplots()
109+
ax.text(.5,.5,"\N{KANGXI RADICAL DRAGON}",fontproperties=fp)
110+
fig.savefig(BytesIO(),format="raw")
111+
fig.savefig(BytesIO(),format="svg")
112+
withpytest.raises(RuntimeError):
113+
fig.savefig(BytesIO(),format="pdf")
114+
withpytest.raises(RuntimeError):
115+
fig.savefig(BytesIO(),format="ps")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp