Skip to content

Commit

Permalink
Render COLR Glyphs (Emoji) (#615)
Browse files Browse the repository at this point in the history
This is following the breadcrumbs laid out in [#gpu > Emoji
Rendering](https://xi.zulipchat.com/#narrow/stream/197075-gpu/topic/Emoji.20rendering)

This supports rendering COLR emoji; we assume that these are reasonably
well behaved.

![image](https://github.com/linebender/vello/assets/36049421/42c11e1d-ef64-4f4e-bd61-9ee6c09c223c)

For examples, we use a very small subset of [Noto Color
Emoji](https://fonts.google.com/noto/specimen/Noto+Color+Emoji), which
is approximately 5.5kB.

Fixes #536 

We will need a follow up issue for `sbix`/`CBDT`. I presume we're
ignoring svg-in-opentype.

---------

Co-authored-by: Chad Brokaw <[email protected]>
  • Loading branch information
DJMcNab and dfrg authored Jun 21, 2024
1 parent fb947d6 commit 886604b
Show file tree
Hide file tree
Showing 6 changed files with 609 additions and 22 deletions.
93 changes: 93 additions & 0 deletions examples/assets/noto_color_emoji/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2021 Google Inc. All Rights Reserved.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.
11 changes: 11 additions & 0 deletions examples/assets/noto_color_emoji/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Noto Color Emoji Subset

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`
39 changes: 38 additions & 1 deletion examples/scenes/src/simple_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;

use vello::glyph::Glyph;
use vello::kurbo::Affine;
use vello::peniko::{Blob, Brush, BrushRef, Font, StyleRef};
use vello::peniko::{Blob, Brush, BrushRef, Color, Font, StyleRef};
use vello::skrifa::raw::FontRef;
use vello::skrifa::MetadataProvider;
use vello::Scene;
Expand All @@ -14,10 +14,13 @@ 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] =
include_bytes!("../../assets/noto_color_emoji/NotoColorEmoji-Subset.ttf");

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

impl SimpleText {
Expand All @@ -26,9 +29,43 @@ 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),
}
}

/// 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.
///
/// 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>(
&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_subset.clone();
self.add_var_run(
scene,
Some(&font),
size,
&[],
// This should be unused
&Brush::Solid(Color::WHITE),
transform,
glyph_transform,
style,
text,
);
}

#[allow(clippy::too_many_arguments)]
pub fn add_run<'a>(
&mut self,
Expand Down
14 changes: 14 additions & 0 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn test_scenes() -> SceneSet {
"stroke_styles (skew)",
false
),
scene!(emoji),
scene!(tricky_strokes),
scene!(fill_types),
scene!(cardioid_and_friends),
Expand All @@ -70,6 +71,19 @@ pub fn test_scenes() -> SceneSet {

// Scenes

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(
scene,
text_size,
Affine::translate(Vec2::new(100., 400.)),
None,
Fill::NonZero,
s,
);
}

fn funky_paths(scene: &mut Scene, _: &mut SceneParams) {
use PathEl::*;
let missing_movetos = [
Expand Down
Loading

0 comments on commit 886604b

Please sign in to comment.