go-text / typesetting

High quality text shaping in pure Go.
Other
100 stars 10 forks source link

fontscan: improve caching of font collections #144

Closed dominikh closed 6 months ago

dominikh commented 6 months ago

If I understand correctly, (*FontMap).loadFont calls Footprint.loadFromDisk, which might parse an entire TTC, only to return a single font.Face, which gets cached by loadFont. ISTM that if we need multiple fonts from the same font collection, then we repeat a lot of parsing. Shouldn't we instead cache all faces from the collection?

benoitkugler commented 6 months ago

Nice catch, thank you. loadFromDisk should return the whole slice of faces, which should be added in the cache in loadFont

benoitkugler commented 6 months ago

Hum, it is not as simple as I had thought, because the other faces in a font collection do not have the same footprint. And, for now, we do not have a simple face -> metadata method (this is #113).

dominikh commented 6 months ago

Well, alternatively, we shouldn't use LoadTTC and instead only load the requested font from the collection, not all fonts. We'll still parse the TTC header repeatedly, but we won't have to load every font included in the collection every time.