bevyengine / bevyengine/bevy

Add support for bitmap glyphs in OTF fonts

Open
#11,593 3 comments 12 reactions 0 assignees View on GitHub
A-Text C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

Retro-style games would benefit a lot from having sharp, stylized bitmap characters in fonts. Currently `bevy_text` only works with glyphs defining vector outlines/curves.

## What solution would you like?

When [processing glyphs](https://github.com/bevyengine/bevy/blob/135c7240f1c00dba941dad4282dee9080dae56df/crates/bevy_text/src/glyph_brush.rs#L102), if outline data is not found for a glyph, we should try to get a glyph bitmap (using [`glyph_raster_image2`](https://docs.rs/ab_glyph/latest/ab_glyph/struct.FontArc.html#method.glyph_raster_image2)). Atlas generating code would now need some abstraction (like an enum) to discern `OutlineGlyph`s from `GlyphImage`s. When blitting `GlyphImage`s in the font atlas, `ImagePlugin`'s sampler settings should be taken into account.

## What alternative(s) have you considered?

At first I thought of creating a plugin that worked with font sprite sheets [like this one](https://github.com/bevyengine/bevy/assets/3709789/e84d0c7b-d57b-49e1-8df7-e67509109dcc) with a couple definitions such as character size and the Unicode range they cover. But it would involve a lot of duplicated code from `bevy_text` as the process would be basically the same, with a different `TextStyle` that would use a `SpriteFont`.

Ideally, in the long run, `bevy_text` should also support such an use case as a more practical way of doing sprite fonts without having to create a TTF file first. Also, would save some memory for such retro games as you'd only need a single font size and the font texture would be the font atlas already. It could support known formats such as [BMFont](http://www.angelcode.com/products/bmfont/)'s `.fnt` (which is actually XML) or a custom RON-based one.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.