Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble drawing emojis #536

Closed
jasoneveleth opened this issue Mar 27, 2024 · 8 comments · Fixed by #615
Closed

Trouble drawing emojis #536

jasoneveleth opened this issue Mar 27, 2024 · 8 comments · Fixed by #615

Comments

@jasoneveleth
Copy link

jasoneveleth commented Mar 27, 2024

I'm trying to render emojis using winit. I've gotten normal text to render just fine following along from here. I'm using an emoji font (I know it has emojis since the charmap.map(c) is returning a nonzero gid, and is returning a zero gid for normal ascii). The following code I think provides enough context to understand what I'm doing:

scene
    .draw_glyphs(&self.font)
    .font_size(font_size)
    .transform(Affine::translate((110.0, 700.0)))
    .glyph_transform(None)
    .draw(
        peniko::Fill::NonZero,
        text.chars().map(|c| {
            let x = pen_x;
            let gid = charmap.map(c).unwrap_or_default();
            pen_x += metrics.advance_width(gid).unwrap_or_default();
            vello::glyph::Glyph {
                id: gid.to_u16() as u32,
                x,
                y: pen_y,
            }
        }),
    );

The text has the emojis we're rendering from. In my case I'm using "abc🪓123" which turns into GID_0, GID_0, GID_0, GID_3750, GID_3192, GID_3198, GID_3196, respectively. The charmap holds the charmap from a font_ref from the font. I'm using the NotoColorEmoji-Regular.ttf font. I'm on macOS 14.2.1 on M1 Pro. When it renders I see the box for missing glyphs for abc but just black for the rest.

I'm starting to think that I'm doing emojis the wrong way because the object returned by draw_glyphs has a brush object that defaults to pure black, but I don't want my emojis to be all black. I've looked around and I can't find anything about how to render an emojis. I'm happy to provide a gist for people in the future trying to do a similar thing.

In short, is this something that is possible? And what files/docs should I go find to get the information I need to understand how to render emojis?

Thank you for such a wonderful library.

EDIT: explaining the parts of the code snippet

@jasoneveleth
Copy link
Author

Okay, I think it has something to do with the color. When I use "NotoColorEmoji-Regular.ttf", which is a font that only has the black outline of each emoji, it renders correctly (the ax emoji and numbers show up). This makes me think that Vello is fine, I just need to figure out how to use the color that the fonts are giving me.

I expect that if I dive into the text shaping crates I will figure this out.

@xorgy
Copy link
Member

xorgy commented Mar 28, 2024

@jasoneveleth There is a little bit more to color emoji support. Supporting the two current main ways that fonts represent color emoji (‘COLRv1’ and embedded PNGs) is something that we intend to do.
Noto Color Emoji has fallback glyphs for the emoji that can be rendered like conventional fonts for the moment.

@jasoneveleth
Copy link
Author

Thank you. That's exactly what I needed to know.

@xorgy
Copy link
Member

xorgy commented Mar 29, 2024

And specifically COLRv1 (the version of color emoji used in current versions of Noto Color Emoji) is likely to be first.

@DJMcNab
Copy link
Member

DJMcNab commented Apr 5, 2024

We decided in the 2024-04-04 office hours to re-open this issue, and use it track getting COLRv1 emoji (etc.) working in Vello

See also #gpu > Emoji Rendering

@DJMcNab DJMcNab reopened this Apr 5, 2024
@jasoneveleth
Copy link
Author

I'd like to get Apple's emojis to render on mac. Do they use COLRv1? I would guess from the existence of this python library that they're using pngs.

If they're using pngs, is the best strategy to render them as an Image and then draw_image onto the scene?

@waywardmonkeys waywardmonkeys added this to the Vello 0.2 release milestone May 3, 2024
@DJMcNab DJMcNab removed this from the Vello 0.2 release milestone May 16, 2024
DJMcNab added a commit to DJMcNab/vello that referenced this issue Jun 24, 2024
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 linebender#536 

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

---------

Co-authored-by: Chad Brokaw <cbrokaw@gmail.com>
@DJMcNab
Copy link
Member

DJMcNab commented Jun 25, 2024

So, #615 supports COLR Emoji, which is not the format used by the Apple emoji. There is still more work required here

However, if you can afford to include Noto Colour Emoji in your app as a temporary measure, this should work using latest main.

@xorgy
Copy link
Member

xorgy commented Jun 27, 2024

And the one exception with Noto Color Emoji is that the flag emoji are in a separate CBDT-based color bitmap font.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants