Skip to content

Commit

Permalink
Support bitmap fonts (#641)
Browse files Browse the repository at this point in the history
Resolve bitmap Emoji fonts at scene construction time (rather than the
ideal resolve time for glyph caching) for expedience.

Current status: Layout details aren't entirely correct

---------

Co-authored-by: Kaur Kuut <[email protected]>
  • Loading branch information
DJMcNab and xStrom committed Aug 21, 2024
1 parent a00cd9f commit 3c8dc79
Show file tree
Hide file tree
Showing 21 changed files with 827 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ jobs:

- name: cargo test
# TODO: Maybe use --release; the CPU shaders are extremely slow when unoptimised
run: cargo nextest run --workspace --locked --all-features
run: cargo nextest run --workspace --locked --all-features --no-fail-fast
env:
VELLO_CI_GPU_SUPPORT: ${{ matrix.gpu }}
# We are experimenting with git lfs, and we don't expect to run out of bandwidth.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ You can find its changes [documented below](#021---2024-07-16).

This release has an [MSRV][] of 1.75.

### Highlights

- Support for most Emoji ([#615][], [#641][] by [@DJMcNab])

### Added

- Support blends more than four layers deep ([#657][] by [@DJMcNab][])
Expand Down Expand Up @@ -117,10 +121,12 @@ This release has an [MSRV][] of 1.75.
[#575]: https://github.com/linebender/vello/pull/575
[#589]: https://github.com/linebender/vello/pull/589
[#612]: https://github.com/linebender/vello/pull/612
[#615]: https://github.com/linebender/vello/pull/615
[#619]: https://github.com/linebender/vello/pull/619
[#630]: https://github.com/linebender/vello/pull/630
[#631]: https://github.com/linebender/vello/pull/631
[#635]: https://github.com/linebender/vello/pull/635
[#641]: https://github.com/linebender/vello/pull/641
[#657]: https://github.com/linebender/vello/pull/657

<!-- Note that this still comparing against 0.2.0, because 0.2.1 is a cherry-picked patch -->
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
4 changes: 3 additions & 1 deletion examples/assets/noto_color_emoji/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

This folder contains a small subset of [Noto Color Emoji](https://fonts.google.com/noto/specimen/Noto+Color+Emoji), licensed under the [OFL version 1.1](LICENSE).
We do not include the full set of Emoji, because including the entire Emoji set would increase the repository size too much.
Note that Vello *does* support any COLR emoji (but not Emoji in other formats at the moment).
Included emoji are:

- ✅ Check Mark - \u{2705}/`:white_check_mark:`
- 👀 Eyes - \u{1f440}/`:eyes:`
- 🎉 Party Popper - \u{1f389}/`:party_popper:`
- 🤠 Face with Cowboy Hat - \u{1f920}/`cowboy_hat_face`

These are in the COLR format in `NotoColorEmoji-Subset` and in the CBTF format in `NotoColorEmoji-CBTF-Subset`.
This covers all ways that Emoji are commonly packaged, and both are supported by Vello.
46 changes: 41 additions & 5 deletions examples/scenes/src/simple_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ use vello::Scene;
// On Windows, can set this to "c:\\Windows\\Fonts\\seguiemj.ttf" to get color emoji
const ROBOTO_FONT: &[u8] = include_bytes!("../../assets/roboto/Roboto-Regular.ttf");
const INCONSOLATA_FONT: &[u8] = include_bytes!("../../assets/inconsolata/Inconsolata.ttf");
const NOTO_EMOJI_SUBSET: &[u8] =
const NOTO_EMOJI_CBTF_SUBSET: &[u8] =
include_bytes!("../../assets/noto_color_emoji/NotoColorEmoji-CBTF-Subset.ttf");
const NOTO_EMOJI_COLR_SUBSET: &[u8] =
include_bytes!("../../assets/noto_color_emoji/NotoColorEmoji-Subset.ttf");

pub struct SimpleText {
roboto: Font,
inconsolata: Font,
noto_emoji_subset: Font,
noto_emoji_colr_subset: Font,
noto_emoji_cbtf_subset: Font,
}

impl SimpleText {
Expand All @@ -29,7 +32,8 @@ impl SimpleText {
Self {
roboto: Font::new(Blob::new(Arc::new(ROBOTO_FONT)), 0),
inconsolata: Font::new(Blob::new(Arc::new(INCONSOLATA_FONT)), 0),
noto_emoji_subset: Font::new(Blob::new(Arc::new(NOTO_EMOJI_SUBSET)), 0),
noto_emoji_colr_subset: Font::new(Blob::new(Arc::new(NOTO_EMOJI_COLR_SUBSET)), 0),
noto_emoji_cbtf_subset: Font::new(Blob::new(Arc::new(NOTO_EMOJI_CBTF_SUBSET)), 0),
}
}

Expand All @@ -42,7 +46,7 @@ impl SimpleText {
/// Note that Vello does support COLR emoji, but does not currently support
/// any other forms of emoji.
#[allow(clippy::too_many_arguments)]
pub fn add_emoji_run<'a>(
pub fn add_colr_emoji_run<'a>(
&mut self,
scene: &mut Scene,
size: f32,
Expand All @@ -51,7 +55,39 @@ impl SimpleText {
style: impl Into<StyleRef<'a>>,
text: &str,
) {
let font = self.noto_emoji_subset.clone();
let font = self.noto_emoji_colr_subset.clone();
self.add_var_run(
scene,
Some(&font),
size,
&[],
// This should be unused
&Brush::Solid(Color::WHITE),
transform,
glyph_transform,
style,
text,
);
}

/// Add a text run which supports some emoji.
///
/// The supported Emoji are ✅, 👀, 🎉, and 🤠.
/// This subset is chosen to demonstrate the emoji support, whilst
/// not significantly increasing repository size.
///
/// This will use a CBTF font, which Vello supports.
#[allow(clippy::too_many_arguments)]
pub fn add_bitmap_emoji_run<'a>(
&mut self,
scene: &mut Scene,
size: f32,
transform: Affine,
glyph_transform: Option<Affine>,
style: impl Into<StyleRef<'a>>,
text: &str,
) {
let font = self.noto_emoji_cbtf_subset.clone();
self.add_var_run(
scene,
Some(&font),
Expand Down
12 changes: 10 additions & 2 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@ mod impls {
pub(super) fn emoji(scene: &mut Scene, params: &mut SceneParams) {
let text_size = 120. + 20. * (params.time * 2.).sin() as f32;
let s = "🎉🤠✅";
params.text.add_emoji_run(
params.text.add_colr_emoji_run(
scene,
text_size,
Affine::translate(Vec2::new(100., 400.)),
Affine::translate(Vec2::new(100., 250.)),
None,
Fill::NonZero,
s,
);
params.text.add_bitmap_emoji_run(
scene,
text_size,
Affine::translate(Vec2::new(100., 500.)),
None,
Fill::NonZero,
s,
Expand Down
2 changes: 2 additions & 0 deletions vello/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ static_assertions = { workspace = true }
futures-intrusive = { workspace = true }
wgpu-profiler = { workspace = true, optional = true }
thiserror = { workspace = true }
# TODO: Add feature for built-in bitmap emoji support?
png = { version = "0.17.13" }
Loading

0 comments on commit 3c8dc79

Please sign in to comment.