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.
| Parameter | Type | Description |
|---|---|---|
DstRect | TFloatRect | Target destination rectangle constraint. |
Text | string | Text string to measure. |
Flags | Cardinal | Formatting flags controlling text alignment and wrapping. |
| Type | Description |
|---|---|
TFloatRect | The 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.
| Parameter | Type | Description |
|---|---|---|
DstRect | TFloatRect | Target destination rectangle constraint. |
Text | string | Text string to measure. |
Layout | TTextLayout | Text layout configuration. |
| Type | Description |
|---|---|
TFloatRect | The 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;