TextGetHeight

Syntax

Height.d = TextGetHeight(Text, ReturnLayoutHeight=#False)

Description

Retrieves the calculated height of the text layout in device-independent pixels (DIPs). Optionally, it can return the maximum layout height constraint set for the text object.

Parameters

Text
The handle of the text object whose height is to be retrieved.

ReturnLayoutHeight (optional)
If set to #True, the function returns the maximum layout height set using TextSetHeight() or during creation. If #False (default), returns the actual calculated height of the rendered text (considering wrapping, font size, etc.).

Return Value

Returns the requested height as a floating-point number (Double) in DIPs. Returns 0.0 or #False if the text handle is invalid. If ReturnLayoutHeight is #True and no layout height was set, it may return 0 or a large default value depending on the underlying text engine.

Remarks

The calculated height (`ReturnLayoutHeight = #False`) represents the actual vertical space occupied by the text after layout, including line spacing and wrapping. The layout height constraint (`ReturnLayoutHeight = #True`) is the value used for vertical alignment and trimming calculations.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

MyText = CreateText("Line 1" + #CRLF$ + "Line 2", "Arial", 14)
TextSetWidth(MyText, 100) ; Set width to allow wrapping

If MyText
    CalculatedHeight.d = TextGetHeight(MyText)
    Debug "Calculated Text Height (DIPs): " + StrD(CalculatedHeight.d) ; Height of the 2 lines

    TextSetHeight(MyText, 50) ; Set a layout height constraint
    LayoutHeight.d = TextGetHeight(MyText, #True)
    Debug "Layout Height Constraint (DIPs): " + StrD(LayoutHeight.d) ; Should be 50.0

    FreeText(MyText)
EndIf

StopProGUI()

See Also

CreateText, TextSetHeight, TextGetWidth, TextSetWidth

Supported OS

Windows, Linux