Search code examples
delphicanvasbidi

Delphi Canvas Textout with RightToLeft BidiMode


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.


Solution

  • FMX

    FireMonkey does not have any BiDi capabilities at this time.

    VCL

    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.