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

Cursor of iText in RTL mode (originX == 'right') #2374

Closed
YaakovHatam opened this issue Jul 29, 2015 · 36 comments
Closed

Cursor of iText in RTL mode (originX == 'right') #2374

YaakovHatam opened this issue Jul 29, 2015 · 36 comments
Labels

Comments

@YaakovHatam
Copy link

YaakovHatam commented Jul 29, 2015

EDIT (17/05/2020)

Hello guyz, i have started to write the RTL version of iText, you can take the dist/favric.rtl.js in my forked repository, after i'll finish i will rewrite it and merge to fabric.js repository.

https://github.com/YaakovHatam/fabric.js

hello i made quick fix that allow the cursor behave like it should be in Right-to-Left texts.

in the function:

renderCursor: function(boundaries, ctx) {

i have replaces the code:

boundaries.left + leftOffset,

with:

this.originX === 'right' ? -boundaries.left - leftOffset : boundaries.left + leftOffset,

and now it works proper!

add:
and for the selection the change is:
in the function

renderSelection: function(chars, boundaries, ctx) {

instead

boundaries.left + lineOffset,

replace with

this.originX === 'right' ? -boundaries.left - boxWidth +lineOffset : boundaries.left + lineOffset,
@asturur
Copy link
Member

asturur commented Jul 30, 2015

i don t think right to left text is supported.

what language are you using?

@YaakovHatam
Copy link
Author

@asturur this fix will let you rtl version

@asturur
Copy link
Member

asturur commented Jul 30, 2015

i cannot see why originX should handle text direction.
if rtl.is supported should be supported with any originX and originY.

@YaakovHatam
Copy link
Author

@asturur i use the Hebrew/English languages, when the user want iText with hebrew i set the originX to right, but the cursor still work like left origin.

@asturur
Copy link
Member

asturur commented Jul 30, 2015

Because originX and originY influence just the position where top and left
are originated.
If we will support RTL languages we have to specify a property "this.rtl =
true" we cannot base it on originX that has another meaning.

2015-07-30 13:18 GMT+02:00 yaakov hatam [email protected]:

@asturur https://github.com/asturur i use the Hebrew/English languages,
when the user want iText with hebrew i set the originX to right, but the
cursor still work like left origin.


Reply to this email directly or view it on GitHub
#2374 (comment).

@YaakovHatam
Copy link
Author

@asturur i will add the "rtl" property and will post my enhancement.

@asturur
Copy link
Member

asturur commented Aug 7, 2016

@kob-e did you ever completed this feature?

@asturur
Copy link
Member

asturur commented Aug 7, 2016

reference: #2673, #2766, #2825

@ThakurKarthik
Copy link

@YaakovHatam @asturur any work progress here?

@asturur
Copy link
Member

asturur commented Apr 2, 2020

no. Sadly no progress on RTL text at all

@ThakurKarthik
Copy link

The workaround @YaakovHatam was mentioning at the beginning is not RTL right..it's just cursor manipulation to start from right.Even the text-align also does the same,it still have to be implemented like a css direction : rtl style.Don't know if we can try this algorithm .

@YaakovHatam
Copy link
Author

Hello guyz, i have started to write the RTL version of iText, you can take the dist/favric.rtl.js in my forked repository, after i'll finish i will rewrite it and merge to fabric.js repository.

https://github.com/YaakovHatam/fabric.js

@asturur
Copy link
Member

asturur commented May 13, 2020

Hi @YaakovHatam you may want to open a PR early to gather feedback and comments about the code.

Thanks for trying!

@YaakovHatam
Copy link
Author

YaakovHatam commented May 17, 2020

Thanks @asturur -
My plan is:

  1. Getting a itext working with rtl fully
  2. Rewrite the code within the classes of fabricjs

@asturur
Copy link
Member

asturur commented May 17, 2020

would be great if you share it earlier if you want to contribute it back. When is done and working going back and adapt things to fabricjs style may be hard.

@YaakovHatam
Copy link
Author

YaakovHatam commented May 17, 2020

@asturur I will deal with the RTL issues in the fabric.js . After 3 years of using this amazing library with Hebrew after doing a lot of fixes, I decided to contribute back.
For now, as you can see in the link: https://yaakovhatam.github.io/fabric.js/index.html
The RTL works, the arrow keys now work, the mixed text (Latin / Hebrew / Arabic) works properly. Now I fix the selection of text.
Once I will complete these basics I will discuss with you how to implement it in the source code.

@YaakovHatam
Copy link
Author

It will be nice if the users here will give me some test cases

@amitmas
Copy link

amitmas commented Jul 29, 2020

Looks good, very nice work...
Except the wrong selection position, there is another problem that the text dissapear when scaling horizontally or vertically.

@mistriel
Copy link
Contributor

@YaakovHatam are you going to complete this MR ?

@asturur
Copy link
Member

asturur commented May 16, 2021

We merged a basic implementation of RTL.
#7046

@asturur asturur closed this as completed May 16, 2021
@mistriel
Copy link
Contributor

Initial support was released in version 4.5.0

@vijaygurjar
Copy link

I am checking with RTL support in fabricjs and its look amazing, but i found one issue when manually set cursor at somewhere in middle in text editing mode and writing text then cursor location is not set properly.

@asturur
Copy link
Member

asturur commented Jun 3, 2021

Can you open an issue with a detailed description and a jsfiddle that show this problem, and this problem only?
a clean simple example.

@vijaygurjar
Copy link

Hello asturur
Thanks for your quick reply.
I made sample url : https://jsfiddle.net/vijaygurjar/cj8wy5xu/
edit text to set cursor middle of the text box and writing text but added characters not at right position. May be i am doing some mistake to set properties.

@mistriel
Copy link
Contributor

mistriel commented Jun 5, 2021

From the snippet you created it seems that you are trying to write English (Latin) inside an IText that is set with text direction rtl now that wont work - you will need to set the text direction back to ltr in order to make it work as expected.

@igalya
Copy link

igalya commented Sep 23, 2021

Another issue is when using RTL text and textAlign is 'center' or 'right'.
Cursor is behaving strange.

@asturur
Copy link
Member

asturur commented Sep 26, 2021

Did you try the latest master? i thought we fixed that.

@igalya
Copy link

igalya commented Sep 26, 2021

4.6? yes.

@mistriel
Copy link
Contributor

@asturur it was not fixed. The only way to work with RTL (direction == rtl) and cursor working as expected is to set textAlign to right. Otherwise cursor is not on the correct location.

@chiragbytes
Copy link

Hello @asturur

I am having issue with charSpacing in hebrew selected texts, after applying charSpacing text got flipped.
I found similar issue on #6848 , later tha found to be linked here.

After upgrading fabricJS to 4.6.0 and using new property direction I am still facing the same issue.

FYI, I am using Angular 8 with fabric js in my project.

Here is my code that i am using for applying charSpacing.
obj.set({ 'charSpacing': Math.ceil(Number(event.target.value)) });

Thank you.

@ShaMan123
Copy link
Contributor

#7864

@oustr
Copy link

oustr commented Jun 12, 2024

@asturur I will deal with the RTL issues in the fabric.js . After 3 years of using this amazing library with Hebrew after doing a lot of fixes, I decided to contribute back. For now, as you can see in the link: https://yaakovhatam.github.io/fabric.js/index.html The RTL works, the arrow keys now work, the mixed text (Latin / Hebrew / Arabic) works properly. Now I fix the selection of text. Once I will complete these basics I will discuss with you how to implement it in the source code.

@YaakovHatam Seems that your link is 404 now😥And I'm still confused whether the text selection problem of rtl text is fixed, as I found I couldn't select some part of a rtl text in fabricjs, because when I click at the middle of such a text the cursor is always at the right. Seems that you're working on the rtl problems and I wonder if this bug is fixed, the information and discussions here on github still confuse me a lot

@YaakovHatam
Copy link
Author

@oustr It was a while ago and I don't know where the RTL issue currently stands in the project
Can you write down what the problem is specifically and I'll try to restore?

@asturur
Copy link
Member

asturur commented Jun 28, 2024

In general RTL is poorly supported.
Shaman123 made some work to fix it, but it was a full refactor that i didn't merge.
Before planning a full refactor of text i prefer to stack fixes on the current architecture even if the dev experience for who works on the fix is not great.

Most of the issue we have is because of the difference firefox and chrome handle the RTL text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

12 participants