Talk:FMX.Graphics.TCanvas.MeasureText
It is important to know that the input value of ARect is the maximum size range of the rectangle:
procedure TCanvas.MeasureText(var ARect: TRectF; const AText: string;
const WordWrap: Boolean; const Flags: TFillTextFlags; const ATextAlign,
AVTextAlign: TTextAlign);
var
Layout: TTextLayout;
begin
if AText.IsEmpty then
begin
ARect.Right := ARect.Left;
ARect.Bottom := ARect.Top;
Exit;
end;
Layout := TTextLayoutManager.TextLayoutByCanvas(Self.ClassType).Create(Self);
try
Layout.BeginUpdate;
Layout.TopLeft := ARect.TopLeft;
Layout.MaxSize := PointF(ARect.Width, ARect.Height);
Layout.Text := AText;
Layout.WordWrap := WordWrap;
Layout.HorizontalAlign := ATextAlign;
Layout.VerticalAlign := AVTextAlign;
Layout.Font := Self.Font;
Layout.Color := Self.Fill.Color;
Layout.RightToLeft := TFillTextFlag.RightToLeft in Flags;
Layout.EndUpdate;
ARect := Layout.TextRect;
finally
FreeAndNil(Layout);
end;
end;