pencil.js
Version:
Nice modular interactive 2D drawing library.
99 lines (98 loc) • 3.15 kB
TypeScript
/**
* Text class
* <br><img src="./media/examples/text.png" alt="text demo"/>
* @class
* @extends Rectangle
*/
export default class Text extends Rectangle {
/**
* @param {Object} definition - Text definition
* @return {Text}
*/
static from(definition: any): Text;
/**
* Load a font URL
* @param {String|Array<String>} url - URL or an array of URL to font files
* @return {Promise<String>} Promise for the generated font-family
*/
static load(url: string | Array<string>): Promise<string>;
/**
* Return a font definition from a set of options
* @param {TextOptions} options - Chosen options
* @return {String}
*/
static getFontDefinition(options: TextOptions): string;
/**
* @typedef {Object} TextMeasures
* @prop {Number} width - Horizontal size
* @prop {Number} height - Vertical size
*/
/**
* Compute a text width and height
* @param {String|Array<String>} text - Any text
* @param {TextOptions} [options] - Options of the text
* @return {TextMeasures}
*/
static measure(text: string | Array<string>, options?: TextOptions): TextMeasures;
/**
* @typedef {Object} TextAlignments
* @enum {String}
* @prop {String} left - The text is left-aligned.
* @prop {String} right - The text is right-aligned.
* @prop {String} center - The text is centered.
* @prop {String} start - The text is aligned at the normal start of the line. (regarding locales)
* @prop {String} end - The text is aligned at the normal end of the line. (regarding locales)
*/
/**
* @type {TextAlignments}
*/
static get alignments(): any;
/**
* Text constructor
* @param {PositionDefinition} positionDefinition - Top most point of the line start (depend on align option)
* @param {String} [text=""] - Text to display
* @param {TextOptions} [options] - Drawing options
*/
constructor(positionDefinition: any, text?: string, options?: TextOptions);
/**
* @type {Array<String>}
*/
lines: Array<string>;
/**
* Change the text
* @param {String|Array<String>} text - New text value
* @example this.text = "Single line text";
* @example this.text = "Multi\nLine text";
* @example this.text = ["Multi", "Line text"];
* @example this.text = ["Multi", "Line\ntext"];
*/
set text(arg: string);
/**
* Returns the text
* @return {String}
*/
get text(): string;
/**
* Return the position offset according to alignment
* @return {Number}
*/
getAlignOffset(): number;
/**
* Measure the text with current options
* @return {TextMeasures}
*/
getMeasures(): TextMeasures;
}
export type TextMeasures = {
/**
* - Horizontal size
*/
width: number;
/**
* - Vertical size
*/
height: number;
};
export type TextOptions = any;
export type TextAlignments = any;
import Rectangle from "@pencil.js/rectangle";