tangrams / tangram

WebGL map rendering engine for creative cartography
https://tangram.city
MIT License
2.22k stars 290 forks source link

Lazy-load fonts as needed #765

Open bcamper opened 4 years ago

bcamper commented 4 years ago

Currently, all fonts in the scene are parsed and loaded when the scene is initially loaded. And there is a blocking effect because all fonts must be loaded before any text labels are rendered on the main thread (but the font loading process starts in parallel with the rest of the scene build process, so the actual blocking time depends on when the first label render request is made from a tile).

Instead, we should lazily load each font definition the first time it is need for label rendering. This requires doing some extra parsing/"matching" logic from font parameters in the draw group, back to the appropriate font face definition in the scene fonts block (and if no matching font is found, assume it's a built-in one).

This could also be used to address the Chrome bug with italics and variable fonts mentioned in #757, by issuing an explicit font load request for each new weight (which should resolve immediately, but needs to be verified).