Calculates the height a word-wrapped string would need given a certain font and width limit.

Syntax

Height = SRP_String("GetHeight", String, Font, Width, LineBreakDelim)

Parameters

ParameterDescription
StringThe string to be measured. (REQUIRED)
FontThe font used when measuring the string. (REQUIRED)
WidthThe maximum width the string can use before word wrapping. (REQUIRED)
LineBreakDelimThe delimiter acting as line breaks. (OPTIONAL)

Returns

The height, in pixels, the string would occupy on the screen.

Remarks

The GetHeight service measures multilined strings as they would appear on the screen using a given font. This is useful when you want to calculate the size of a popup to fit the given text.

The Font parameter uses the standard FONT structure in OpenInsight and SRP ActiveX Controls. This allows the service to take into account a font's unique attributes, size, weight, etc.

The Width parameter is very important since this service will take word wrapping into account. In order to calculate the height, a width constraint must be provided, for a width of 300 will produce a different result than a width of 900. The width is in pixels.

The LineBreakDelim is an optional parameter useful when you have delimiters representing line breaks. When omitted, @TM is used. The delimiter is converted into hard line breaks (CRLFs) before the string is measured. CRLFs that were already in the string are also taken into account when measuring. If there are no hard line breaks, word wrapping is still considered in the final calculation.

Example

// Long sample text. No line breaks, but there should be plenty of word wrapping
String  = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et '
String := 'dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex '
String := 'ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu '
String := 'fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt '
String := 'mollit anim id est laborum.'

// Font used to measure
Font = 'Calibri' : @SVM : 11 : @SVM : 400

// Measure the height given a 300 pixel maximum width
Height = SRP_String("GetHeight", String, Font, 300)

See Also

GetWidth

 

  • No labels