rxi / lite

A lightweight text editor written in Lua
MIT License
7.42k stars 353 forks source link

[issue] can not render some unicode characters #227

Closed quadroli closed 3 years ago

quadroli commented 3 years ago

lite Rendering issue

mikolaj24 commented 3 years ago

Can You check this in C? For example:

RenRect       pr = {1, 1, 300, 300};

main()...
 ff = ren_load_font("monospace.ttf", 12);
 w = ren_get_font_width(foncik,"Alleluja");
 printf("w=%d",w);
 ren_draw_text(ff, "_Your_unicode_char", 10, 10, color_black);
 ren_update_rects(&pr, 1);
 SDL_RenderPresent(renderer);

or using rencache ? Strings is in utf-8 / iso/ etc?

quadroli commented 3 years ago

?

fab1an2 commented 3 years ago

question is. How drawing utf8 in C do You know example in C? Can write a code?

takase1121 commented 3 years ago

If there is a way to detect which glyph is unavailable for the font, we could possibly select a placeholder character to replace it. I am not very familiar with stb_truetype though.

quadroli commented 3 years ago

@takase1121 Am as unfamiliar as you are but sounds as if we are heading in the right direction with that

takase1121 commented 3 years ago

@quadroli Google always helps.

To test my idea, I modified lite to check if the codepoint has a glyph and replace them with the Unicode replacement character, U+FFFD, but it doesn't seem to work consistently. The problem (I suspect) is because the fonts are not very standardised, with the font coming with lite not having the replacement character while the font I used has a proper replacement character (an empty box).

Thus, besides checking if the codepoint has a proper glyph, we will also need to have a backup replacement glyph (texture), or we had to support fallback fonts which I think is too much work.

takase1121 commented 3 years ago

OR another alternative which I just discovered.

While thinking about this I remembered a lite plugin I used, drawwhitespace is somehow able to render whitespace with a dot or something. We could somehow get a list of unsupported codepoints and somehow use renderer.draw_text or renderer.draw_rect to draw the replacement.

the keyword here being somehow.

quadroli commented 3 years ago

Hmmmmmmm, how tedious of a task would it be to change the default font?

Assuming the issue is with it, don really know about the code points though, what supports them? Is it the sdl2 renderer or is that info also included within the font?

takase1121 commented 3 years ago

Changing the font is relatively easy, look for font in core.styles, you might find some way to change the font.

lite's font rendering is powered by stb_truetype.h. The glyphs that are rendered are wholly contained in the font, so you really can't render anything that is not in the font. However, there is some way to utilise the lower-level rendering API to render more basic things, that is what I am investigating right now.

quadroli commented 3 years ago

But for it to render a glyph it has to corelate to a certain code point, and these code points are defined by unicode, so, how are these code points implemented, cause its UTF-8 lite is using, meaning that we have all code points defined by it right? So where exactly is the issue arising if not the fact that these code points haven't been mapped to a glyph? Or could it be that its SDL2's renderer thats broken?

Cause i know for sure my display screen aint the issue, so i dunno if its SDL2's work to implement the code points or the font's work or the devs themselves or even the frikin cpu, quite confused on that, and once implemented i know its the renderer's work to display and seems as if u only need to pass it a font, a character, position and color, dunno where along the chain things are breaking, but, seems as if by the time your rendering u already have the font and all configured, so, back to my initial question, where are the codepoints configured and mapped?

takase1121 commented 3 years ago

The problem here is not with the code point, but with the glyph they point to, or more precisely, the glyph index.

Using glyph indexes, multiple codepoints can point to one glyph, which is why some font can display the replacement character properly - all of the unimplemented codepoints simply point to the replacement glyph.

However, some fonts does not do this, and this is why they're rendered as blanks.

quadroli commented 3 years ago

Ohh, good to know, so since there may not be glyphs for the superscrpts and subscripts you'd rather have them point to the replacement character?

How about just using a font that supports them? assuming that the code points are implemented

takase1121 commented 3 years ago

it's almost impossible to have most of them implemented - you would need to have glyphs for every single language supported by UTF. The best compromise is to use a font that is known to support some characters. Majority of fonts at least supports the English alphabet, so you won't have problems with it.

I recommend you to try out fonts that suits your needs (if you need to view cyrillic, find a font that supports cyrillic. If you need to view CJK characters, use a font for that). That is actually what most program does - they have a fallback font (or multiple) to support the worst case scenario.

quadroli commented 3 years ago

Oh, cool, well, guess i'll just look for 1 that supports both subs and supers, and hopefully also increase the font size a bit, good luck tackling the issue, wish i could help but i aint so familiar with C nor Lua either, but will definitely do more research on this stuff, peace ✌

takase1121 commented 3 years ago

(self promotion lmao) After messing around, I have found an at least workable solution for your problem.

Introducing my own plugin that loads multiple fonts.

quadroli commented 3 years ago

Well, after all this time i believe a good fix was found, good work @takase1121 👍