Search code examples
delphirect

Delphi: calculate Rect height needed for a wordwrapped text


Delphi Rio 10.3.1 + GR32 (TextoutW + DT_WORDBREAK)

I want to draw text on a TBitmap32 using TextoutW from GR32's library, and I want to calculate the necessary height to accommodate wordwrapped text given a MaxWidth parameter and a specific font.

How can I calculate the necessary Rect for this?


Solution

  • The TextoutW method from GR32, at least for the VCL backend, wraps the Windows DrawTextW function. This Windows API function does provide a method to calculate the output rect via the DT_CALCRECT flag. However, the GR32 interface does not return the calculated rect to the caller.

    So instead I suspect that you need to call DrawTextW directly, passing the appropriate flags and the device context (HDC) of the GR32 surface.