index.d.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. import type { IDestroyOptions } from '@pixi/display';
  2. import { Rectangle } from '@pixi/math';
  3. import type { Renderer } from '@pixi/core';
  4. import { Sprite } from '@pixi/sprite';
  5. declare interface IFontMetrics {
  6. ascent: number;
  7. descent: number;
  8. fontSize: number;
  9. }
  10. export declare interface ITextStyle {
  11. align: TextStyleAlign;
  12. breakWords: boolean;
  13. dropShadow: boolean;
  14. dropShadowAlpha: number;
  15. dropShadowAngle: number;
  16. dropShadowBlur: number;
  17. dropShadowColor: string | number;
  18. dropShadowDistance: number;
  19. fill: TextStyleFill;
  20. fillGradientType: TEXT_GRADIENT;
  21. fillGradientStops: number[];
  22. fontFamily: string | string[];
  23. fontSize: number | string;
  24. fontStyle: TextStyleFontStyle;
  25. fontVariant: TextStyleFontVariant;
  26. fontWeight: TextStyleFontWeight;
  27. letterSpacing: number;
  28. lineHeight: number;
  29. lineJoin: TextStyleLineJoin;
  30. miterLimit: number;
  31. padding: number;
  32. stroke: string | number;
  33. strokeThickness: number;
  34. textBaseline: TextStyleTextBaseline;
  35. trim: boolean;
  36. whiteSpace: TextStyleWhiteSpace;
  37. wordWrap: boolean;
  38. wordWrapWidth: number;
  39. leading: number;
  40. }
  41. declare interface ModernContext2D extends CanvasRenderingContext2D {
  42. textLetterSpacing?: number;
  43. letterSpacing?: number;
  44. }
  45. /**
  46. * A Text Object will create a line or multiple lines of text.
  47. *
  48. * The text is created using the [Canvas API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API).
  49. *
  50. * The primary advantage of this class over BitmapText is that you have great control over the style of the text,
  51. * which you can change at runtime.
  52. *
  53. * The primary disadvantages is that each piece of text has it's own texture, which can use more memory.
  54. * When text changes, this texture has to be re-generated and re-uploaded to the GPU, taking up time.
  55. *
  56. * To split a line you can use '\n' in your text string, or, on the `style` object,
  57. * change its `wordWrap` property to true and and give the `wordWrapWidth` property a value.
  58. *
  59. * A Text can be created directly from a string and a style object,
  60. * which can be generated [here](https://pixijs.io/pixi-text-style).
  61. *
  62. * ```js
  63. * let text = new PIXI.Text('This is a PixiJS text',{fontFamily : 'Arial', fontSize: 24, fill : 0xff1010, align : 'center'});
  64. * ```
  65. * @memberof PIXI
  66. */
  67. declare class Text_2 extends Sprite {
  68. /**
  69. * New behavior for `lineHeight` that's meant to mimic HTML text. A value of `true` will
  70. * make sure the first baseline is offset by the `lineHeight` value if it is greater than `fontSize`.
  71. * A value of `false` will use the legacy behavior and not change the baseline of the first line.
  72. * In the next major release, we'll enable this by default.
  73. */
  74. static nextLineHeightBehavior: boolean;
  75. /**
  76. * New rendering behavior for letter-spacing which uses Chrome's new native API. This will
  77. * lead to more accurate letter-spacing results because it does not try to manually draw
  78. * each character. However, this Chrome API is experimental and may not serve all cases yet.
  79. */
  80. static experimentalLetterSpacing: boolean;
  81. /** The canvas element that everything is drawn to. */
  82. canvas: HTMLCanvasElement;
  83. /** The canvas 2d context that everything is drawn with. */
  84. context: ModernContext2D;
  85. localStyleID: number;
  86. dirty: boolean;
  87. /**
  88. * The resolution / device pixel ratio of the canvas.
  89. *
  90. * This is set to automatically match the renderer resolution by default, but can be overridden by setting manually.
  91. * @default PIXI.settings.RESOLUTION
  92. */
  93. _resolution: number;
  94. _autoResolution: boolean;
  95. /**
  96. * Private tracker for the current text.
  97. * @private
  98. */
  99. protected _text: string;
  100. /**
  101. * Private tracker for the current font.
  102. * @private
  103. */
  104. protected _font: string;
  105. /**
  106. * Private tracker for the current style.
  107. * @private
  108. */
  109. protected _style: TextStyle;
  110. /**
  111. * Private listener to track style changes.
  112. * @private
  113. */
  114. protected _styleListener: () => void;
  115. /**
  116. * Keep track if this Text object created it's own canvas
  117. * element (`true`) or uses the constructor argument (`false`).
  118. * Used to workaround a GC issues with Safari < 13 when
  119. * destroying Text. See `destroy` for more info.
  120. */
  121. private _ownCanvas;
  122. /**
  123. * @param text - The string that you would like the text to display
  124. * @param {object|PIXI.TextStyle} [style] - The style parameters
  125. * @param canvas - The canvas element for drawing text
  126. */
  127. constructor(text?: string | number, style?: Partial<ITextStyle> | TextStyle, canvas?: HTMLCanvasElement);
  128. /**
  129. * Renders text to its canvas, and updates its texture.
  130. *
  131. * By default this is used internally to ensure the texture is correct before rendering,
  132. * but it can be used called externally, for example from this class to 'pre-generate' the texture from a piece of text,
  133. * and then shared across multiple Sprites.
  134. * @param respectDirty - Whether to abort updating the text if the Text isn't dirty and the function is called.
  135. */
  136. updateText(respectDirty: boolean): void;
  137. /**
  138. * Render the text with letter-spacing.
  139. * @param text - The text to draw
  140. * @param x - Horizontal position to draw the text
  141. * @param y - Vertical position to draw the text
  142. * @param isStroke - Is this drawing for the outside stroke of the
  143. * text? If not, it's for the inside fill
  144. */
  145. private drawLetterSpacing;
  146. /** Updates texture size based on canvas size. */
  147. private updateTexture;
  148. /**
  149. * Renders the object using the WebGL renderer
  150. * @param renderer - The renderer
  151. */
  152. protected _render(renderer: Renderer): void;
  153. /** Updates the transform on all children of this container for rendering. */
  154. updateTransform(): void;
  155. getBounds(skipUpdate?: boolean, rect?: Rectangle): Rectangle;
  156. /**
  157. * Gets the local bounds of the text object.
  158. * @param rect - The output rectangle.
  159. * @returns The bounds.
  160. */
  161. getLocalBounds(rect?: Rectangle): Rectangle;
  162. /** Calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */
  163. protected _calculateBounds(): void;
  164. /**
  165. * Generates the fill style. Can automatically generate a gradient based on the fill style being an array
  166. * @param style - The style.
  167. * @param lines - The lines of text.
  168. * @param metrics
  169. * @returns The fill style
  170. */
  171. private _generateFillStyle;
  172. /**
  173. * Destroys this text object.
  174. *
  175. * Note* Unlike a Sprite, a Text object will automatically destroy its baseTexture and texture as
  176. * the majority of the time the texture will not be shared with any other Sprites.
  177. * @param options - Options parameter. A boolean will act as if all options
  178. * have been set to that value
  179. * @param {boolean} [options.children=false] - if set to true, all the children will have their
  180. * destroy method called as well. 'options' will be passed on to those calls.
  181. * @param {boolean} [options.texture=true] - Should it destroy the current texture of the sprite as well
  182. * @param {boolean} [options.baseTexture=true] - Should it destroy the base texture of the sprite as well
  183. */
  184. destroy(options?: IDestroyOptions | boolean): void;
  185. /** The width of the Text, setting this will actually modify the scale to achieve the value set. */
  186. get width(): number;
  187. set width(value: number);
  188. /** The height of the Text, setting this will actually modify the scale to achieve the value set. */
  189. get height(): number;
  190. set height(value: number);
  191. /**
  192. * Set the style of the text.
  193. *
  194. * Set up an event listener to listen for changes on the style object and mark the text as dirty.
  195. */
  196. get style(): TextStyle | Partial<ITextStyle>;
  197. set style(style: TextStyle | Partial<ITextStyle>);
  198. /** Set the copy for the text object. To split a line you can use '\n'. */
  199. get text(): string;
  200. set text(text: string | number);
  201. /**
  202. * The resolution / device pixel ratio of the canvas.
  203. *
  204. * This is set to automatically match the renderer resolution by default, but can be overridden by setting manually.
  205. * @default 1
  206. */
  207. get resolution(): number;
  208. set resolution(value: number);
  209. }
  210. export { Text_2 as Text }
  211. /**
  212. * Constants that define the type of gradient on text.
  213. * @static
  214. * @constant
  215. * @name TEXT_GRADIENT
  216. * @memberof PIXI
  217. * @type {object}
  218. * @property {number} LINEAR_VERTICAL Vertical gradient
  219. * @property {number} LINEAR_HORIZONTAL Linear gradient
  220. */
  221. export declare enum TEXT_GRADIENT {
  222. LINEAR_VERTICAL = 0,
  223. LINEAR_HORIZONTAL = 1
  224. }
  225. /**
  226. * The TextMetrics object represents the measurement of a block of text with a specified style.
  227. *
  228. * ```js
  229. * let style = new PIXI.TextStyle({fontFamily : 'Arial', fontSize: 24, fill : 0xff1010, align : 'center'})
  230. * let textMetrics = PIXI.TextMetrics.measureText('Your text', style)
  231. * ```
  232. * @memberof PIXI
  233. */
  234. declare class TextMetrics_2 {
  235. /** The text that was measured. */
  236. text: string;
  237. /** The style that was measured. */
  238. style: TextStyle;
  239. /** The measured width of the text. */
  240. width: number;
  241. /** The measured height of the text. */
  242. height: number;
  243. /** An array of lines of the text broken by new lines and wrapping is specified in style. */
  244. lines: string[];
  245. /** An array of the line widths for each line matched to `lines`. */
  246. lineWidths: number[];
  247. /** The measured line height for this style. */
  248. lineHeight: number;
  249. /** The maximum line width for all measured lines. */
  250. maxLineWidth: number;
  251. /**
  252. * The font properties object from TextMetrics.measureFont.
  253. * @type {PIXI.IFontMetrics}
  254. */
  255. fontProperties: IFontMetrics;
  256. static METRICS_STRING: string;
  257. static BASELINE_SYMBOL: string;
  258. static BASELINE_MULTIPLIER: number;
  259. static HEIGHT_MULTIPLIER: number;
  260. private static __canvas;
  261. private static __context;
  262. static _fonts: {
  263. [font: string]: IFontMetrics;
  264. };
  265. static _newlines: number[];
  266. static _breakingSpaces: number[];
  267. /**
  268. * @param text - the text that was measured
  269. * @param style - the style that was measured
  270. * @param width - the measured width of the text
  271. * @param height - the measured height of the text
  272. * @param lines - an array of the lines of text broken by new lines and wrapping if specified in style
  273. * @param lineWidths - an array of the line widths for each line matched to `lines`
  274. * @param lineHeight - the measured line height for this style
  275. * @param maxLineWidth - the maximum line width for all measured lines
  276. * @param {PIXI.IFontMetrics} fontProperties - the font properties object from TextMetrics.measureFont
  277. */
  278. constructor(text: string, style: TextStyle, width: number, height: number, lines: string[], lineWidths: number[], lineHeight: number, maxLineWidth: number, fontProperties: IFontMetrics);
  279. /**
  280. * Measures the supplied string of text and returns a Rectangle.
  281. * @param text - The text to measure.
  282. * @param style - The text style to use for measuring
  283. * @param wordWrap - Override for if word-wrap should be applied to the text.
  284. * @param canvas - optional specification of the canvas to use for measuring.
  285. * @returns Measured width and height of the text.
  286. */
  287. static measureText(text: string, style: TextStyle, wordWrap?: boolean, canvas?: HTMLCanvasElement | OffscreenCanvas): TextMetrics_2;
  288. /**
  289. * Applies newlines to a string to have it optimally fit into the horizontal
  290. * bounds set by the Text object's wordWrapWidth property.
  291. * @param text - String to apply word wrapping to
  292. * @param style - the style to use when wrapping
  293. * @param canvas - optional specification of the canvas to use for measuring.
  294. * @returns New string with new lines applied where required
  295. */
  296. private static wordWrap;
  297. /**
  298. * Convienience function for logging each line added during the wordWrap method.
  299. * @param line - The line of text to add
  300. * @param newLine - Add new line character to end
  301. * @returns A formatted line
  302. */
  303. private static addLine;
  304. /**
  305. * Gets & sets the widths of calculated characters in a cache object
  306. * @param key - The key
  307. * @param letterSpacing - The letter spacing
  308. * @param cache - The cache
  309. * @param context - The canvas context
  310. * @returns The from cache.
  311. */
  312. private static getFromCache;
  313. /**
  314. * Determines whether we should collapse breaking spaces.
  315. * @param whiteSpace - The TextStyle property whiteSpace
  316. * @returns Should collapse
  317. */
  318. private static collapseSpaces;
  319. /**
  320. * Determines whether we should collapse newLine chars.
  321. * @param whiteSpace - The white space
  322. * @returns should collapse
  323. */
  324. private static collapseNewlines;
  325. /**
  326. * Trims breaking whitespaces from string.
  327. * @param text - The text
  328. * @returns Trimmed string
  329. */
  330. private static trimRight;
  331. /**
  332. * Determines if char is a newline.
  333. * @param char - The character
  334. * @returns True if newline, False otherwise.
  335. */
  336. private static isNewline;
  337. /**
  338. * Determines if char is a breaking whitespace.
  339. *
  340. * It allows one to determine whether char should be a breaking whitespace
  341. * For example certain characters in CJK langs or numbers.
  342. * It must return a boolean.
  343. * @param char - The character
  344. * @param [_nextChar] - The next character
  345. * @returns True if whitespace, False otherwise.
  346. */
  347. static isBreakingSpace(char: string, _nextChar?: string): boolean;
  348. /**
  349. * Splits a string into words, breaking-spaces and newLine characters
  350. * @param text - The text
  351. * @returns A tokenized array
  352. */
  353. private static tokenize;
  354. /**
  355. * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
  356. *
  357. * It allows one to customise which words should break
  358. * Examples are if the token is CJK or numbers.
  359. * It must return a boolean.
  360. * @param _token - The token
  361. * @param breakWords - The style attr break words
  362. * @returns Whether to break word or not
  363. */
  364. static canBreakWords(_token: string, breakWords: boolean): boolean;
  365. /**
  366. * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
  367. *
  368. * It allows one to determine whether a pair of characters
  369. * should be broken by newlines
  370. * For example certain characters in CJK langs or numbers.
  371. * It must return a boolean.
  372. * @param _char - The character
  373. * @param _nextChar - The next character
  374. * @param _token - The token/word the characters are from
  375. * @param _index - The index in the token of the char
  376. * @param _breakWords - The style attr break words
  377. * @returns whether to break word or not
  378. */
  379. static canBreakChars(_char: string, _nextChar: string, _token: string, _index: number, _breakWords: boolean): boolean;
  380. /**
  381. * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
  382. *
  383. * It is called when a token (usually a word) has to be split into separate pieces
  384. * in order to determine the point to break a word.
  385. * It must return an array of characters.
  386. * @example
  387. * // Correctly splits emojis, eg "🤪🤪" will result in two element array, each with one emoji.
  388. * TextMetrics.wordWrapSplit = (token) => [...token];
  389. * @param token - The token to split
  390. * @returns The characters of the token
  391. */
  392. static wordWrapSplit(token: string): string[];
  393. /**
  394. * Calculates the ascent, descent and fontSize of a given font-style
  395. * @param font - String representing the style of the font
  396. * @returns Font properties object
  397. */
  398. static measureFont(font: string): IFontMetrics;
  399. /**
  400. * Clear font metrics in metrics cache.
  401. * @param {string} [font] - font name. If font name not set then clear cache for all fonts.
  402. */
  403. static clearMetrics(font?: string): void;
  404. /**
  405. * Cached canvas element for measuring text
  406. * TODO: this should be private, but isn't because of backward compat, will fix later.
  407. * @ignore
  408. */
  409. static get _canvas(): HTMLCanvasElement | OffscreenCanvas;
  410. /**
  411. * TODO: this should be private, but isn't because of backward compat, will fix later.
  412. * @ignore
  413. */
  414. static get _context(): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
  415. }
  416. export { TextMetrics_2 as TextMetrics }
  417. /**
  418. * A TextStyle Object contains information to decorate a Text objects.
  419. *
  420. * An instance can be shared between multiple Text objects; then changing the style will update all text objects using it.
  421. *
  422. * A tool can be used to generate a text style [here](https://pixijs.io/pixi-text-style).
  423. *
  424. * @memberof PIXI
  425. */
  426. export declare class TextStyle implements ITextStyle {
  427. styleID: number;
  428. protected _align: TextStyleAlign;
  429. protected _breakWords: boolean;
  430. protected _dropShadow: boolean;
  431. protected _dropShadowAlpha: number;
  432. protected _dropShadowAngle: number;
  433. protected _dropShadowBlur: number;
  434. protected _dropShadowColor: string | number;
  435. protected _dropShadowDistance: number;
  436. protected _fill: TextStyleFill;
  437. protected _fillGradientType: TEXT_GRADIENT;
  438. protected _fillGradientStops: number[];
  439. protected _fontFamily: string | string[];
  440. protected _fontSize: number | string;
  441. protected _fontStyle: TextStyleFontStyle;
  442. protected _fontVariant: TextStyleFontVariant;
  443. protected _fontWeight: TextStyleFontWeight;
  444. protected _letterSpacing: number;
  445. protected _lineHeight: number;
  446. protected _lineJoin: TextStyleLineJoin;
  447. protected _miterLimit: number;
  448. protected _padding: number;
  449. protected _stroke: string | number;
  450. protected _strokeThickness: number;
  451. protected _textBaseline: TextStyleTextBaseline;
  452. protected _trim: boolean;
  453. protected _whiteSpace: TextStyleWhiteSpace;
  454. protected _wordWrap: boolean;
  455. protected _wordWrapWidth: number;
  456. protected _leading: number;
  457. /**
  458. * @param {object} [style] - The style parameters
  459. * @param {string} [style.align='left'] - Alignment for multiline text ('left', 'center' or 'right'),
  460. * does not affect single line text
  461. * @param {boolean} [style.breakWords=false] - Indicates if lines can be wrapped within words, it
  462. * needs wordWrap to be set to true
  463. * @param {boolean} [style.dropShadow=false] - Set a drop shadow for the text
  464. * @param {number} [style.dropShadowAlpha=1] - Set alpha for the drop shadow
  465. * @param {number} [style.dropShadowAngle=Math.PI/6] - Set a angle of the drop shadow
  466. * @param {number} [style.dropShadowBlur=0] - Set a shadow blur radius
  467. * @param {string|number} [style.dropShadowColor='black'] - A fill style to be used on the dropshadow e.g 'red', '#00FF00'
  468. * @param {number} [style.dropShadowDistance=5] - Set a distance of the drop shadow
  469. * @param {string|string[]|number|number[]|CanvasGradient|CanvasPattern} [style.fill='black'] - A canvas
  470. * fillstyle that will be used on the text e.g 'red', '#00FF00'. Can be an array to create a gradient
  471. * eg ['#000000','#FFFFFF']
  472. * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle|MDN}
  473. * @param {number} [style.fillGradientType=PIXI.TEXT_GRADIENT.LINEAR_VERTICAL] - If fill is an array of colours
  474. * to create a gradient, this can change the type/direction of the gradient. See {@link PIXI.TEXT_GRADIENT}
  475. * @param {number[]} [style.fillGradientStops] - If fill is an array of colours to create a gradient, this array can set
  476. * the stop points (numbers between 0 and 1) for the color, overriding the default behaviour of evenly spacing them.
  477. * @param {string|string[]} [style.fontFamily='Arial'] - The font family
  478. * @param {number|string} [style.fontSize=26] - The font size (as a number it converts to px, but as a string,
  479. * equivalents are '26px','20pt','160%' or '1.6em')
  480. * @param {string} [style.fontStyle='normal'] - The font style ('normal', 'italic' or 'oblique')
  481. * @param {string} [style.fontVariant='normal'] - The font variant ('normal' or 'small-caps')
  482. * @param {string} [style.fontWeight='normal'] - The font weight ('normal', 'bold', 'bolder', 'lighter' and '100',
  483. * '200', '300', '400', '500', '600', '700', '800' or '900')
  484. * @param {number} [style.leading=0] - The space between lines
  485. * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0
  486. * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses
  487. * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve
  488. * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel"
  489. * (creates a squared corner).
  490. * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce
  491. * or increase the spikiness of rendered text.
  492. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from
  493. * happening by adding padding to all sides of the text.
  494. * @param {string|number} [style.stroke='black'] - A canvas fillstyle that will be used on the text stroke
  495. * e.g 'blue', '#FCFF00'
  496. * @param {number} [style.strokeThickness=0] - A number that represents the thickness of the stroke.
  497. * Default is 0 (no stroke)
  498. * @param {boolean} [style.trim=false] - Trim transparent borders
  499. * @param {string} [style.textBaseline='alphabetic'] - The baseline of the text that is rendered.
  500. * @param {string} [style.whiteSpace='pre'] - Determines whether newlines & spaces are collapsed or preserved "normal"
  501. * (collapse, collapse), "pre" (preserve, preserve) | "pre-line" (preserve, collapse). It needs wordWrap to be set to true
  502. * @param {boolean} [style.wordWrap=false] - Indicates if word wrap should be used
  503. * @param {number} [style.wordWrapWidth=100] - The width at which text will wrap, it needs wordWrap to be set to true
  504. */
  505. constructor(style?: Partial<ITextStyle>);
  506. /**
  507. * Creates a new TextStyle object with the same values as this one.
  508. * Note that the only the properties of the object are cloned.
  509. *
  510. * @return New cloned TextStyle object
  511. */
  512. clone(): TextStyle;
  513. /** Resets all properties to the defaults specified in TextStyle.prototype._default */
  514. reset(): void;
  515. /**
  516. * Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text
  517. *
  518. * @member {string}
  519. */
  520. get align(): TextStyleAlign;
  521. set align(align: TextStyleAlign);
  522. /** Indicates if lines can be wrapped within words, it needs wordWrap to be set to true. */
  523. get breakWords(): boolean;
  524. set breakWords(breakWords: boolean);
  525. /** Set a drop shadow for the text. */
  526. get dropShadow(): boolean;
  527. set dropShadow(dropShadow: boolean);
  528. /** Set alpha for the drop shadow. */
  529. get dropShadowAlpha(): number;
  530. set dropShadowAlpha(dropShadowAlpha: number);
  531. /** Set a angle of the drop shadow. */
  532. get dropShadowAngle(): number;
  533. set dropShadowAngle(dropShadowAngle: number);
  534. /** Set a shadow blur radius. */
  535. get dropShadowBlur(): number;
  536. set dropShadowBlur(dropShadowBlur: number);
  537. /** A fill style to be used on the dropshadow e.g 'red', '#00FF00'. */
  538. get dropShadowColor(): number | string;
  539. set dropShadowColor(dropShadowColor: number | string);
  540. /** Set a distance of the drop shadow. */
  541. get dropShadowDistance(): number;
  542. set dropShadowDistance(dropShadowDistance: number);
  543. /**
  544. * A canvas fillstyle that will be used on the text e.g 'red', '#00FF00'.
  545. *
  546. * Can be an array to create a gradient eg ['#000000','#FFFFFF']
  547. * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle|MDN}
  548. *
  549. * @member {string|string[]|number|number[]|CanvasGradient|CanvasPattern}
  550. */
  551. get fill(): TextStyleFill;
  552. set fill(fill: TextStyleFill);
  553. /**
  554. * If fill is an array of colours to create a gradient, this can change the type/direction of the gradient.
  555. *
  556. * @see PIXI.TEXT_GRADIENT
  557. */
  558. get fillGradientType(): TEXT_GRADIENT;
  559. set fillGradientType(fillGradientType: TEXT_GRADIENT);
  560. /**
  561. * If fill is an array of colours to create a gradient, this array can set the stop points
  562. * (numbers between 0 and 1) for the color, overriding the default behaviour of evenly spacing them.
  563. */
  564. get fillGradientStops(): number[];
  565. set fillGradientStops(fillGradientStops: number[]);
  566. /** The font family. */
  567. get fontFamily(): string | string[];
  568. set fontFamily(fontFamily: string | string[]);
  569. /**
  570. * The font size
  571. * (as a number it converts to px, but as a string, equivalents are '26px','20pt','160%' or '1.6em')
  572. */
  573. get fontSize(): number | string;
  574. set fontSize(fontSize: number | string);
  575. /**
  576. * The font style
  577. * ('normal', 'italic' or 'oblique')
  578. *
  579. * @member {string}
  580. */
  581. get fontStyle(): TextStyleFontStyle;
  582. set fontStyle(fontStyle: TextStyleFontStyle);
  583. /**
  584. * The font variant
  585. * ('normal' or 'small-caps')
  586. *
  587. * @member {string}
  588. */
  589. get fontVariant(): TextStyleFontVariant;
  590. set fontVariant(fontVariant: TextStyleFontVariant);
  591. /**
  592. * The font weight
  593. * ('normal', 'bold', 'bolder', 'lighter' and '100', '200', '300', '400', '500', '600', '700', 800' or '900')
  594. *
  595. * @member {string}
  596. */
  597. get fontWeight(): TextStyleFontWeight;
  598. set fontWeight(fontWeight: TextStyleFontWeight);
  599. /** The amount of spacing between letters, default is 0. */
  600. get letterSpacing(): number;
  601. set letterSpacing(letterSpacing: number);
  602. /** The line height, a number that represents the vertical space that a letter uses. */
  603. get lineHeight(): number;
  604. set lineHeight(lineHeight: number);
  605. /** The space between lines. */
  606. get leading(): number;
  607. set leading(leading: number);
  608. /**
  609. * The lineJoin property sets the type of corner created, it can resolve spiked text issues.
  610. * Default is 'miter' (creates a sharp corner).
  611. *
  612. * @member {string}
  613. */
  614. get lineJoin(): TextStyleLineJoin;
  615. set lineJoin(lineJoin: TextStyleLineJoin);
  616. /**
  617. * The miter limit to use when using the 'miter' lineJoin mode.
  618. *
  619. * This can reduce or increase the spikiness of rendered text.
  620. */
  621. get miterLimit(): number;
  622. set miterLimit(miterLimit: number);
  623. /**
  624. * Occasionally some fonts are cropped. Adding some padding will prevent this from happening
  625. * by adding padding to all sides of the text.
  626. */
  627. get padding(): number;
  628. set padding(padding: number);
  629. /**
  630. * A canvas fillstyle that will be used on the text stroke
  631. * e.g 'blue', '#FCFF00'
  632. */
  633. get stroke(): string | number;
  634. set stroke(stroke: string | number);
  635. /**
  636. * A number that represents the thickness of the stroke.
  637. *
  638. * @default 0
  639. */
  640. get strokeThickness(): number;
  641. set strokeThickness(strokeThickness: number);
  642. /**
  643. * The baseline of the text that is rendered.
  644. *
  645. * @member {string}
  646. */
  647. get textBaseline(): TextStyleTextBaseline;
  648. set textBaseline(textBaseline: TextStyleTextBaseline);
  649. /** Trim transparent borders. */
  650. get trim(): boolean;
  651. set trim(trim: boolean);
  652. /**
  653. * How newlines and spaces should be handled.
  654. * Default is 'pre' (preserve, preserve).
  655. *
  656. * value | New lines | Spaces
  657. * --- | --- | ---
  658. * 'normal' | Collapse | Collapse
  659. * 'pre' | Preserve | Preserve
  660. * 'pre-line' | Preserve | Collapse
  661. *
  662. * @member {string}
  663. */
  664. get whiteSpace(): TextStyleWhiteSpace;
  665. set whiteSpace(whiteSpace: TextStyleWhiteSpace);
  666. /** Indicates if word wrap should be used. */
  667. get wordWrap(): boolean;
  668. set wordWrap(wordWrap: boolean);
  669. /** The width at which text will wrap, it needs wordWrap to be set to true. */
  670. get wordWrapWidth(): number;
  671. set wordWrapWidth(wordWrapWidth: number);
  672. /**
  673. * Generates a font style string to use for `TextMetrics.measureFont()`.
  674. *
  675. * @return Font style string, for passing to `TextMetrics.measureFont()`
  676. */
  677. toFontString(): string;
  678. }
  679. export declare type TextStyleAlign = 'left' | 'center' | 'right' | 'justify';
  680. export declare type TextStyleFill = string | string[] | number | number[] | CanvasGradient | CanvasPattern;
  681. export declare type TextStyleFontStyle = 'normal' | 'italic' | 'oblique';
  682. export declare type TextStyleFontVariant = 'normal' | 'small-caps';
  683. export declare type TextStyleFontWeight = 'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
  684. export declare type TextStyleLineJoin = 'miter' | 'round' | 'bevel';
  685. export declare type TextStyleTextBaseline = 'alphabetic' | 'top' | 'hanging' | 'middle' | 'ideographic' | 'bottom';
  686. export declare type TextStyleWhiteSpace = 'normal' | 'pre' | 'pre-line';
  687. export { }