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

Add proper kerning for RTL scripts(persian, arabic, ...) #529

Closed
IMAN4K opened this issue Mar 2, 2018 · 8 comments
Closed

Add proper kerning for RTL scripts(persian, arabic, ...) #529

IMAN4K opened this issue Mar 2, 2018 · 8 comments

Comments

@IMAN4K
Copy link

IMAN4K commented Mar 2, 2018

Hi @olikraus
Thanks for your great work, it's precious!

I've followed issues and works for supporting kerning for RTL languages in these threads:

I'm going to add this feature to u8g2 but first need to know what part of u8g2 needs modification and what is the right way to do it.
Since adding manual kerning as your last work will not solve the issue: #42 (comment)
So if possible please help me to start.

Regards.
Iman.

@olikraus
Copy link
Owner

olikraus commented Mar 2, 2018

I think there are two different problems.

  1. Combining two glyphs into one under specific conditions [Font Request] Farsi font #234
  2. Reducing the size between glyphs kerning table (follow up #39) #42

Which problem do you want to solve/improve? Both of the problems or only one of the problems?
Basically we could leave problem one to the writer of the text. That means, U8g2 can expect the correct utf-8 code of the combind glyph. So the only problem is the kerning itself. In this case the solution in #42 should be good enough. In fact my suggestion would be to give #42 a try with a bigger portion of text and enhance/improve the method if required.

@IMAN4K
Copy link
Author

IMAN4K commented Mar 2, 2018

At first glance, if i put chars with these unicodes:

Unicode Char
0xFEB3
0xFEE0
0xFE8E
0xFEE1
0xFEA9 د
0xFEE7
0xFEF4
0xFE8E

The string is rendered properly(kerning table is required)!

const uint16_t my_kerning_table[] = {
	/* first char, second char, gap reduction value */
	0x646, 0x627, 4, /* ن and ا */
	0x627, 0x647, 5, /* ا and ه */
	0x647, 0x62C, 6, /* ه and ج */
	0x645, 0x627, 3, /* م and ا */
	0x627, 0x644, 4, /* ا and ل */
	0x644, 0x633, 2, /* ل and س */

	/* this line terminates the table */
	0xffff, 0xffff, 0xffff
};

void setup() {
	LCD.begin();
	LCD.setFont(u8g2_font_unifont_t_arabic);
	LCD.drawExtUTF8(80, 64 / 2, 1, my_kerning_table, "ﺳﻠﺎﻡ دﻧﻴﺎ");
	LCD.sendBuffer();
}

photo_2018-03-02_12-48-37

But with other unicodes(put directly in source) we've discrete chars

@IMAN4K
Copy link
Author

IMAN4K commented Mar 2, 2018

More interesting :)
We've right text in display with even empty kerning table, but without it(drawUTF8(..)) problem exists!
Should dive into drawExtUTF8(...) source, see what's going on.

void setup() {
	LCD.begin();
	LCD.setFont(u8g2_font_unifont_t_arabic);
	LCD.drawExtUTF8(80, 64 / 2, 1, NULL, "ﻤﺎﮬﻲ ﺧﻮﺐ");
	LCD.sendBuffer();
}

photo_2018-03-02_13-32-19

@IMAN4K
Copy link
Author

IMAN4K commented Mar 7, 2018

@olikraus
For now we provide exact unicode for proper text display to drawExtUTF8(...) with empty kerning table.
I'm thinking to have a lookup table to replace the correct unicodes.
e.g
If we have unicode 0x0633:س followed by 0xFEDD:ﻝ then we should replace first one with 0xFEB3:ﺳ and so forth.

@olikraus
Copy link
Owner

olikraus commented Mar 7, 2018

ok, but i think this should be done during typing in the string into Arduino IDE.
I think this is not something for u8g2.

@IMAN4K
Copy link
Author

IMAN4K commented Mar 7, 2018

Adding Kerning for RTL scripts make u8g2 even better!
So if you have no problem with an optional implementation(adding a control macro):
#define U8G2_ENABLE_RTL_KERNING
Let me know to commit in the next few days.

@olikraus
Copy link
Owner

olikraus commented Mar 7, 2018

I tried already some time back. The kerning tables will be VERY huge. That is why I added drawExtUTF8.
Is drawExtUTF8 not sufficient? You can nicely construct the kerning table exactly for your need.

There is one more problem: From where shell I get the kerning information. I do not have the kerning information and I am not able to extract the same from .ttf files.

@olikraus
Copy link
Owner

no further feedback, closing...

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

No branches or pull requests

2 participants