Repository navigation
Conversation
…hem in exports Text that plotly.js measures before a web font loads keeps the size of the fallback font, so titles, legends and margins do not fit the final text. An exported SVG cannot use the fonts of the page, so the exported text shows a fallback font. config.fonts gives plotly.js the font data, as a URL, a base64 data URL or the bytes. plotly.js loads these faces before it measures text. SVG exports embed the faces that the image uses, if the font file permits embedding. See plotly#8056.
The repository uses jasmine 3.5, which has no jasmine.stringContaining.
…n in the next draw plotly.js cannot read the embedding permission of a WOFF2 file, because browsers have no Brotli decoder. Before this change, svg, pdf and eps exports refused every WOFF2 face, so the exported text showed a fallback font. Now an export refuses a face only if the font file forbids embedding. A face that failed to load stayed in the cache for the life of the page. Thus a short network fault removed the font from all later graphs. Now the cache forgets a failed face, and the next draw tries the font again. See plotly#8056.
…led downloads A data URL, a byte source or a downloaded file that the browser cannot decode gives the same result each time. Before this change, the next draw tried such a face again and logged the same warning again. Now only a failed download makes the next draw try the face again, because a network fault can go away. See plotly#8056.
…ing, buffers and warnings A purge during the font wait made the waiting draw throw, and a relayout during the wait failed on the undrawn graph. Now a purge stops the waiting draw, and Plots.previousPromises holds later calls until the fonts load. Plotly.react compared font bytes by reference, so new bytes rebuilt the plot. collectionsAreEqual now compares binary values by their bytes. The export embedded a family whose name only occurred in class names, and Snapshot.toImage lost the fonts. Now the export reads the font-family declarations, and the snapshot clone keeps config.fonts. A detached ArrayBuffer source broke the next export, so plotly.js now copies the buffer. A config.fonts value of the wrong shape now gives a warning. See plotly#8056.
nul0m
marked this pull request as ready for review
November 16, 2026 16:45
Contributor
|
Thanks for putting this together. I'll review and follow up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8056.
@camdecoster i've finally got some time to look into this, this PR covers most of the things you mentioned in comments to #8056 so we can iterate here on the proposed solutions and possible gaps.
What it adds
config.fonts: a list of{family, source, weight?, style?}sourceis the URL of a font file, a base64 data URL, or the bytes (ArrayBufferor a typed array)FontSourcetype, exported fromlib/index.d.ts;fontsadded to theConfigOverridesinsrc/types/core/config.d.ts, since its schemavalTypeisanyLoading
_doPlotloads the faces ofconfig.fontsbefore it measures any text (a step afterPlots.previousPromises)FontFace.load(), so nofont-familyparsing and noloadingdoneconfig.fontsstill draws synchronouslyDrawing.savedBBoxesnewPlotresolves, nothing drawn)Plots.previousPromisesuntil the fonts load (checked:relayout,restyle,reactwith style, range, annotation, shape,layout.imagesor transition changes,Plotly.animate, resize)reactwith the same font bytes in a new buffer isn't a config change:helpers.collectionsAreEqualcompares binary values by their bytesArrayBuffersource is copiedfontsnot an array, string items, an unsupported source typeExports
toSVGadds a<style>with base64@font-facerules for the faces that afont-familydeclaration of the SVG names (rich-text spans included; case and quotes don't matter)fsTypeforbids embedding (restricted license, bitmap only), with a warningPlotly.Snapshot.toImage/Snapshot.clonekeepconfig.fonts, and pass the format totoSVGNot in this PR
Known limits
config.fontsswitch to the face when it loads, but aren't re-measured - the same as any web font that loads after a drawrelayoutofxaxis.rangeduring the wait becomes the double-click reset rangerelayoutqueued during the wait and followed by a purge still rejects, as before this changeTests
config_test.js,fonts:(11): load before the draw, sync draw from the cache, typed array, decode failure warns once, no second download of a bad file, retry after a failed download, purge during the wait, relayout during the wait, react with new bytes, item without a family, wrong shapestoimage_test.js,with config.fonts(9): svg embed, forbidden face in svg and in raster, unreadable permission, compressed OS/2 table in WOFF, detachedArrayBuffer, unused family, rich-text span, snapshot clonelib_test.js,readEmbeddingPermission(3)plot_api_test.js,collectionsAreEqual: binary valuestest/jasmine/assets/test_fonts.js: synthetic fonts, every glyph a 1 em square, so text widths are exact (TTF and WOFF,fsType0 and 2)Checks run
npm run lint,typecheck,test-syntax,test-types,entry-point-types-check: passnpm run schema-typegen-diff-check: no driftnpm run test-jasmine -- config toimage lib plot_api plots snapshot: 591 of 591 (Chrome 157, macOS)build/plotly.js: title 100 px with the font vs 68.9 px with the fallback; a direct URL from a local server that answers after 300 ms draws after about 320 ms; a URL that never answers falls back after 10 sOpen questions
newPlot, onerelayoutand an export)font.familydescription, which says only installed fonts work, mentionconfig.fonts?figure.configtoday, so this doesn't reach plotly.py'swrite_imageyet - is a Kaleido issue the right next step?draftlogs/0000_add.mdgets the PR number once it exists.