PolyMeilex / sctk-adwaita

Adwaita-like SCTK Frame
MIT License
26 stars 19 forks source link

Use memory mapped system fonts for ab_glyph titles instead of keeping in RAM #18

Closed alexheretic closed 1 year ago

alexheretic commented 1 year ago

ab_glyph titles will read the system title font using memory mapped buffers instead of reading to heap.

This lowers RAM usage of the since previously the system font would be saved in heap. For some system fonts this can be quite large and undesirable for rendering a title.

The disadvantage is currently the font must be parsed before each use instead of once at startup. It may be possible to improve this later with https://github.com/alexheretic/owned-ttf-parser/issues/11. In any case on my system render() time is relatively unaffected at 50-100µs so this doesn't seem a deal breaker.

Tests

My system title font is Cantarell-VF.otf (167K). Running the cargo run --example simple --release

If I choose NotoSerifCJK-Bold.ttc (27M). Running the cargo run --example simple --release

Bonus

I've also improved the FontPreference parsing so it can handle config like Noto Serif CJK HK Bold 12 as I noticed that wasn't working properly when I wanted to test it.

Resolves #17

alexheretic commented 1 year ago

@PolyMeilex wdyt?

PolyMeilex commented 1 year ago

I completely forgot about this PR, my bad, thanks for a ping. In general the idea sounds good, I'll try to take a look at the code soon.

PolyMeilex commented 1 year ago

Thanks!