Skip to content
Member Filters
Show Inherited
Show Protected
Show abstract
GR32_Paths🞂TCanvas32🞂MeasureTextMethod

TCanvas32.MeasureText

Measures the bounding rectangle required to render specified text within a destination rectangle.

Declarations ​

pascal
function MeasureText(const DstRect: TFloatRect; const Text: string; Flags: Cardinal): TFloatRect; overload;
function MeasureText(const DstRect: TFloatRect; const Text: string; const Layout: TTextLayout): TFloatRect; overload;
Overload Details

Overload 1 ​

pascal
function MeasureText(const DstRect: TFloatRect; const Text: string; Flags: Cardinal): TFloatRect; overload;

Measures text bounding rectangle using formatting flags.

ParameterTypeDescription
DstRectTFloatRectTarget destination rectangle constraint.
TextstringText string to measure.
FlagsCardinalFormatting flags controlling text alignment and wrapping.
TypeDescription
TFloatRectThe bounding rectangle required to render the text under the given formatting flags.

Overload 2 ​

pascal
function MeasureText(const DstRect: TFloatRect; const Text: string; const Layout: TTextLayout): TFloatRect; overload;

Measures text bounding rectangle using a TTextLayout structure.

ParameterTypeDescription
DstRectTFloatRectTarget destination rectangle constraint.
TextstringText string to measure.
LayoutTTextLayoutText layout configuration.
TypeDescription
TFloatRectThe bounding rectangle required to render the text using the specified text layout.

Description ​

MeasureText computes the tight bounding rectangle (TFloatRect) required to layout and render Text within DstRect according to the specified formatting flags or TTextLayout options.

Example ​

pascal
var
  Canvas: TCanvas32;
  ConstraintRect, MeasuredRect: TFloatRect;
begin
  Canvas := TCanvas32.Create(MyBitmap);
  try
    ConstraintRect := FloatRect(0.0, 0.0, 200.0, 1000.0);
    MeasuredRect := Canvas.MeasureText(ConstraintRect, 'Sample multiline text to measure');

    WriteLn(Format('Measured text height: %.1f', [MeasuredRect.Bottom - MeasuredRect.Top]));
  finally
    Canvas.Free;
  end;
end;