Title: [Bug]: `backend_pdf` gives `TTLibError` with `pdf.fonttype : 42` · Issue #21893 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: `backend_pdf` gives `TTLibError` with `pdf.fonttype : 42` · Issue #21893 · matplotlib/matplotlib
X Title: [Bug]: `backend_pdf` gives `TTLibError` with `pdf.fonttype : 42` · Issue #21893 · matplotlib/matplotlib
Description: Bug summary On macOS 12, fresh install of conda-forge matplotlib 3.5.0, when saving a figure to pdf, I get: TTLibError: specify a font number between 0 and 5 (inclusive) which I can trace to: ... ~/miniconda3/lib/python3.8/site-packages/...
Open Graph Description: Bug summary On macOS 12, fresh install of conda-forge matplotlib 3.5.0, when saving a figure to pdf, I get: TTLibError: specify a font number between 0 and 5 (inclusive) which I can trace to: ... ~...
X Description: Bug summary On macOS 12, fresh install of conda-forge matplotlib 3.5.0, when saving a figure to pdf, I get: TTLibError: specify a font number between 0 and 5 (inclusive) which I can trace to: ... ~...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/21893
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: `backend_pdf` gives `TTLibError` with `pdf.fonttype : 42`","articleBody":"### Bug summary\n\nOn macOS 12, fresh install of conda-forge matplotlib 3.5.0, when saving a figure to pdf, I get:\r\n\r\n```python\r\nTTLibError: specify a font number between 0 and 5 (inclusive)\r\n```\r\n\r\nwhich I can trace to:\r\n```python\r\n...\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend_pdf.py in embedTTF(self, filename, characters)\r\n 1424 return embedTTFType3(font, characters, descriptor)\r\n 1425 elif fonttype == 42:\r\n-\u003e 1426 return embedTTFType42(font, characters, descriptor)\r\n 1427 \r\n 1428 def alphaState(self, alpha):\r\n...\r\n```\r\n\r\nEverything works as expected if I save to a png or if I set `pdf.fonttype : 3` in my `matplotlibrc` file and save to pdf.\r\n\r\nI can see that `Helvetica*.afm` is present under `~/miniconda3/lib/python3.8/site-packages/matplotlib/mpl-data/fonts/pdfcorefonts` but not under `.../ttf`\n\n### Code for reproduction\n\n```python\nimport matplotlib.pyplot as plt\r\nplt.plot((1,2,3))\r\nplt.title('Axes Title', font='Helvetica')\r\nplt.savefig('text.pdf')\n```\n\n\n### Actual outcome\n\n```python\r\n---------------------------------------------------------------------------\r\nTTLibError Traceback (most recent call last)\r\n/var/folders/bj/czjbfh496258q1lc3p01lyz00000gn/T/ipykernel_58793/3096390865.py in \u003cmodule\u003e\r\n 2 plt.plot((1,2,3))\r\n 3 plt.title('Axes Title', font='Helvetica')\r\n----\u003e 4 plt.savefig('text.pdf')\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)\r\n 956 def savefig(*args, **kwargs):\r\n 957 fig = gcf()\r\n--\u003e 958 res = fig.savefig(*args, **kwargs)\r\n 959 fig.canvas.draw_idle() # need this if 'transparent=True' to reset colors\r\n 960 return res\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)\r\n 3010 ax.patch._cm_set(facecolor='none', edgecolor='none'))\r\n 3011 \r\n-\u003e 3012 self.canvas.print_figure(fname, **kwargs)\r\n 3013 \r\n 3014 def ginput(self, n=1, timeout=30, show_clicks=True,\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)\r\n 2312 # force the figure dpi to 72), so we need to set it again here.\r\n 2313 with cbook._setattr_cm(self.figure, dpi=dpi):\r\n-\u003e 2314 result = print_method(\r\n 2315 filename,\r\n 2316 facecolor=facecolor,\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)\r\n 1641 kwargs.pop(arg)\r\n 1642 \r\n-\u003e 1643 return func(*args, **kwargs)\r\n 1644 \r\n 1645 return wrapper\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)\r\n 384 # Early return in the simple, non-deprecated case (much faster than\r\n 385 # calling bind()).\r\n--\u003e 386 return func(*inner_args, **inner_kwargs)\r\n 387 arguments = signature.bind(*inner_args, **inner_kwargs).arguments\r\n 388 if is_varargs and arguments.get(name):\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend_pdf.py in print_pdf(self, filename, dpi, bbox_inches_restore, metadata)\r\n 2786 renderer.finalize()\r\n 2787 if not isinstance(filename, PdfPages):\r\n-\u003e 2788 file.finalize()\r\n 2789 finally:\r\n 2790 if isinstance(filename, PdfPages): # finish off this page\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend_pdf.py in finalize(self)\r\n 792 self.endStream()\r\n 793 self._write_annotations()\r\n--\u003e 794 self.writeFonts()\r\n 795 self.writeExtGSTates()\r\n 796 self._write_soft_mask_groups()\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend_pdf.py in writeFonts(self)\r\n 925 chars = self._character_tracker.used.get(filename)\r\n 926 if chars:\r\n--\u003e 927 fonts[Fx] = self.embedTTF(filename, chars)\r\n 928 self.writeObject(self.fontObject, fonts)\r\n 929 \r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend_pdf.py in embedTTF(self, filename, characters)\r\n 1424 return embedTTFType3(font, characters, descriptor)\r\n 1425 elif fonttype == 42:\r\n-\u003e 1426 return embedTTFType42(font, characters, descriptor)\r\n 1427 \r\n 1428 def alphaState(self, alpha):\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend_pdf.py in embedTTFType42(font, characters, descriptor)\r\n 1230 subset_str = \"\".join(chr(c) for c in characters)\r\n 1231 _log.debug(\"SUBSET %s characters: %s\", filename, subset_str)\r\n-\u003e 1232 fontdata = _backend_pdf_ps.get_glyphs_subset(filename, subset_str)\r\n 1233 _log.debug(\r\n 1234 \"SUBSET %s %d -\u003e %d\", filename,\r\n\r\n~/miniconda3/lib/python3.8/site-packages/matplotlib/backends/_backend_pdf_ps.py in get_glyphs_subset(fontfile, characters)\r\n 40 options.drop_tables += ['FFTM', 'PfEd']\r\n 41 \r\n---\u003e 42 with subset.load_font(fontfile, options) as font:\r\n 43 subsetter = subset.Subsetter(options=options)\r\n 44 subsetter.populate(text=characters)\r\n\r\n~/miniconda3/lib/python3.8/site-packages/fontTools/misc/loggingTools.py in wrapper(*args, **kwds)\r\n 370 def wrapper(*args, **kwds):\r\n 371 with self:\r\n--\u003e 372 return func(*args, **kwds)\r\n 373 return wrapper\r\n 374 else:\r\n\r\n~/miniconda3/lib/python3.8/site-packages/fontTools/subset/__init__.py in load_font(fontFile, options, checkChecksums, dontLoadGlyphNames, lazy)\r\n 3006 \t lazy=True):\r\n 3007 \r\n-\u003e 3008 \tfont = ttLib.TTFont(fontFile,\r\n 3009 checkChecksums=checkChecksums,\r\n 3010 recalcBBoxes=options.recalc_bounds,\r\n\r\n~/miniconda3/lib/python3.8/site-packages/fontTools/ttLib/ttFont.py in __init__(self, file, res_name_or_index, sfntVersion, flavor, checkChecksums, verbose, recalcBBoxes, allowVID, ignoreDecompileErrors, recalcTimestamp, fontNumber, lazy, quiet, _tableCache)\r\n 141 file = tmp\r\n 142 self._tableCache = _tableCache\r\n--\u003e 143 self.reader = SFNTReader(file, checkChecksums, fontNumber=fontNumber)\r\n 144 self.sfntVersion = self.reader.sfntVersion\r\n 145 self.flavor = self.reader.flavor\r\n\r\n~/miniconda3/lib/python3.8/site-packages/fontTools/ttLib/sfnt.py in __init__(self, file, checkChecksums, fontNumber)\r\n 58 numFonts = header.numFonts\r\n 59 if not 0 \u003c= fontNumber \u003c numFonts:\r\n---\u003e 60 raise TTLibError(\"specify a font number between 0 and %d (inclusive)\" % (numFonts - 1))\r\n 61 self.numFonts = numFonts\r\n 62 self.file.seek(header.offsetTable[fontNumber])\r\n\r\nTTLibError: specify a font number between 0 and 5 (inclusive)\r\n```\n\n### Expected outcome\n\nA pdf file saved to filesystem\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nmacOS 12, M1 pro, arm64\n\n### Matplotlib Version\n\n3.5.0\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n3.8.12\n\n### Jupyter version\n\n6.4.6\n\n### Installation\n\nconda","author":{"url":"https://github.com/shaharkadmiel","@type":"Person","name":"shaharkadmiel"},"datePublished":"2021-12-09T17:23:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/21893/matplotlib/issues/21893"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9d7ecc9b-5344-18c6-a202-f2232109357b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CC8:2FD3E:1A8CA11:2334D3F:6A52CD2D |
| html-safe-nonce | 4d1ea7d51b13603d62af49722c6ffa68042bb60568e320be4efd2d6a71fc24eb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0M4OjJGRDNFOjFBOENBMTE6MjMzNEQzRjo2QTUyQ0QyRCIsInZpc2l0b3JfaWQiOiI2MTg3OTc0NDU1NjE4MzU4NTc0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 223ca8e89d9c96fc042bbdab8ebae498fccdf5216dc2b89f90d35e3fdf461c6e |
| hovercard-subject-tag | issue:1075819791 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/21893/issue_layout |
| twitter:image | https://opengraph.githubassets.com/55620c46293d5e7f46b43d82dcade6484c626ae765127c9bd4c364eab06656c4/matplotlib/matplotlib/issues/21893 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/55620c46293d5e7f46b43d82dcade6484c626ae765127c9bd4c364eab06656c4/matplotlib/matplotlib/issues/21893 |
| og:image:alt | Bug summary On macOS 12, fresh install of conda-forge matplotlib 3.5.0, when saving a figure to pdf, I get: TTLibError: specify a font number between 0 and 5 (inclusive) which I can trace to: ... ~... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shaharkadmiel |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width