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

Commit3aaf4c9

Browse files
committed
Type-1 subsetting
With this I can produce smaller pdf files with usetex in some smalltests, but this obviously needs more extensive testing, thus markingas draft.On top of#20715.Closes#127.
1 parent9418b35 commit3aaf4c9

File tree

3 files changed

+286
-13
lines changed

3 files changed

+286
-13
lines changed

‎lib/matplotlib/backends/_backend_pdf_ps.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,25 @@ class CharacterTracker:
2727
def__init__(self):
2828
self.used= {}
2929

30-
deftrack(self,font,s):
31-
"""Record that string *s* is being typeset usingfont *font*."""
30+
@staticmethod
31+
def_get_name(font):
3232
ifisinstance(font,str):
3333
# Unused, can be removed after removal of track_characters.
3434
fname=font
35-
else:
35+
elifhasattr(font,'fname'):
3636
fname=font.fname
37-
self.used.setdefault(fname,set()).update(map(ord,s))
37+
elifhasattr(font,'name'):
38+
fname=font.name
39+
ifisinstance(fname,bytes):
40+
fname=fname.decode('ascii','error')
41+
returnfname
42+
43+
defget_used(self,font,default=None):
44+
returnself.used.get(self._get_name(font),default)
45+
46+
deftrack(self,font,s):
47+
"""Record that string *s* is being typeset using font *font*."""
48+
self.used.setdefault(self._get_name(font),set()).update(map(ord,s))
3849

3950
# Not public, can be removed when pdf/ps merge_used_characters is removed.
4051
defmerge(self,other):

‎lib/matplotlib/backends/backend_pdf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,8 @@ def _embedTeXFont(self, fontinfo):
963963
t1font=type1font.Type1Font(fontinfo.fontfile)
964964
iffontinfo.effects:
965965
t1font=t1font.transform(fontinfo.effects)
966+
chars=self._character_tracker.get_used(fontinfo.pdfname)
967+
t1font=t1font.subset(chars)
966968
fontdict['BaseFont']=Name(t1font.prop['FontName'])
967969

968970
# Font descriptors may be shared between differently encoded
@@ -2227,6 +2229,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
22272229
seq+= [['font',pdfname,dvifont.size]]
22282230
oldfont=dvifont
22292231
seq+= [['text',x1,y1, [bytes([glyph])],x1+width]]
2232+
self.file._character_tracker.track(pdfname,chr(glyph))
22302233

22312234
# Find consecutive text strings with constant y coordinate and
22322235
# combine into a sequence of strings and kerns, or just one

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp