8000 Move listing of Type1 glyph widths to backend_pdf. · matplotlib/matplotlib@41bb3e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 41bb3e5

Browse files
committed
Move listing of Type1 glyph widths to backend_pdf.
DviFont.widths (the widths of each glyph in a font) is only used by backend_pdf to embed (classic, Type1) TeX fonts; deprecate that attribute and instead compute it where needed. This change is in preparation for supporting {xe,lua}tex, where DviFont can also refer to OpenType fonts which would be embedded via a different mechanism into the pdf file, and which can contain so many glyphs that explicitly listing the width of each one would be wasteful.
1 parent a9dc9ac commit 41bb3e5

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``DviFont.widths``
2+
~~~~~~~~~~~~~~~~~~
3+
... is deprecated with no replacement.

lib/matplotlib/backends/backend_pdf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,15 +991,19 @@ def _embedTeXFont(self, fontinfo):
991991

992992
# Widths
993993
widthsObject = self.reserveObject('font widths')
994-
self.writeObject(widthsObject, fontinfo.dvifont.widths)
994+
tfm = fontinfo.dvifont._tfm
995+
# convert from TeX's 12.20 representation to 1/1000 text space units.
996+
widths = [(1000 * tfm.width.get(char, 0)) >> 20
997+
for char in range(max(tfm.width, default=-1) + 1)]
998+
self.writeObject(widthsObject, widths)
995999

9961000
# Font dictionary
9971001
fontdictObject = self.reserveObject('font dictionary')
9981002
fontdict = {
9991003
'Type': Name('Font'),
10001004
'Subtype': Name('Type1'),
10011005
'FirstChar': 0,
1002-
'LastChar': len(fontinfo.dvifont.widths) - 1,
1006+
'LastChar': len(widths) - 1,
10031007
'Widths': widthsObject,
10041008
}
10051009

lib/matplotlib/dviread.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,8 @@ class DviFont:
577577
size : float
578578
Size of the font in Adobe points, converted from the slightly
579579
smaller TeX points.
580-
widths : list
581-
Widths of glyphs in glyph-space units, typically 1/1000ths of
582-
the point size.
583-
584580
"""
585-
__slots__ = ('texname', 'size', 'widths', '_scale', '_vf', '_tfm')
581+
__slots__ = ('texname', 'size', '_scale', '_vf', '_tfm')
586582

587583
def __init__(self, scale, tfm, texname, vf):
588584
_api.check_isinstance(bytes, texname=texname)
@@ -591,12 +587,10 @@ def __init__(self, scale, tfm, texname, vf):
591587
self.texname = texname
592588
self._vf = vf
593589
self.size = scale * (72.0 / (72.27 * 2**16))
594-
try:
595-
nchars = max(tfm.width) + 1
596-
except ValueError:
597-
nchars = 0
598-
self.widths = [(1000*tfm.width.get(char, 0)) >> 20
599-
for char in range(nchars)]
590+
591 5ECA +
widths = _api.deprecated("3.11")(lambda self: [
592+
(1000 * self._tfm.width.get(char, 0)) >> 20
593+
for char in range(max(self._tfm.width, default=-1) + 1)])
600594

601595
def __eq__(self, other):
602596
return (type(self) is type(other)

0 commit comments

Comments
 (0)
0