xi-editor / xi-mac

The xi-editor mac frontend.
Apache License 2.0
3.02k stars 147 forks source link

Fix Emoji drawing for dark themes #466

Closed jeremywiebe closed 2 years ago

jeremywiebe commented 5 years ago

NOTE: This is incomplete. I've gotten a bit lost in the vertex shader as that's completely new territory for me. Any pointers would be appreciated.

Summary

This PR fixes drawing emoji when using dark themes. It detects an Emoji in a CTRun and provides a flag to the text vertex shader program so it can avoid inverting the emoji colours.

Closes #266

Checklist

Example:

Review Checklist

raphlinus commented 5 years ago

Unfortunately I think you might require a different pipeline to draw emoji than to draw RGB subpixeled text. The existing shaders blend the foreground color using the RGB pixel values as 3 independent alpha masks (this requires dual source blending, which is set in the Swift code that does the draw call).

So to do it really correctly, you'll need another draw for the color emojis. These won't take an fg color (although it's possible they could take an alpha value), don't do dual source blending. The fragment shader should be really simple, basically just return texture(mask, uv) (note, you'll need all 4 channels, the emoji has an alpha channel).

Sorry this isn't simpler - it would be nice to use the existing shaders, just make them do emoji properly.

nangtrongvuon commented 5 years ago

Unfortunately I think you might require a different pipeline to draw emoji than to draw RGB subpixeled text. The existing shaders blend the foreground color using the RGB pixel values as 3 independent alpha masks (this requires dual source blending, which is set in the Swift code that does the draw call).

Just wondering, why is it bad to draw emoji as RGB subpixeled text? Is it because then they don't appear properly?

raphlinus commented 5 years ago

@nangtrongvuon Very simply, there are different rules for drawing it. Text is only an alpha value (though there are three separate channels for RGB) and takes the foreground color. Emoji is basically an RGBA image. I'm not sure if there's good documentation easily accessible, but if you look at the text drawing part of, say, Android, you'll find different paths for drawing them.

jeremywiebe commented 5 years ago

@raphlinus thank-you for the direction! I was kinda lost once I hit the shaders. I'll begin getting more familiar with this part of xi-mac (and OpenGL) and update this PR!