Switch AWT font loading to Skia-based (#639)
## Improve font loading and listing Available font listing doesn't rely anymore on discovering and loading font files from the disk. This is MUCH faster than the previous solution, which could take seconds on a performant machine. Besides, this greatly reduces memory usage as we're only holding the font family names list in memory, and cache items in memory lazily only once they are requested to speed up later lookups. Users can manually clear the memory cache, and register custom fonts (from files or resources). We now get the list of available font families directly from Skia, with some additional features such as adding entries for the system font on macOS (which is hidden by default). To note, the list of fonts available to Skia is not the same as available to AWT, for a number of reasons: 1. AWT adds logical fonts (e.g., `Dialog`) 2. AWT silently substitutes broken fonts 3. AWT lists the macOS system font, but under a weird name, `.AppleSystemUIFont`, whereas Skia doesn't 4. AWT and Skia don't use the same logic to list installed fonts on all platforms 5. AWT includes fonts embedded into the JVM automatically This makes things a bit more complicated, but if you _know_ the correct family name, everything works fine. While AWT silently substitutes invalid font family names with others, Skia will return `null` if it can't find a font. We follow the Skia approach, returning null if we can't match a font family name. ## Improve AWT `Font` conversion to Skiko `Typeface` On the JetBrains Runtime, the `Font.toSkikoTypefaceOrNull()` will be able to properly match an AWT `Font` to a Skiko `Typeface`, even on OSes other than macOS. If running on other JVMs, this returns `null`, as requested by @igordmn. This requirement is documented in the KDocs. The necessity to be on the JBR is due to the "regular" AWT implementations of `sun.font.Font2D` and `sun.funt.TrueTypeFont` being essentially broken: they read the wrong entry from the `name` table in TrueType fonts and use it as font family name. In the JBR, additional logic has been added to read the correct entry, the [_preferred family_](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html), and we can use this information to match with Skia font families, as Skia uses the correct _preferred family name_.
Showing
File added
File moved
Please register or sign in to comment