import TextOptions from "./TextOptions"; import TextFormat from "./TextFormat"; import ITextCompositor from "./ITextCompositor"; import BitmapFont from "./BitmapFont"; import MeshStyle from "../styles/MeshStyle"; import Painter from "../rendering/Painter"; import DisplayObjectContainer from "../display/DisplayObjectContainer"; import DisplayObject from "../display/DisplayObject"; import Rectangle from "openfl/geom/Rectangle"; import Point from "openfl/geom/Point"; declare namespace starling.text { /** * A TextField displays text, using either standard true type fonts, custom bitmap fonts, * * or a custom text representation. * * * *
Access the format property to modify the appearance of the text, like the
* * font name and size, a color, the horizontal and vertical alignment, etc. The border property
* * is useful during development, because it lets you see the bounds of the TextField.
There are several types of fonts that can be displayed:
* * * *registerBitmapFont, and then pass
* * the font name to the corresponding property of the text field.ITextCompositor
* * interface can be used to render text. If the two standard options are not sufficient
* * for your needs, such a compositor might do the trick.For bitmap fonts, we recommend one of the following tools:
* * * *When using a bitmap font, the 'color' property is used to tint the font texture. This
* * works by multiplying the RGB values of that property with those of the texture's pixel.
* * If your font contains just a single color, export it in plain white and change the 'color'
* * property to any value you like (it defaults to zero, which means black). If your font
* * contains multiple colors, change the 'color' property to Color.WHITE to get
* * the intended result.
Normally, TextFields will require exactly one draw call. For TrueType fonts, you cannot * * avoid that; bitmap fonts, however, may be batched if you enable the "batchable" property. * * This makes sense if you have several TextFields with short texts that are rendered one * * after the other (e.g. subsequent children of the same sprite), or if your bitmap font * * texture is in your main texture atlas.
* * * *The recommendation is to activate "batchable" if it reduces your draw calls (use the * * StatsDisplay to check this) AND if the text fields contain no more than about 15-20 * * characters. For longer texts, the batching would take up more CPU time than what is saved * * by avoiding the draw calls.
* */ export class TextField extends DisplayObjectContainer { /** * Create a new text field with the given properties. */ constructor(width: number, height: number, text?: string, format?: TextFormat, options?: TextOptions); /** * The Context3D texture format that is used for rendering of all TrueType texts. * * The default provides a good compromise between quality and memory consumption; * * useContext3DTextureFormat.BGRAfor the highest quality. * * * * @default Context3DTextureFormat.BGRA_PACKED */ static get defaultTextureFormat(): string; static set defaultTextureFormat(value: string) /** * The default compositor used to arrange the letters of the text. * * If a specific compositor was registered for a font, it takes precedence. * * * * @default TrueTypeCompositor * */ static get defaultCompositor(): ITextCompositor; static set defaultCompositor(value: ITextCompositor) /** * Updates the list of embedded fonts. Call this method when you loaded a TrueType font * * at runtime so that Starling can recognize it as such. */ static updateEmbeddedFonts(): void; /** * Makes a text compositor (like a
BitmapFont) available to any TextField in
* * the current stage3D context. The font is identified by its name (not
* * case sensitive).
*/
static registerCompositor(compositor: ITextCompositor, name: string): void;
/**
* Unregisters the text compositor and, optionally, disposes it.
*/
static unregisterCompositor(name: string, dispose?: boolean): void;
/**
* Returns a registered text compositor (or null, if the font has not been registered).
* * The name is not case sensitive.
*/
static getCompositor(name: string): ITextCompositor;
/**
* Makes a bitmap font available at any TextField in the current stage3D context.
* * The font is identified by its name (not case sensitive).
* * Per default, the name property of the bitmap font will be used, but you
* * can pass a custom name, as well. @return the name of the font.
*/
static registerBitmapFont(bitmapFont: BitmapFont, name?: string): string;
/**
* Unregisters the bitmap font and, optionally, disposes it.
*/
static unregisterBitmapFont(name: string, dispose?: boolean): void;
/**
* Returns a registered bitmap font compositor (or null, if no compositor has been
* * registered with that name, or if it's not a bitmap font). The name is not case
* * sensitive.
*/
static getBitmapFont(name: string): BitmapFont;
/**
* Disposes the underlying texture data.
*/
override dispose(): void;
/**
* @inheritDoc
*/
override render(painter: Painter): void;
/**
* Forces the text to be recomposed before rendering it in the upcoming frame. Any changes
* * of the TextField itself will automatically trigger recomposition; changes in its
* * parents or the viewport, however, need to be processed manually. For example, you
* * might want to force recomposition to fix blurring caused by a scale factor change.
*
*/
setRequiresRecomposition(): void;
/**
* Returns the bounds of the text within the text field.
*/
get textBounds(): Rectangle;
/**
* @inheritDoc
*/
override getBounds(targetSpace: DisplayObject, out?: Rectangle): Rectangle;
/**
* Returns the bounds of the text within the text field in the given coordinate space.
*/
getTextBounds(targetSpace: DisplayObject, out?: Rectangle): Rectangle;
/**
* @inheritDoc
*/
override hitTest(localPoint: Point): DisplayObject;
/**
* The displayed text.
*/
get text(): string;
set text(value: string)
/**
* The format describes how the text will be rendered, describing the font name and size,
* * color, alignment, etc.
* *
* * Note that you can edit the font properties directly; there's no need to reassign * * the format for the changes to show up.
* * * *This works only with bitmap fonts, and it makes sense only for TextFields with no * * more than 10-15 characters. Otherwise, the CPU costs will exceed any gains you get * * from avoiding the additional draw call.
* * * * @default false * */ get batchable(): boolean; set batchable(value: boolean) /** * Indicates if text should be interpreted as HTML code. For a description * * of the supported HTML subset, refer to the classic Flash 'TextField' documentation. * * Clickable hyperlinks and images are not supported. Only works for * * TrueType fonts! @default false */ get isHtmlText(): boolean; set isHtmlText(value: boolean) /** * The padding (in points) that's added to the sides of text that's rendered to a Bitmap. * * If your text is truncated on the sides (which may happen if the font returns incorrect * * bounds), padding can make up for that. Value must be positive. @default 0.0 */ get padding(): number; set padding(value: number) /** * Controls whether or not the instance snaps to the nearest pixel. This can prevent the * * object from looking blurry when it's not exactly aligned with the pixels of the screen. * * @default true */ get pixelSnapping(): boolean; set pixelSnapping(value: boolean) /** * The mesh style that is used to render the text. * * Note that a style instance may only be used on one mesh at a time. */ get style(): MeshStyle; set style(value: MeshStyle) } } export default starling.text.TextField;