DS Server

Javascript: TextCharCollection.getItem Method

Method|Introduced in 28.0

Description

Gets a particular character from the collection specified through a certain geometrical position.

Syntax

<void> TextCharCollection.getItem(<Point> location, <boolean> getNearest, <RequestTextCharCallback> callback, [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
location

Specifies the character's location. The point must be specified in pixels with an origin at the top left corner of the control.

getNearest

Specifies whether the nearest character is returned. If this parameter is set to true, the nearest character is returned. Otherwise, if set to false, a character is only returned, if the specified location is inside the bounding rectangle of an existing character.

callback

Receives the textchar at the certain geometrical position.

errorCallback

Optional. Is called when the operation failed with an error.

Examples

The following example demonstrates TextCharCollection.getItem in a practical document-editing workflow. It gets a particular character from the collection specified through a certain geometrical position.

function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

function inspectItem(textChars) {
    textChars.getItem(
        { x: 1440, y: 720 },
        true,
        function(textChar) {
            if (!textChar) {
                console.warn("No text char was returned.");
                return;
            }
            
            console.log("get item result:", textChar);
        },
        onTxError
    );
}