Advance text rendering on canvas lazarus / 31-LCL ---------------------------------------------------------------------- stoffman · 2021-07-11 09:24 Hi, I'm familiar with TextOut. But I'm looking for something along the lines of Win32 DrawTextEx (That provides alignment, word wrapping and some other niceties) that is also cross platform. It would be great if it also supports different colors (TextOut/DrawTextEx uses the current pen color)  Any suggestions ? https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser- drawtextexa Thanks, ---------------------------------------------------------------------- wp · 2021-07-11 09:31 AFAIK, DrawTextEx is not available in LCLIntf, in contrast to DrawText. The basic DrawText functionality is also available in the TCanvas.TextRect method which respects the TextStyle record of TCanvas. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TTextStyle = packed record    Alignment : TAlignment;  // TextRect Only: horizontal alignment     Layout    : TTextLayout; // TextRect Only: vertical alignment     SingleLine: boolean;     // If WordBreak is false then process #13, #10 as                             // standard chars and perform no Line breaking.     Clipping  : boolean;   // TextRect Only: Clip Text to passed Rectangle     ExpandTabs: boolean;     // Replace #9 by apropriate amount of spaces (default is usually 8)     ShowPrefix: boolean;     // TextRect Only: Process first single '&' per                             //    line as an underscore and draw '&&' as '&'     Wordbreak : boolean;     // TextRect Only: If line of text is too long                             //    too fit between left and right boundaries                           //    try to break into multiple lines between                           //    words                             //    See also EndEllipsis.     Opaque    : boolean;     // TextRect: Fills background with current Brush                             // TextOut : Fills background with current                             //          foreground color     SystemFont: Boolean;     // Use the system font instead of Canvas Font        RightToLeft: Boolean;    //For RightToLeft text reading (Text Direction)     EndEllipsis: Boolean;    // TextRect Only: If line of text is too long                           //    to fit between left and right boundaries                           //    truncates the text and adds "..."                           //    If Wordbreak is set as well, Workbreak will                           //    dominate.  end;   TCanvas = class(TFPCustomCanvas)  ...    procedure TextRect(const ARect: TRect; X, Y: integer; const Text: string);    procedure TextRect(ARect: TRect; X, Y: integer; const Text: string;                       const Style: TTextStyle); virtual;  end; ---------------------------------------------------------------------- jamie · 2021-07-11 12:07 it's unfortunate the canvas.TextRect(… did not define the TRECT as a VAR because you can not use that function if all you want to do is simply calculate the rectangle without painting. However, all is not lost..  the LCLINTF unit which makes cross platform calls does have the DrawText which accepts the same parameters as the windows counter part..  So all one needs to do is just include the unit.