slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 565 forks source link

Korean characters shown as squares in OpenGL rendering #1139

Closed teminian closed 2 years ago

teminian commented 2 years ago

hangul-broken If you follow instructions below, you find that Korean characters are shown as squares(as if there's no such font)

  1. Run gallery example
  2. Click LineEdit
  3. Input in this sequence: DDDDjjjj가나다라 (or you can just copy-and-paste the left characters)
  4. And you'll meet the same "broken" text rendering

As of current the only workaround is as follows:

  1. Input Korean characters along with others(e.g. 가나다라DDDDjjjj)
  2. Erase all of them
  3. Input the "erroneous" stuff
  4. The text is rendered, but "pulled down" as I uploaded in https://github.com/slint-ui/slint/issues/1138

For your reference, I used OpenGL backend in Windows, and the language is C++.

tronical commented 2 years ago

Thanks for the detailed report!

On Windows we're using IDWriteFontFallback::MapCharacters to determine the list of fonts we need to render a given piece of text. When that text starts with Korean characters, we locate the correct font. When it starts with latin, we either fail to pick the correct fallback font or the font we pick claims to cover CJK when in fact it doesn't.

This is also reproducible with Chinese characters, so this is most likely related to us calling the function incorrect or interpreting the results wrongly.

tronical commented 2 years ago

The implementation returns only a single font ever, so there's definitely something fishy there.

ogoffart commented 2 years ago

I can reproduce on Linux btw

Screenshot_20220404_104753

(string: "e.g. 가나다라DDDDjjjj")

Edit: I think I just don't have the character in my fonts. Because Qt is also not showing it. And even in the browser it is replacement character.

teminian commented 2 years ago

I agree with @ogoffart. I think you can install a few Korean fonts in Linux and try again, for example Nanum. For Ubuntu the package name must be fonts-nanum and for Fedora and like I think it's nhn-nanum-fonts.

legend59 commented 2 years ago

It can be used in the font of the following address.

https://hangeul.naver.com/hangeul_static/webfont/zips/nanum-myeongjo.zip

The prefix 'nanum' means open, and all nanum fonts follow the open source license. Because the default font is already used, Hangul(Korean characters) is shown as squares. To use Hangul, the font was changed by adding "NanumGothic" to default-font-family. Add below parameter

default-font-family: "NanumMyeongjo";

in gallery.slint file.

tronical commented 2 years ago

The implementation returns only a single font ever, so there's definitely something fishy there.

What's fishy is that we're not looking at the valid_len field.