[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'Graphics' (#lcl)

TCanvas.TextFitInfo

Gets the number of characters that fit in the specified maximum width.

Declaration

Source position: graphics.pp line 1170

public function TCanvas.TextFitInfo(

  const Text: string;

  MaxWidth: Integer

):Integer;

Arguments

Text

  

Text examined in the method.

MaxWidth

  

Maximum width allowed for the character values.

Function result

Number of code points allowed in the specified maximum width.

Description

TextFitInfo is an Integer function used to the determine the number characters from Text that will fit within the maximum width specified in MaxWidth. It is useful for situations where text must be truncated or wrapped to fit within a given area.

Text is a String type and allows UTF-8-encoded multi-bytes values in its content.

MaxWidth contains the maximum number of pixels allowed in the measurement.

TextFitInfo calls the GetTextExtentExPoint routine in the LCL interface to measure each of the characters (UTF-8 code points) in Text. Please note that partial character extents are not used when calling the LCL interface routine.

The return value contains a non-zero value on successful completion of the method, or 0 when number of characters cannot be determined.

Use TextWidth to get width in pixels for a given string value.


Version 3.2 Generated 2024-02-25 Home