Closed almontasser closed 6 years ago
Sure it's easy to solve.
In Lazarus trunk there is UTF8ReverseString https://github.com/alrieckert/lazarus/blob/master/components/lazutils/lazutf8.pas#L142
That can be used to reverse the string when that option is present. But warning: That function is not available with Lazarus 1.6 and FPC 3.0. Make sure to keep that in account.
Edit: the real TextRect is in the unit BGRAText, however using UTF8ReverseString is not usefull at all.
I've tested with
if style.RightToLeft then sUTF8 := UTF8ReverseString(sUTF8);
But seems that there are other calculations somewhere that affects the width of the string?
That didn't solve it.
The problem is not in the order of the letters, the problem is when you mix right to left text with left to right text, like Arabic and English, or Arabic and Numbers, or Arabic and Symbols.
I'know I tried to locate it, and I got stuck.
TCanvas works as it suppose to, but TBGRABitmap don't.
Yes that happened to my the first time I tried to reverse the string. Everything was reversed and not only the part that is not english.
You know where to find the working code in TCanvas?
https://github.com/alrieckert/lazarus/blob/master/lcl/include/canvas.inc#L1275
if Style.RightToLeft then
Options := Options or DT_RTLREADING;
...
DrawText(DC, pChar(Text), Length(Text), fRect, Options);
Is strange because reading the BGRABitmap code it uses the Canvas to draw the Text, uses the same functions you're using with Canvas internally.
It uses TextOut https://github.com/bgrabitmap/lazpaint/blob/master/bgrabitmap/bgratext.pas#L720
They don't check for RightToLeft at all.
You're right, that's the bug
I gusse It will require a lot of work to support RightToLeft
TCanvas uses ExtUTF8Out, and I was able to make print correctly when I pass it (ETO_RTLREADING=128) in the Options parameter.
https://github.com/alrieckert/lazarus/blob/master/lcl/include/canvas.inc#L1351
Indeed that would be work to handle RightToLeft. In the meantime, you can use the Canvas property of BGRABitmap. It works ok as long as images have an opaque background.
I fixed it on dev branch. I have used the LCL TextRect function. I suppose that also solves the ticket with missing unicode glyphs: https://github.com/bgrabitmap/bgrabitmap/issues/11
By the way, I've added a RightToLeft parameter to TBGRABitmap.TextOut. That allows to use RightToLeft option without having to supply the TRect for TextRect.
TBGRABitmap.TextRec result (the forth line of the image attached) Should be as the TCanvas.TextRec result (the third line of the image attached).
and here is the code I used: