Skip to main content
Version: 4.1

TextUtils

Namespace: Wisej.Base

Assembly: Wisej.Framework (4.1.0.0)

Provides utility methods to measure, encode, and extract mnemonics from text.

public static class TextUtils

Fields​

NameTypeDescriptionValue
ConvertToStringFunc<Object, Object, String>Pluggable method used to convert user input to a string.
3.0.10+
MeasureStringFunc<String, Font, Size, StringFormat, SizeF>Pluggable method used to measure strings.

Properties​

Static member DisableMeasurementsCache​

Nullable<Boolean>: Gets or sets a value indicating whether the measurements cache is disabled.

Disabling the measurements cache may impact performance, as caching is used to optimize repeated access to measurement data. Use this property to explicitly enable or disable caching based on application requirements.

Static member MaxMeasurementCacheSize​

Int32: Gets or sets the maximum number of measurements that can be stored in the cache.

This property is intended for internal use and may not be visible in standard development scenarios.

Methods​

Static member EscapeText(text, allowHtml)​

Escapes special characters in the specified string.

ParameterTypeDescription
textStringThe text to escape.
allowHtml optionalBooleanIndicates that HTML tags should not be escaped. The default is false.

Returns: String. The escaped string. Null if the specified string was null, or empty if it was empty.

Static member EscapeText(text, allowHtml, useMnemonic, translateNewLines)​

Removes the ampersand from the text and encodes HTML characters if necessary.

ParameterTypeDescription
textStringThe text to convert.
allowHtmlBooleanWhether to encode HTML characters.
useMnemonicBooleanWhether to convert the first mnemonic to an underlined character.
translateNewLinesBooleanWhether to convert newlines (CRLF) to <BR/>. The conversion is performed only when

allowHtml is false, or, if

allowHtml is true and the text doesn't contain any HTML.

Returns: String. The escaped string. Null if the specified string was null, or empty if it was empty.

Static member GetMnemonic(text)​

Returns the first character that is preceded by an ampersand (&).

ParameterTypeDescription
textStringThe string from which to extract the mnemonic character.

Returns: String.

Static member InvalidateMeasurementsCache()​

Clears the internal measurements cache.

Static member MeasureText(text, font)​

Returns the size of the specified text when rendered with the specified font.

ParameterTypeDescription
textStringThe text to measure.
fontFontThe Font to apply to the measured text.

Returns: Size. The computed Size of the specified text.

Static member MeasureText(text, font, format)​

Returns the size of the specified text when rendered with the specified font.

ParameterTypeDescription
textStringThe text to measure.
fontFontThe Font to apply to the measured text.
formatStringFormatFormatting information.

Returns: Size. The computed Size of the specified text.

Static member MeasureText(text, font, layoutArea)​

Returns the size of the specified text when rendered with the specified font.

ParameterTypeDescription
textStringThe text to measure.
fontFontThe Font to apply to the measured text.
layoutAreaSizeThe Size to use as bounding rectangle for the text.

Returns: Size.

Static member MeasureText(text, font, layoutArea, format)​

Returns the size of the specified text when rendered with the specified font.

ParameterTypeDescription
textStringThe text to measure.
fontFontThe Font to apply to the measured text.
layoutAreaSizeThe Size to use as bounding rectangle for the text.
formatStringFormatFormatting information.

Returns: Size.

Static member MeasureText(text, allowHtml, font, callback)​

Returns the size of the specified text when rendered with the specified font.

ParameterTypeDescription
textStringThe text to measure.
allowHtmlBooleanThe text to measure may contain HTML tags.
fontFontThe Font to apply to the measured text.
callbackAction<Size>Result callback method, invoked when the client has finished measuring the text.

Static member MeasureText(text, allowHtml, font, width, callback)​

Returns the size of the specified text when rendered with the specified font.

ParameterTypeDescription
textStringThe text to measure.
allowHtmlBooleanThe text to measure may contain HTML tags.
fontFontThe Font to apply to the measured text.
widthInt32The width to use as bounding rectangle for the text.
callbackAction<Size>Result callback method, invoked when the client has finished measuring the text.

Static member MeasureTextAsync(text, allowHtml, font, width)​

Asynchronously returns the size of the specified text when rendered with the specified font. The measurement is performed on the browser. Returns an awaitable Task that contains the measured size.

ParameterTypeDescription
textStringThe text to measure.
allowHtmlBooleanThe text to measure may contain HTML tags.
fontFontThe Font to apply to the measured text.
width optionalInt32The optional width to use as bounding rectangle for the text.

Returns: Task<Size>. An awaitable Task that represents the asynchronous operation.