Add font-kit support
Continued from #1
Right now fonts are accessed via hard-coded paths. This is not portable, we should look into using fontkit.
Plan
Remove usage of https://doc.rust-lang.org/std/macro.include_bytes.html with:
- Load system monospace font with font-kit.
- Convert it to
wgpu_glyph::Font(compiler showsrusttype::Font).
Use this examples
- https://github.com/dhardy/kas/blob/f4b052203752d16f9aeb7b53b42a1c17b7189bf5/kas-wgpu/src/font.rs
- https://github.com/servo/font-kit/tree/master/examples
Documentation
- https://crates.io/crates/glyph_brush
- https://crates.io/crates/rusttype
- On Windows this loader https://github.com/servo/font-kit/blob/9c189cc8b6dd139b1d9bce4920d7788a7f27c076/src/loaders/directwrite.rs is used but is not in documentation https://docs.rs/font-kit/0.5.0/font_kit/loaders/?
- https://docs.rs/font-kit/0.5.0/font_kit/handle/enum.Handle.html
- https://docs.rs/wgpu_glyph/0.6.0/wgpu_glyph/struct.Font.html
- https://docs.rs/font-kit/0.5.0/font_kit/loaders/freetype/struct.Font.html
- https://docs.rs/rusttype/0.8.2/rusttype/struct.Font.html
- https://docs.rs/rusttype/0.8.2/rusttype/enum.SharedBytes.html
Other Examples
- https://github.com/linebender/skribo/blob/03c63ac17bb93e29f82e959dac94027935a21159/examples/render.rs#L21
- https://github.com/wez/wezterm/blob/4687b3bb48b49c0a1ffaade299aea0480ff3d488/src/font/locator/mod.rs#L116
- https://github.com/RazrFalcon/resvg/blob/0c1219667a27b39792c59fd24c1f628808f57d01/usvg/src/fontdb.rs#L313
Concerns/Alternatives
On my Windows box, font-kit takes just over a minute to compile and over 800k release code size. That seems high for something that's just loading fonts, but on the other hand I don't see any good way to get this down.
- https://www.reddit.com/r/rust/comments/b9mt2i/font_fallback_deep_dive/ek5ndmv/
- https://raphlinus.github.io/rust/skribo/text/2019/04/04/font-fallback.html
- https://github.com/servo/font-kit/wiki/FAQ
- alternative https://github.com/MSleepyPanda/rust-font-loader
- https://github.com/alacritty/alacritty/issues/957#issuecomment-371646492
- https://github.com/alacritty/alacritty/pull/1720#issuecomment-447677264
- https://github.com/alacritty/alacritty/issues/1568
I prefer to avoid adding large dependencies, but for now this is probably the easiest approach to get the editor much more portable.
It may be worth revisiting this later as we probably won't be using everything font-kit has to offer.