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

Appearance settings

Commit cb5d039

Browse filesBrowse 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 cb5d039
Copy full SHA for cb5d039

4 files changed

+16-14Lines changed: 16 additions & 14 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``DviFont.widths``
2+
~~~~~~~~~~~~~~~~~~
3+
... is deprecated with no replacement.
Collapse file

‎lib/matplotlib/backends/backend_pdf.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pdf.py
+6-2Lines 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

Collapse file

‎lib/matplotlib/dviread.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/dviread.py
+5-11Lines 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+
widths = _api.deprecated("3.11")(property(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)
Collapse file

‎lib/matplotlib/dviread.pyi‎

Copy file name to clipboardExpand all lines: lib/matplotlib/dviread.pyi
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ class Dvi:
5656
class DviFont:
5757
texname: bytes
5858
size: float
59-
widths: list[int]
6059
def __init__(
6160
self, scale: float, tfm: Tfm, texname: bytes, vf: Vf | None
6261
) -> None: ...
6362
def __eq__(self, other: object) -> bool: ...
6463
def __ne__(self, other: object) -> bool: ...
64+
@property
65+
def widths(self) -> list[int]: ...
6566

6667
class Vf(Dvi):
6768
def __init__(self, filename: str | os.PathLike) -> None: ...

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.