Title: Type 42 chars beyond BMP not displayed in PDF · Issue #20616 · matplotlib/matplotlib · GitHub
Open Graph Title: Type 42 chars beyond BMP not displayed in PDF · Issue #20616 · matplotlib/matplotlib
X Title: Type 42 chars beyond BMP not displayed in PDF · Issue #20616 · matplotlib/matplotlib
Description: Bug report Bug summary Characters from beyond the Basic Multilingual Plane (BMP) in Unicode are not displayed in PDFs with Type 42 fonts. Characters beyond the BMP have a code point greater than 65535 and cannot be encoded in a fixed-siz...
Open Graph Description: Bug report Bug summary Characters from beyond the Basic Multilingual Plane (BMP) in Unicode are not displayed in PDFs with Type 42 fonts. Characters beyond the BMP have a code point greater than 65...
X Description: Bug report Bug summary Characters from beyond the Basic Multilingual Plane (BMP) in Unicode are not displayed in PDFs with Type 42 fonts. Characters beyond the BMP have a code point greater than 65...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/20616
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type 42 chars beyond BMP not displayed in PDF","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nCharacters from beyond the Basic Multilingual Plane (BMP) in Unicode are not displayed in PDFs with Type 42 fonts. Characters beyond the BMP have a code point greater than 65535 and cannot be encoded in a fixed-size 2-byte encoding, such as the obsolete UCS-2. My understanding is that the CID maps still use such an encoding and cannot handle code points beyond that.\r\n \r\nIn the case of the `m` in STIX Sans, it's implemented via a virtual font embedded in the base font with chars shifted to higher code points, here code point 120366.\r\n\r\n**Code for reproduction**\r\n```python\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib import rcParams\r\n\r\nrcParams[\"pdf.fonttype\"] = 42\r\nrcParams[\"mathtext.fontset\"] = \"stixsans\"\r\n\r\nplt.text(0.5, 0.5, \"Mass $m$ \\U00010308\")\r\nplt.savefig(\"beyond_bmp.pdf\")\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\r\n[beyond_bmp.pdf](https://github.com/matplotlib/matplotlib/files/6792729/beyond_bmp.pdf)\r\n\r\n**Expected outcome**\r\n\r\n\r\n**Possible solutions**\r\nWe could take a similar approach as we did for Type 3 fonts. There any char\u003e255 is embedded via an `XObject` and not via the font directly. So, here the solution would be to use `XObjects` if the char\u003e65535 in text and math mode.\r\n\r\nI have a local, modified version of matplotlib based on https://github.com/matplotlib/matplotlib/pull/20615 which implements this approach. It extends the use of `_font_supports_char` and restricts the supported range for Type 42 to \u003c=65535. I can polish this local fix into a PR if people what to go this route.\r\n\r\n**Matplotlib version**\r\n\r\n * Operating system: Debian 11\r\n * Matplotlib version (`import matplotlib; print(matplotlib.__version__)`): 3.4.2\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): TkAgg (but I assume pdf)\r\n * Python version: 3.9.2\r\n * Matplotlib installed with pip in a virtual env\r\n","author":{"url":"https://github.com/sauerburger","@type":"Person","name":"sauerburger"},"datePublished":"2021-07-09T16:39:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/20616/matplotlib/issues/20616"}
| 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:dbf0e9cb-d040-5636-cd01-53afc6ebff03 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A430:17CF54:90476B:C7D5A6:6A5393E4 |
| html-safe-nonce | 9257fcc210b35c11c9bcff2fb4ae422e9e1ef4c092932dce3c2642e0c37938c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDMwOjE3Q0Y1NDo5MDQ3NkI6QzdENUE2OjZBNTM5M0U0IiwidmlzaXRvcl9pZCI6IjU1NDE0MDkyODAwMTQ2NTIzODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6cbd89bdae5aef7ac7bb14eb2123bdf0a82125b2693ce7b7d7cf3f18d51fcd84 |
| hovercard-subject-tag | issue:940916011 |
| 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/20616/issue_layout |
| twitter:image | https://opengraph.githubassets.com/714b7e73c21a151ae0ee0d2a3461e510cad25b46933f2bf6d58251b6ce542bc1/matplotlib/matplotlib/issues/20616 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/714b7e73c21a151ae0ee0d2a3461e510cad25b46933f2bf6d58251b6ce542bc1/matplotlib/matplotlib/issues/20616 |
| og:image:alt | Bug report Bug summary Characters from beyond the Basic Multilingual Plane (BMP) in Unicode are not displayed in PDFs with Type 42 fonts. Characters beyond the BMP have a code point greater than 65... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sauerburger |
| 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