Title: [FEATURE]: accept font data (a URL or the bytes) for export and text measurement · Issue #8056 · plotly/plotly.js · GitHub
Open Graph Title: [FEATURE]: accept font data (a URL or the bytes) for export and text measurement · Issue #8056 · plotly/plotly.js
X Title: [FEATURE]: accept font data (a URL or the bytes) for export and text measurement · Issue #8056 · plotly/plotly.js
Description: Description We want charts to render with a font that isn't installed on the machine doing the rendering - Kaleido in a container, in our case. This all started in plotly/kaleido#464 but @camdecoster has pointed me here and I found a sim...
Open Graph Description: Description We want charts to render with a font that isn't installed on the machine doing the rendering - Kaleido in a container, in our case. This all started in plotly/kaleido#464 but @camdecost...
X Description: Description We want charts to render with a font that isn't installed on the machine doing the rendering - Kaleido in a container, in our case. This all started in plotly/kaleido#464 but @camde...
Opengraph URL: https://github.com/plotly/plotly.js/issues/8056
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE]: accept font data (a URL or the bytes) for export and text measurement","articleBody":"### Description\n\nWe want charts to render with a font that isn't installed on the machine doing the rendering - Kaleido in a container, in our case. This all started in https://github.com/plotly/Kaleido/issues/464 but @camdecoster has pointed me here and I found a similar issue - #4885, but we then concluded it would make sense to create a narrower one, so here it is. \n\nThe request is a way to hand plotly.js a font, as either a URL or the raw bytes, and have it do two things with whichever it gets: register the face\nbefore it measures text, and inline `@font-face` with base64 into the exported SVG.\n\n### Why should this feature be added?\n\nWell, people are still hitting #4885 that has been open since 2020. I just tried with plotly.py 7.1.0 (plotly.js 4.1.1) and a font that isn't installed on my machine:\n\n```python\nfig.update_layout(font=dict(family=\"Fira Sans Condensed\"))\nfig.write_image(\"out.svg\")\n```\n\nand the resulting SVG names that family 7 times but carries no `@font-face` and no base64anywhere. The name travels, but the bytes don't.\n\nIt's two bugs though, not one. The other is WilliamMayor's 2023 comment in the same thread - the font also isn't loaded when plotly.js measures text, so ticks, margins and legends get sized on some kind of \"fallback\" and the layout is wrong before anything is exported. Taking the font as input could fix both, I believe, because both come from it not being in the page.\n\nI saw @alexcjohnson proposing a cheaper alternative in #4885 - to read the `@font-face` rules already active in the document instead of having users declare fonts. I tested that: with a plain `\u003clink>` to fonts.googleapis.com, `cssRules` throws `SecurityError`, and it's only readable when the link carries `crossorigin=\"anonymous\"` (at least in the one browser and the one Google family we've checked).\n\n### Mocks/Designs\n\nRough, and I'm not attached to the naming:\n\n```js\nPlotly.newPlot(gd, data, layout, {\n fonts: [\n // a google fonts css url - the same string that's already in the \u003clink>\n {family: 'Open Sans', url: 'https://fonts.googleapis.com/css2?family=Open+Sans'},\n\n // a direct font file, nothing to parse\n {family: 'Open Sans', weight: 700, url: '/static/OpenSans-Bold.woff2'},\n\n // or the bytes, for offline and headless\n {family: 'Open Sans', weight: 700, data: arrayBufferOrBase64}\n ]\n})\n```\n\nThe first form is the convenient one and it's the only one that needs extra work: a Google Fonts URL returns CSS rather than a font, so something has to read the src out of that CSS and fetch the file it points at. The other two skip that step - the second is already a font file, the third is already bytes. So the CSS reading could come later, or never, and the feature still works.\n\n### Notes\n\nMy motivation is Kaleido, which has no user CSS and no network, so it would pass bytes. The same option would cover a browser user passing the Google Fonts URL they already have in their `\u003clink>`.\n\nIn case it comes up: I've grep'ed the latest plotly.js bundle and maplibre-gl does this already, and it's in the tree, but I don't think chart text can borrow it. Its loader is wired into maplibre's own style system, and `plotly-basic` and `plotly-cartesian` contain 0 `FontFace` - only the full bundle has it - so depending on it would put a map renderer in every build.\n\nOne case I'd leave out on purpose: pulling the bytes of a font that's only installed on the system. No browser API exposes them, so those users would have to supply the file.\n\nOne question we would need to agree on: how much of the URL side is needed? The bytes form needs no network at all, so it could land on its own. A direct `.woff2` URL adds a fetch, which would need a timeout and a warn-and-continue fallback so it can never hang a render. A Google Fonts CSS URL (which would add reading the `src` out of that CSS) looks a bit more complicated - from what I saw, google splits one family across several `@font-face` blocks, one per script, each pointing at a different file, so taking just the first gets you Latin and drops Cyrillic or Greek without saying anything.","author":{"url":"https://github.com/nul0m","@type":"Person","name":"nul0m"},"datePublished":"2026-09-18T15:28:18Z","url":"https://github.com/plotly/plotly.js/issues/8056"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:ba4c1945-8f7f-cdf4-c150-70c8237142f5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80A2:2E5652:2ACBD7C:3681594:6B01ADF6 |
| html-safe-nonce | e44a17527a1860f47fb16ece92d5a1ff16e578cddb1d3b837521fdd8ad7dcb7b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEEyOjJFNTY1MjoyQUNCRDdDOjM2ODE1OTQ6NkIwMUFERjYiLCJ2aXNpdG9yX2lkIjoiODQyMDY3NTAyNjQ5MTEyNTIzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2ceecf58ed0c64be9e80cbdebff27dbb06baa40f02ae23bf524bc1ef9be01d5c |
| hovercard-subject-tag | issue:5501378529 |
| 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/plotly/plotly.js/8056/issue_layout |
| twitter:image | https://opengraph.githubassets.com/324b94a236cd1c2cc73676af84692cadae8d80351b87fc903e1a2eedf9e05f1b/plotly/plotly.js/issues/8056 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/324b94a236cd1c2cc73676af84692cadae8d80351b87fc903e1a2eedf9e05f1b/plotly/plotly.js/issues/8056 |
| og:image:alt | Description We want charts to render with a font that isn't installed on the machine doing the rendering - Kaleido in a container, in our case. This all started in plotly/kaleido#464 but @camdecost... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nul0m |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/plotly/plotly.js git https://github.com/plotly/plotly.js.git |
| octolytics-dimension-user_id | 5997976 |
| octolytics-dimension-user_login | plotly |
| octolytics-dimension-repository_id | 45646037 |
| octolytics-dimension-repository_nwo | plotly/plotly.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 45646037 |
| octolytics-dimension-repository_network_root_nwo | plotly/plotly.js |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width