Reputation: 524
I want to print Right-to-left Unicode strings on a Canvas. I can't find a BidiMode property or something like that to get it done.
currently the symbols which are located at the end of strings, appear before the first character of the text which is printed on the Canvas.
Upvotes: 0
Views: 1830
Reputation: 1
Had no success to display RTL text with "TextOut" when form bidimode is set to "bdLeftToRight", so I usually used XXX.Canvas.TextRect(Rect,Text,[tfRtlReading,tfRight]); Worked very well for me.. I needed to detect Hebrew, so I did it like this:
function CheckHebrew(s: string): boolean;
var
i: Integer;
begin
Result := false;
for i := 1 to Length(s) do
if (ord(s[i])>=1424) and (ord(s[i])<1535) then
begin
Result := true;
exit;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
tf : TTextFormat;
r : TRect;
s : string;
begin
r.Left := 0;
r.Top := 0;
r.Width := Image1.Width;
r.Height := Image1.Height;
s := Edit1.Text;
if CheckHebrew(s) then
tf := [tfRtlReading,tfRight,tfWordBreak]
else
tf := [tfWordBreak];
Image1.Canvas.FillRect(r);
Image1.Canvas.TextRect(r,s,tf)
end;
Upvotes: 0
Reputation: 596387
FireMonkey does not have any BiDi capabilities at this time.
The Vcl.TControl
class has public DrawTextBiDiModeFlags()
and DrawTextBiDiModeFlagsReadingOnly()
methods, which help the control decide the appropriate BiDi flags to specify when calling the Win32 API DrawText()
function.
In Vcl.Graphics.TCanvas
, its TextOut()
and TextRect()
methods do not use the Win32 API DrawText()
function, they use the Win32 API ExtTextOut()
function instead, where the value of the TCanvas.TextFlags
property is passed to the fuOptions
parameter of ExtTextOut()
. The TextFlags
property also influences the value of the TCanvas.CanvasOrientation
property, which TextOut()
and TextRect()
use internally to adjust the X coordinate of the drawing.
For right-to-left drawing with TCanvas
, include the ETO_RTLREADING
flag in the TextFlags
property.
Upvotes: 6