mathew-kurian / TextJustify-Android

:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0
https://github.com/bluejamesbond/TextJustify-Android/wiki
Apache License 2.0
1.86k stars 369 forks source link

Arabic support #54

Open Shuhrat-java opened 9 years ago

Shuhrat-java commented 9 years ago

Hi, first of all thanks for sharing great work. Let me show some issues related with arabic text: 1.We see that your justify logic is by adding spaces and fill free spaces in one row, but in arabic if you divide letters which related to one word, meaning is broken. So if we put arabic text, sometimes if one arabic word has space between letters your logic divide one word to parts. 2.In arabic text, words are being displayed correctly by meaning, but appearing from left to right not from right to left. How to fix that issue?

mathew-kurian commented 9 years ago
  1. I am not sure about. Can you explain more?
  2. Yes you can. documentView.getLayoutParams().setReverse(true)
khaledhosny commented 9 years ago

Can you give examples of Arabic text with spaces between parts of the same word, I don’t think such spaces are valid.

mathew-kurian commented 9 years ago

I don't know Arabic unfortunately, so can you give me rules that might help imrpove this library.

khaledhosny commented 9 years ago

My question was for the OP actually.

Basic Arabic script justification requires just increasing the spacing between words (just like basic Latin justification), and no letter-spacing at all (letter-spacing is not allowed in Arabic or any other cursive script as it breaks word shaping). Also there is generally no hyphenation in Arabic (some languages using the Arabic script allow hyphenation, though that is the exception not the rule).

More advanced Arabic justification would require word elongation (AKA kashida), but that is much harder to achieve as it is font-dependent and the current font formats and layout engine provide very little (or even nothing at all) to properly handle it, so I think it can be ignored for now.

mathew-kurian commented 9 years ago

@khaledhosny Currently, the library only increases spacing between letters in words only if words don't fit inside one line. And I will look into kashida when I get a chance

Shuhrat-java commented 9 years ago

@bluejamesbond documentView.getLayoutParams().setReverse(true) this will reverse all text given. However in my text there is arabic text with translation. So reverse method affecting all text, including translated text. Also without reversing, when we use Arabic Reshaper Utilities(https://github.com/agawish/Better-Arabic-Reshaper/) for arabic text, words are appearing in correct way but their position is not correct, I mean words appearing from LTR not RTL

Shuhrat-java commented 9 years ago

We have mixed arabic and formatted text, how could we get correct text using documentlayout? Could you provide with some sample code?

mathew-kurian commented 9 years ago

Try DirectionSpan. Set it as you would any other span. Just remember mixing left-to-right with right-to-left can cause unintended results if they are in the same line.

new DirectionSpan(Direction.RIGHT_TO_LEFT)

EDIT: I apologize this is embarrassing. I had created the classes in all intention of adding support, but didn't have the time. So, this feature is yet to be added.

mathew-kurian commented 9 years ago

@Shuhratjava I have added support, but it is barely tested so i will release it as a snapshot which is accessible via gradle at 2.0.7-SNAPSHOT. Let me know if you have any problems.

Please refer to MixedRTLTest for how to use DirectionSpans

narutouzumaki32 commented 9 years ago

Thanks for this great shared library, but it cannot support persian or arabic text. When I set direction, my word draw from last to start, instead of start to last. I means this: my Word is : "سلام" and its draw like this: "مالس" .
(if you dont understand persian see this example: let me "1234" -> "4321" )

saeedjassani commented 8 years ago

@samanmari use documentView.getLayoutParams().setReverse(true)