RichTextFX
RichTextFX copied to clipboard
Support for bidirectional text
Hi,
I know support for bidirectional text is a dropped feature, but could this be implemented? How difficult would this be?
I'm not familiar with RichTextFX code yet but I'm wiling to help with the implementation of BiDi support (done that with other tools before).
Regards, Rodolfo
Hi Rodolfo,
I omitted bidirectional text support for the sake of simplicity and, quite frankly, because I don't have a need for bidi editor. Also, I don't even know how bidi text editor works from user's perspective. For example, how do you insert some right-to-left text into a left-to-right paragraph? Does the editor just know based on the inserted characters? How do you determine the primary directionality of a mixed paragraph? How is selection supposed to work in a bidi paragraph?
I welcome your help and contributions in this area.
Best, Tomas
Hi Tomas,
I'm porting an application from SWT to JavaFX and need a component for editing rich text in any language. RichTextFX seems a good choice but support for Arabic or Hebrew is essential in the tool I'm rewriting.
Yesterday I tried RichTextFX for the first time. The first thing I noticed was that I'm unable to align text to the right, center or to the left. Text alignment is a common feature in JavaFX controls.
The current way to insert text in the caret position is fine. You should not care if the inserted text ir RTL or LTR on inserting. The text may need to be reordered after inserting but that is done using the BiDI algorithm from Unicode Consortium (see http://www.unicode.org/reports/tr9/). Java implements the sorting algorithm in java.text.Bidi.
Selection handling is the same and from a practical point of view you don't care. The user has to deal with keyboard or mouse and you grab whatever is between the starting and ending selection point.
If you are reusing components from JavaFX, those components should already be able to handle BiDi text.
I'll take a look at the source code and compare behavior with SWT's StyledText (that works fine with BiDi text and is what I need to replace in JavaFX).
Thanks, Rodolfo
You are right, text alignment is not supported in a principled way. You can only set the alignment of the whole document in a hacky way (see #74). Per paragraph alignment would come with #6.
I mean how should a selection be highlighted. Assume you have a string "ABCDWXYZ" where ABCD are letters from LTR alphabet and WXYZ are letters from RTL alphabet. Then the text is rendered as "ABCDZYXW", right? How do I select the substring "CDWX"? Should "CD" and "XW" be highlighted, while "ZY" in between them should not?
Regarding the directionality of the paragraph, suppose again the text "ABCDWXYZ". If the paragraph is LTR, then this is rendered as "ABCDZYXW", aligned to the left (i.e. RTL word embedded in a LTR paragraph). If the paragraph is RTL, then it is rendered as "ZYXWABCD", aligned to the right (i.e. LTR word embedded in a RTL paragraph). Am I correct? How do I determine the primary directionality of the paragraph?
Document level alignment is fine. An option for setting it using Java should be added. I was not aware of the possibility of aligning via CSS. Could work as temporary workaround.
When selecting text, you normally only select contiguous characters. Once you use the BiDI algorithm for reordering text, you only work with the reordered string. So, in your example you would only select a fragment from the rendered part, "ZYXWABCD".
The Bidi class can tell you the primary directionality of a text string using baseIsLeftToRight() method. You can rely on the Bidi class and also let the user define the directionality if desired.
Hope this helps, Rodolfo
Hi Tomas,
I am working on a text editor project. As far as I explore RichtextFX is the best choice to provide text editing facility, in case of JavaFX. It's really nice, easy to use and also support many features that I need them. So, from the practical view, I think that I have only this choice.
To clear up the ambiguities, I suggest that take a look at some word processing applications like Microsoft Word, Libreoffice Writer, or Apple Pages to see that how they handle your complex "ABCDWXYZ" samples.
I also have a question. As I understand, the problem comes up when we have a complex document containing both RTL and LTR texts. However in many cases, at least for me, the documents are completely RTL. Is there any solution to extend GenericStyledArea to support these kind of documents? It seems that this assumption could make the problem much easier.
Note that I tested the nodeOrientation
. The texts became correct but the caret and selection were still have problem.
Thanks for considering my request.
@vahidooo Could you please open a new issue describing the caret and selection problems. Thanks.
Thank you @Jugen. It's done. Please see #1170.