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

Strange rendering of emojis #69

Closed
snaggen opened this issue Jan 18, 2024 · 23 comments · Fixed by pop-os/cosmic-text#216
Closed

Strange rendering of emojis #69

snaggen opened this issue Jan 18, 2024 · 23 comments · Fixed by pop-os/cosmic-text#216

Comments

@snaggen
Copy link

snaggen commented Jan 18, 2024

I have some old emoji font installed, not sure which font it belongs to, but then I also have NotoColorEmoji.ttf and that is the emojis I normally see. Now when I paste U+1F600 to a new line in the terminal, it renders it using the old emoji font, but the next time I paste it I get the color emoji (however, rendered very small).

To reproduce

  1. Go to https://www.unicode.org/emoji/charts/full-emoji-list.html#1f600
  2. copy the emoji character
  3. In a new line in the terminal, paste it multiple times

This is how it looks
image

@snaggen
Copy link
Author

snaggen commented Jan 18, 2024

Note the first grean triangle-arrow is my prompt, the line starts with the read emoji.
Tested both on a 200% zoom 4k screen and a screen with 100% zoom, and it renders the color emoji small on both screens. So it is not hdpi/zoom related.

@snaggen
Copy link
Author

snaggen commented Jan 18, 2024

Also, tried to enter it by ctrl-shit-u and unicode code (1f600) but that doesn't work at all, that just prints the digits and letters.

@MoSal
Copy link
Contributor

MoSal commented Jan 18, 2024

This could be connected to the braile issue (same underlying cause).

If you run with RUST_LOG=cosmic_text=trace, do you see "Adjusted glyph font size" messages?

@snaggen
Copy link
Author

snaggen commented Jan 18, 2024

Yes I get
[2024-01-18T20:00:38Z TRACE cosmic_text::shape] Adjusted glyph font size (20 => 9.637648)

@jackpot51
Copy link
Member

@MoSal normalization of width should take into account the unicode width of the glyph, since that is what terminal programs will use to determine how many columns were used (https://docs.rs/unicode-width/latest/unicode_width/)

@jackpot51
Copy link
Member

Yes, that is pretty strange. Noto color emoji should be preferred so I'm not sure why it is falling back to another font.

@MoSal
Copy link
Contributor

MoSal commented Jan 18, 2024

I would like to see what happens with pop-os/cosmic-text#215 applied first.

@MoSal
Copy link
Contributor

MoSal commented Jan 18, 2024

@MoSal normalization of width should take into account the unicode width of the glyph, since that is what terminal programs will use to determine how many columns were used (https://docs.rs/unicode-width/latest/unicode_width/)

But font resize uses the width of ' ' to avoid this!

@snaggen
Copy link
Author

snaggen commented Jan 18, 2024

There was no difference using the fallback_codepoints branch

When I look at the debug output I see that

[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Sans'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'DejaVu Sans'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'FreeSans'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Sans Mono'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'DejaVu Sans Mono'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'FreeMono'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Sans Symbols'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Sans Symbols2'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Color Emoji'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] Failed to find preset fallback for [] locale 'sv-SE', used 'DejaVu Sans': '😀'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Sans'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'FreeSans'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Sans Mono'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'DejaVu Sans Mono'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'FreeMono'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Sans Symbols'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Sans Symbols2'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] failed to find family 'Noto Color Emoji'
[2024-01-18T20:53:59Z DEBUG cosmic_text::font::fallback] Failed to find preset fallback for [] locale 'sv-SE', used 'Noto Color Emoji': '😀'

It uses DejaVu Sans for the first substitution and then Noto Color Emoji.

Also, I realize it looks extra weird, since the zsh auto suggestion is suggesting previous emoji tests... but without that it still is like in the screenshot that it first fallbacks to the ugly emoji for the first char in the line, and after that it uses the correct emoji.

@snaggen
Copy link
Author

snaggen commented Jan 18, 2024

Deleted the screencast since that just got confusing due to zsh autosuggestions...

@MoSal
Copy link
Contributor

MoSal commented Jan 18, 2024

Since DejaVu Sans and Noto Color Emoji are not monospace fonts, whatever got resized probably wasn't an emoji!

@MoSal
Copy link
Contributor

MoSal commented Jan 18, 2024

@snaggen If you could test with the set_monospace_width() lines in src/terminal.rs commented, that should remove all doubt about this not being related to font resize.

@MoSal
Copy link
Contributor

MoSal commented Jan 18, 2024

Wait, Noto Color Emoji is a Monospace font!

@jackpot51
Copy link
Member

Emoji fonts, probably some CJK fonts too, are monospace.

@jackpot51
Copy link
Member

Nevermind, not CJK fonts.

@jackpot51
Copy link
Member

Actually, there are monospace CJK fonts. This means there are monospace full width characters other than emojis.

MoSal added a commit to MoSal/cosmic-text that referenced this issue Jan 18, 2024
 "Noto Color Emoji" reports itself as a Monospace font. But resizing
 glyphs from such a font to fit a certain width may make emojis look
 rather small. So avoid font resizing with such fonts by not setting
 `monospace_em_width`.

 Fixes pop-os/cosmic-term#69.

Signed-off-by: Mohammad AlSaleh <[email protected]>
@MoSal
Copy link
Contributor

MoSal commented Jan 18, 2024

Actually, there are monospace CJK fonts. This means there are monospace full width characters other than emojis.

So, some characters would be a multiple of the Monospace width?

@jackpot51
Copy link
Member

Yes, and unicode-width is the way to know.

@MoSal
Copy link
Contributor

MoSal commented Jan 18, 2024

But then again, I made font resizing depend on the width of a space:

https://github.com/pop-os/cosmic-text/blob/8457e68d984c465f7c5306424a73aa162aff32f2/src/font/mod.rs#L83-L90

A space in "Noto Color Emoji" has a horizontal_advance/units_per_em of 2550/2048. Compare that to 600/1000 for Fira Mono.

@MoSal
Copy link
Contributor

MoSal commented Jan 19, 2024

If, for the sake of keeping monospatiality, we pretend that an Emoji monospace font has half the width it really has, would that be too hackish?

Basically, pretending that it's not monospace so it doesn't get resized

ct_no_mono_emoji

vs. pretending it's half width so it gets double the resized font size

ct_2x_emoji

@snaggen
Copy link
Author

snaggen commented Jan 19, 2024

I'm not sure it is as easy as special handle emoji fonts.... we have other fonts with symbols, like Nerd Fonts (which may be merged in to various fonts, which can be found on the Nerd Font home page https://www.nerdfonts.com ).

The screenshot below shows how some nerd font symbol is rendred in Cosmic Term and Wezterm. I included the letter A for reference.

image

The rust logo is the Nerd Font character with unicode f1617

@snaggen
Copy link
Author

snaggen commented Jan 19, 2024

Also, I created #70 to make it easier to use various special unicode characters, that should make it easier to test this since you then just can enter the unicode code for the different characters.

@MoSal
Copy link
Contributor

MoSal commented Jan 19, 2024

Good point. This is not Emoji-specific.

Another idea to keep monospatiality is to add a rounded factor to resizing:

1/(font_width/default_width) * (font_width/default_width).round() * font_size

MoSal added a commit to MoSal/cosmic-text that referenced this issue Jan 19, 2024
 When matching to a default monospace width, big fonts like those
 containing symbols and emojis got too small from font resizing.

 Adding a glyph-to-default rounded factor to the calculation should fix
 that issue without losing monospatiality.

 Fixes pop-os/cosmic-term#69.

Signed-off-by: Mohammad AlSaleh <[email protected]>
jackpot51 pushed a commit to pop-os/cosmic-text that referenced this issue Jan 19, 2024
 When matching to a default monospace width, big fonts like those
 containing symbols and emojis got too small from font resizing.

 Adding a glyph-to-default rounded factor to the calculation should fix
 that issue without losing monospatiality.

 Fixes pop-os/cosmic-term#69.

Signed-off-by: Mohammad AlSaleh <[email protected]>
vorporeal pushed a commit to warpdotdev/cosmic-text that referenced this issue Mar 22, 2024
 When matching to a default monospace width, big fonts like those
 containing symbols and emojis got too small from font resizing.

 Adding a glyph-to-default rounded factor to the calculation should fix
 that issue without losing monospatiality.

 Fixes pop-os/cosmic-term#69.

Signed-off-by: Mohammad AlSaleh <[email protected]>
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.

3 participants