Text

A text shape

options OptionsStore

The configuration of this element.

Constructors

Text (content: string, position: Point | number[], options?: TextOptions)

Creates a new Text instance

Parameters

content string

The content of the text. Control characters are not supported.

position Point | number[]

The position of the text upper left corner.

options? TextOptions

The configuration options.

Methods

bbox

Returns the bounding box of the element with applied transformations.

Returns

Rect - The bounding box of the element with transformations applied.

clip

Gets the clipping path for this element.

Returns

Path - The clipping path for this element.

clip

Sets the clipping path for this element. The Path instance will be monitored for changes. Can be replaced by calling the clip method.

The following example demonstrates how to set a clipping path on a Circle.

import { Circle, Surface, Path, geometry } from '@progress/kendo-drawing';
const { transform, Circle: GeomCircle } = geometry;

export function drawScene(surface) {
  // Create the circle geometry and shape
    const geometry = new GeomCircle([ 100, 100 ], 80);
    const circle = new Circle(geometry, {
        stroke: { color: "red", width: 1 }
    });

  // Create a clipping path
    const clipPath = new Path();
    clipPath.moveTo(0, 0).lineTo(100, 100).lineTo(100, 0).close();

  // Clip the circle
    circle.clip(clipPath);

  // Render the group on the surface
    surface.draw(circle);
}

The following example demonstrates how to clear a clipping path.

import { Circle, Surface, Path, geometry } from '@progress/kendo-drawing';
const { transform, Circle: GeomCircle } = geometry;

export function drawScene(surface) {
  // Create the circle geometry and shape
    const geometry = new GeomCircle([ 100, 100 ], 80);
    const circle = new Circle(geometry, {
        stroke: { color: "red", width: 1 }
    });

  // Create a clipping path
    const clipPath = new Path();
    clipPath.moveTo(0, 0).lineTo(100, 100).lineTo(100, 0).close();

  // Clip the circle
    circle.clip(clipPath);

  // Render the group on the surface
    surface.draw(circle);

    setTimeout(() => {
        circle.clip(null);
    }, 2000);
}

Parameters

clip Path

The element clipping path.

clippedBBox

Returns the bounding box of the element with clipping and transformations applied. This is the rectangle that will fit around the actual rendered element.

Returns

Rect - The bounding box of the element with clipping and transformations applied.

containsPoint

Returns true if the shape contains the specified point.

Parameters

point Point

The point that should be checked.

Returns

boolean value indicating if the shape contains the point.

content

Gets the text content.

Returns

string The current text content.

content

Sets the text content.

Parameters

value string

The new text content.

fill

Sets the fill of the Shape (see the basic usage example).

Parameters

color string

The fill color to set.

opacity? number

The fill opacity to set.

Returns

Text - The current instance to allow chaining.

opacity

Gets the element opacity.

Returns

number The current element opacity.

opacity

Sets the opacity of the element.

import { Surface, Path } from '@progress/kendo-drawing';

export function drawScene(surface) {
  // Draw a path
    const path = new Path({
        stroke: {
            color: 'red',
            width: 10
        }
    });
    path.moveTo(25, 75).lineTo(75, 25);

  // Set its opacity to 50%
    path.opacity(0.5);

  // Render the group on the surface
    surface.draw(path);
}

Parameters

opacity number

The element opacity. Ranges from 0 (completely transparent) to 1 (completely opaque).

position

Gets the position of the text upper left corner.

Returns

Point The position of the text upper left corner.

position

Sets the the position of the text upper left corner.

Parameters

value Point | number[]

The new position of the text upper left corner.

stroke

Sets the stroke of the Shape.

Parameters

color string

The stroke color to set.

width? number

The stroke width to set.

opacity? number

The stroke opacity to set.

Returns

Text - The current instance to allow chaining.

transform

Gets the transformation of the element.

Returns

Transformation - The current transformation on the element.

transform

Sets the transformation of the element.

import { Surface, Path, geometry } from '@progress/kendo-drawing';
const { transform } = geometry;

export function drawScene(surface) {
  // Draw a path
    const path = new Path({
        stroke: {
            color: 'red',
            width: 10
        }
    });
    path.moveTo(25, 50).lineTo(75, 50);

  // Rotate the path
    path.transform(transform().rotate(-45, [ 50, 50 ]));

  // Render the group on the surface
    surface.draw(path);
}

Parameters

transform Transformation

The transformation to apply to the element.

visible

Gets the visibility of the element.

Returns

boolean true if the element is visible. Otherwise, returns false.

visible

Sets the visibility of the element.

import { Surface, Path, geometry } from '@progress/kendo-drawing';
const { transform } = geometry;

export function drawScene(surface) {
  // Draw a path
    const path = new Path({
        stroke: {
            color: 'red',
            width: 10
        }
    });
    path.moveTo(25, 50).lineTo(75, 50);

  // Toggle the visibility of the path
    setInterval(() => {
        path.visible(!path.visible());
    }, 500);

  // Render the group on the surface
    surface.draw(path);
}

Parameters

visible boolean

A flag which indicates if the element will be visible.

 /