HOST-Oman / libraqm

A library for complex text layout
MIT License
268 stars 62 forks source link

Incorrect resolved paragraph direction #163

Open niello opened 2 years ago

niello commented 2 years ago

https://github.com/HOST-Oman/libraqm/blob/ce67a59b8e19a67c0d5c47dbcf652e70bbdbc6f0/src/raqm.c#L1417-L1420

An assumption is made that everything that is not explicitly LTR is RTL. It fails for direction-neutral paragraphs (FRIBIDI_PAR_ON). This leads to strange results, e.g. a number in a separate paragraph in a completely LTR text is considered RTL.

I suggest to turn FRIBIDI_PAR_ON into RAQM_DIRECTION_DEFAULT, so users can treat it accordingly to their preference. This value should not have any side meaning anyway, e.g. checking whether layouting was performed by inspecting raqm_get_par_resolved_direction is definitely a bad practice.

This sould also be fixed for SheenBIDI but I can't make exact suggestions as I didn't work with it.

niello commented 2 years ago

@khaledhosny , please look at the PR. The fix works perfectly in my case. Now all necessary info is provided to the library user code.

khaledhosny commented 2 years ago

I think the code is assuming par direction is explicitly set, which I think is one way to handle this. Am I right that you are using auto par dir?

vorlov-playrix commented 2 years ago

Yes, I want a multiline editbox to detect text direction per paragraph and align them correctly. Direction-neutral paragraphs are aligned as the above text. But this is only a practical example. The problem is conceptual - there are direction-neutral paragraphs (i.e. "111") and middleware should not suppose any strict direction for them. It should be handled in user code.

khaledhosny commented 2 years ago

I understand that, I was trying to figure out how the original code came to be like that, but it was definitely wrong. Now I need to make sure the SeenBiDi code is fixed the same way.