Skip to main content
Version: 3.5

TextUtils

Namespace: Wisej.Base

Assembly: Wisej.Framework (3.5.0.0)

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

public class TextUtils

Fields

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

Methods

Static memberEscapeText(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 memberEscapeText(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 memberGetMnemonic(text)

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

ParameterTypeDescription
textStringThe string from which to extract the mnemonic character.

Returns: String.

Static memberMeasureText(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 memberMeasureText(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 memberMeasureText(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 memberMeasureText(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 memberMeasureText(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 memberMeasureText(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 memberMeasureTextAsync(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.