This question was created in reference to: [RTL Localization Support Questions in [Content removed]
Hi,
we tried to implement the workaround for text justification with RTL text and found a bug with the “Invariant Left” justification. For some reason, all but the last line in multi line texts are positioned incorrectly. Here is a screenshot from two similar text widgets, the first with justification “Left” and the second with “Invariant Left” (which should be the same for the text):
[Image Removed]
This is quite a big problem for us, as we wanted to use the Invariant Left/Right for most of our text widgets. Is there a workaround for this problem?
Thanks for reporting this issue. I was able to reproduce the behavior in UE 5.6, 5.7.3, and the latest source build (UE5-Main CL 51069643). I’ll investigate further and update you soon.
After further investigating this behavior, it appears that during justification, the editor performs an adjustment to remove leftover whitespaces caused by text wrapping. This adjustment is only applied during Left/Right justification. For Invariant Left and Invariant Right, this step is not done, which leads to the issue you described.
You can manually fix this in a source build by updating the FTextLayout::JustifyLayout() method in the if-statement where LineJustificationWidth is set:
// The JustificationWidth of a line omits any trailing whitespace that might have been left over from soft-wrapping the text
// We only want to use this (rather than the full line width) when the justification is at odds with the text flow direction at the edge being justified
// That is, when right-justifying LTR text we will use the JustificationWidth as the trailing whitespace is visually on the right, but when
// right-justifying RTL text we will use the full line width as the trailing whitespace is visually on the left
float LineJustificationWidth = LineView.JustificationWidth;
if ( ( (VisualJustification == ETextJustify::Right || VisualJustification == ETextJustify::InvariantRight) && LineView.Blocks.Last()->GetTextContext().TextDirection == TextBiDi::ETextDirection::RightToLeft) ||
( (VisualJustification == ETextJustify::Left || VisualJustification == ETextJustify::InvariantLeft) && LineView.Blocks[0]->GetTextContext().TextDirection == TextBiDi::ETextDirection::LeftToRight))
{
LineJustificationWidth = LineView.Size.X;
}
This change will be applied when you have combinations like InvariantLeft+LTR or InvariantRight+RTL so leftover whitespaces are removed. This fix worked in a recent source build from UE5-Main, so it should resolve the issue for you.
Please let me know if this workaround helps with your case. Since this seems to be an editor issue, I will also submit a bug report to the engine team so they can review it and introduce a fix in the engine.
Thanks a lot for the reply with the fix. We tried it and it works perfectly! We would appreciate it, if the fix would make it in to the engine, as we are still using the precompiled engine version for our project (easier to update to the next version & less maintenance).
I noticed another small problem, while trying out all the different justification & RTL/LTR/Mixed text options. For mixed text e.g.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. هناك حقيقة مثبتة منذ زمن طويل وهي أن المحتوى المقروء لصفحة ما سيلهي القارئ عن التركيز على الشكل الخارجي للنص أو شكل توضع الفقرات في الصفحة التي يقرأها. ولذلك يتم استخدام طريقة لوريم إيبسوم لأنها تعطي توزيعاَ طبيعياَ -إلى حد ما- للأحرف عوضاً عن استخدام "هنا يوجد محتوى نصي، هنا يوجد محتوى نصي" فتجعلها تبدو (أي الأحرف) وكأنها نص مقروء. العديد من برامح النشر المكتبي وبرامح تحرير صفحات الويب تستخدم لوريم إيبسوم بشكل إفتراضي كنموذجthe Left & Invariant Left justification still seems to have alignment problems if mixed text is on the same line and the text starts with LTR text:
[Image Removed]and Right & Invariant Right justification if the text starts with RTL text:
I’ve gone ahead and submitted a bug report for the engine team to review. You will be able to track its status in the following link: https://issues.unrealengine.com/issue/UE\-367716\. Please note that newly created issues may take some time to become publicly visible.
Regarding the additional problem you described, the suggested change does produce the issue you mentioned for combinations like InvariantLeft+RTL or InvariantRight+LTR.
As a temporary workaround, you can try forcing the justification width logic to use the full line width for invariant justifications:
In my local testing this helps avoid the incorrect per-line offsets for those invariant+direction combinations, but it may introduce a small visual gap near the edge.
You may use this in the meantime until a proper fix is addressed.