import { mat4 } from 'gl-matrix'; import { ChangeLookup } from '../changelookup'; import { Color } from '../color'; import { FontFace } from './fontface'; import { GlyphVertices } from './glyphvertices'; import { Text } from './text'; /** * Object comprising a text reference, a font face, and additional typographic information for type setting, rendering, * and interaction. Multiple labels might reference the same text, but could be placed at different locations or * rendered applying different font faces, styles etc. */ export declare abstract class Label { private static readonly DEFAULT_COLOR; private static readonly DEFAULT_ELLIPSIS; /** @see {@link text} */ protected _text: Text; /** @see {@link alignment} */ protected _alignment: Label.Alignment; /** @see {@link lineAnchor} */ protected _lineAnchor: Label.LineAnchor; /** @see {@link lineWidth} */ protected _lineWidth: number; /** @see {@link fontSize} */ protected _fontSize: number; /** @see {@link fontSizeUnit} */ protected _fontSizeUnit: Label.Unit; /** @see {@link fontFace} */ protected _fontFace: FontFace | undefined; /** @see {@link color} */ protected _color: Color; /** @see {@link background} */ protected _backgroundColor: Color; /** @see {@link type} */ protected _type: Label.Type; /** @see {@link staticTransform} */ protected _staticTransform: mat4; /** @see {@link dynamicTransform} */ protected _dynamicTransform: mat4; /** @see {@link extent} */ protected _extent: [number, number]; /** @see {@link altered} */ protected readonly _altered: ChangeLookup & { any: boolean; color: boolean; resources: boolean; text: boolean; typesetting: boolean; static: boolean; dynamic: boolean; }; /** @see {@link wrap} */ protected _wrap: boolean; /** @see {@link elide} */ protected _elide: Label.Elide; /** @see {@link ellipsis} */ protected _ellipsis: string; /** * Returns the window device pixel ratio. If this is not available/undefined 1.0 is returned. */ static devicePixelRatio(): number; /** * Constructs an unconfigured, empty label. Depending on the label type, transformations are applied * once when typesetting (static) or every frame during rendering (dynamic). * @param text - The text that is displayed by this label. * @param type - Either static or dynamic. If static is used, all transformations are baked and modifications to * any of the label's transformations are expected to occur less often. * @param fontFace - The font face that should be used for that label, or undefined if set later. */ constructor(text: Text, type: Label.Type, fontFace?: FontFace); /** * Creates an Array of glyph vertices, ready to be used in the Typesetter. */ protected vertices(): GlyphVertices; /** * Interface intended to compute/update the label's static and dynamic transformations as well as invoking the * typesetter in order to create the glyph vertices. Returns undefined, if previous vertices can be reused since no * typesetting was required. Returns an empty GlyphVertices storage if label is invalid or cannot be rendered ... */ abstract typeset(): GlyphVertices | undefined; /** * Returns the character at the specified index. * @param index - The zero-based index of the desired character. * @returns character at the specified index */ charAt(index: number): string; /** * Returns the Unicode value (codepoint) of the character at the specified location. * @param index - The zero-based index of the desired character. If there is no character at the specified index, * NaN is returned. * @returns - codepoint of the char at given index or NaN */ charCodeAt(index: number): number; /** * Returns, whether or not the character at a given index is equal to the default or the text's line feed character. * @param index - The zero-based index of the desired character. If there is no character at the specified index, * NaN is returned. * @returns - true if char at given index equals the text's line feed character */ lineFeedAt(index: number): boolean; /** * Gets the kerning value before (i.e., left in left-to-right writing systems) the given glyph index. * @param index - index of the glyph in this label * @returns - kerning value before glyph at given index */ kerningBefore(index: number): number; /** * Gets the kerning value after (i.e., right in left-to-right writing systems) the given glyph index. * @param index - index of the glyph in this label * @returns - kerning value after glyph at given index */ kerningAfter(index: number): number; /** * Returns the advancement of the glyph at given index. * @param index - The zero-based index of the desired character. If there is no character at the specified index, * NaN is returned. * @returns - advancement of the glyph at given index or NaN */ advance(index: number): number; /** * Convenience getter to the label's text as string. * @returns the label's text as string */ toString(): string; /** * Intended for resetting alteration status. */ reset(): void; /** * Text that is to be rendered. */ set text(text: Text); get text(): Text; /** * Read-only access to this labels type specified at construction time. Static labels are baking as much * transformations as possible into the glyph vertices (used for GPU). This means, when the position or size * changes, the label must be typeset again and vertices are fully re-computed. For dynamic labels, only most * relevant transformations are applied and dynamic transformations such as rotation, translation, scale etc, * are applied during rendering without requiring re-typesetting or re-computation of vertices. The type, * however, does not relate to the text. Whenever the text changes, re-typesetting etc. have to be invoked. */ get type(): Label.Type; /** * Length of the text, i.e., number of characters within the text. */ get length(): number; /** * Character that is to be used for Line feed. */ get lineFeed(): string; /** * If enabled, breaks lines automatically at line width (while typesetting). Note that elide mode takes precedence. */ set wrap(flag: boolean); get wrap(): boolean; /** * If enabled, shrinks the label to line width. Depending on the elide mode, the ellipses is put left, middle, or * right. The ellipsis string can be adjusted (@see {@link ellipsis}). If the labels text does not exceed the line * width no elide will be applied. */ set elide(elide: Label.Elide); get elide(): Label.Elide; /** * Allows to override/customize the ellipsis string used for text elide (@see {@link elide}). */ set ellipsis(ellipsis: string); get ellipsis(): string; /** * Line width used to either maximum length for elide or maximum length for line breaks due to word wrap. The line * width is expected in font size. */ set lineWidth(lineWidth: number); /** * Width of a single line in typesetting space (the unit used while Typesetting, i.e., the unit as the font face's * glyph texture atlas). Since the font face needs to be defined in order to typeset, we assume here that the label * has a defined fontFace. */ get lineWidth(): number; /** * Horizontal text alignment for typesetting. */ set alignment(alignment: Label.Alignment); get alignment(): Label.Alignment; /** * Vertical text anchor point used for positional reference. */ set lineAnchor(anchor: Label.LineAnchor); get lineAnchor(): Label.LineAnchor; /** * The currently used font size. * (@see {@link fontSizeUnit}) */ set fontSize(size: number); get fontSize(): number; /** * This unit is used for the font size. * (@see {@link fontSize}) */ set fontSizeUnit(unit: Label.Unit); get fontSizeUnit(): Label.Unit; /** * Font face used for typesetting, transformation, and rendering. To avoid unnecessary state changes when rendering, * prefer to add labels of the same font face consecutively (since this specifies draw sequence and state change * occurs whenever font face changes between two subsequent labels). */ set fontFace(fontFace: FontFace | undefined); get fontFace(): FontFace | undefined; /** * Color used for text rendering. */ set color(color: Color); get color(): Color; /** * Color used for background of text rendering. */ set backgroundColor(color: Color); get backgroundColor(): Color; /** * Transformation used to move, scale, rotate, skew, etc. the label into an arbitrary coordinate space (e.g., * screen space, world space, ...). This can be set either explicitly or implicitly using various transformation * utility functions. @todo review/refine this. */ set staticTransform(transform: mat4); get staticTransform(): mat4; /** * Stores the resulting dynamic transform. This is intended to be used when in dynamic mode. * (e.g., for calculations to the final transform). */ set dynamicTransform(t: mat4); get dynamicTransform(): mat4; /** * The typesetter sets this extent after typesetting and applying the static transform. Don't set this manually * without typesetting. */ set extent(e: [number, number]); /** * Returns the width and height of the typset label in fontSizeUnit. Both are zero if not typeset yet. The static * transform is already applied. */ get extent(): [number, number]; get altered(): boolean; /** * Returns whether or not this label is ready to be rendered (aka has a font face with valid texture * as well as a text with a length > 0). */ get valid(): boolean; } export declare namespace Label { enum Type { Static = "static", Dynamic = "dynamic" } enum Elide { None = "none", Left = "left", Middle = "middle", Right = "right" } enum Alignment { Left = "left", Center = "center", Right = "right" } enum LineAnchor { Top = "top", Ascent = "ascent", Center = "center", Baseline = "baseline", Descent = "descent", Bottom = "bottom" } /** * This unit is used for the font size and related calculations. */ enum Unit { World = "world", Pixel = "pixel", Mixed = "mixed" } }