fontdue icon indicating copy to clipboard operation
fontdue copied to clipboard

Store glyphs in a memory-mapped file

Open losfair opened this issue 2 years ago • 1 comments

Hello,

Thanks for your work on this crate! I'm using fontdue in Blueboat for drawing text onto a canvas and would like to reduce the memory usage after loading a large font file (e.g. NotoSerifSC). Found this in readme:

A non-goal of this library is to be allocation free and have a fast, "zero cost" initial load. This library does make allocations and depends on the alloc crate. Fonts are fully parsed on creation and relevant information is stored in a more convenient to access format. Unlike other font libraries, the font structures have no lifetime dependencies since it allocates its own space.

But it seems possible to write the glyphs field of a Font to a file after initial parsing, and memory-map the file back to a slice so that the OS kernel manages swapping of unused parts?

losfair avatar Dec 18 '21 07:12 losfair

@losfair I was just thinking about this yesterday. I think I will want to generate the font atlas and all the font and glyph metrics in a build script, serialize it to my own format, and just load that. Also nice, that it would make fontdue a build-only dependency.

Would be interesting if this could have been done in const fn and stored in a static, but probably won't be possible anytime soon.

yanchith avatar May 26 '22 12:05 yanchith