pop-os / cosmic-term

WIP COSMIC terminal emulator
GNU General Public License v3.0
389 stars 72 forks source link

Strange rendering of emojis #69

Closed snaggen closed 10 months ago

snaggen commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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

jackpot51 commented 10 months ago

@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 commented 10 months ago

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 commented 10 months ago

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

MoSal commented 10 months ago

@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 commented 10 months ago

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 commented 10 months ago

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

MoSal commented 10 months ago

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

MoSal commented 10 months ago

@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 commented 10 months ago

Wait, Noto Color Emoji is a Monospace font!

jackpot51 commented 10 months ago

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

jackpot51 commented 10 months ago

Nevermind, not CJK fonts.

jackpot51 commented 10 months ago

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

MoSal commented 10 months ago

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 commented 10 months ago

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

MoSal commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

Also, I created https://github.com/pop-os/cosmic-term/pull/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 commented 10 months ago

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