TCustomLabel.CalcFittingFontHeight function
Calculates the font height needed to fill the specified width and height constraints.
Declaration
function CalcFittingFontHeight(const TheText: string;
MaxWidth: Integer; MaxHeight: Integer;
out FontHeight: Integer;
out NeededWidth: Integer;
out NeededHeight: Integer): BooleanArguments
TheText | Text measured in the method. |
MaxWidth | Width constraint for the text rectangle. |
MaxHeight | Height constraint for the text rectangle. |
FontHeight | Font height calculated in the method. |
NeededWidth | Width needed for the text using the calculated font size. |
NeededHeight | Height needed for the text using the calculated font size. |
Function result
True when the text fits within the size constraints in MaxWidth and MaxHeight.Description
CalcFittingFontHeight is a
Boolean function used to
calculate the maximum font height needed to make the specified string fill
the available space, given the MaxWidth and MaxHeight constraints.
The return value is True when the text rectangle using the new font height fits within the size constraints in MaxWidth and MaxHeight. NeedWidth and NeedHeight are set to the values indicated in the text rectangle. The return value is False when the text rectangle is either too wide or too tall, or cannot be calculated using the specified parameter values.
No actions are performed in the method when AutoSizeDelayed is set to True, when TheText is an empty string, or when MaxHeight or MaxWidth contain 0 or a negative value.
The font height is calculated using a temporary TFont instance with the current Font for the control, setting its drawing flags to calculate the text rectangle. The drawing flags include wrapping when the WordWrap property is set to True. The font height is incrementally increased or decreased until the maximum font height which fits with MaxHeight and MaxWidth is determined.
CalcFittingFontHeight is used in the implementation of the
AdjustFontForOptimalFill method.
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
