UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

52 lines (48 loc) 1.73 kB
'use strict'; var TextureStyle = require('../../rendering/renderers/shared/texture/TextureStyle.js'); var AbstractText = require('./AbstractText.js'); var CanvasTextGenerator = require('./canvas/CanvasTextGenerator.js'); var CanvasTextMetrics = require('./canvas/CanvasTextMetrics.js'); var TextStyle = require('./TextStyle.js'); "use strict"; class Text extends AbstractText.AbstractText { constructor(...args) { const options = AbstractText.ensureTextOptions(args, "Text"); super(options, TextStyle.TextStyle); /** @internal */ this.renderPipeId = "text"; if (options.textureStyle) { this.textureStyle = options.textureStyle instanceof TextureStyle.TextureStyle ? options.textureStyle : new TextureStyle.TextureStyle(options.textureStyle); } } /** @private */ updateBounds() { const bounds = this._bounds; const anchor = this._anchor; let width = 0; let height = 0; if (this._style.trim) { const { frame, canvasAndContext } = CanvasTextGenerator.CanvasTextGenerator.getCanvasAndContext({ text: this.text, style: this._style, resolution: 1 }); CanvasTextGenerator.CanvasTextGenerator.returnCanvasAndContext(canvasAndContext); width = frame.width; height = frame.height; } else { const canvasMeasurement = CanvasTextMetrics.CanvasTextMetrics.measureText( this._text, this._style ); width = canvasMeasurement.width; height = canvasMeasurement.height; } bounds.minX = -anchor._x * width; bounds.maxX = bounds.minX + width; bounds.minY = -anchor._y * height; bounds.maxY = bounds.minY + height; } } exports.Text = Text; //# sourceMappingURL=Text.js.map