1 line
6.9 KiB
Plaintext
1 line
6.9 KiB
Plaintext
{"version":3,"file":"BitmapText.mjs","sources":["../../../src/scene/text-bitmap/BitmapText.ts"],"sourcesContent":["import { AbstractText, ensureOptions } from '../text/AbstractText';\nimport { TextStyle } from '../text/TextStyle';\nimport { BitmapFontManager } from './BitmapFontManager';\n\nimport type { View } from '../../rendering/renderers/shared/view/View';\nimport type { TextOptions, TextString } from '../text/AbstractText';\nimport type { TextStyleOptions } from '../text/TextStyle';\n\n/**\n * A BitmapText Object will create a line or multiple lines of text.\n *\n * To split a line you can use '\\n' in your text string, or, on the `style` object,\n * change its `wordWrap` property to true and and give the `wordWrapWidth` property a value.\n *\n * The text is created using a bitmap font (a sprite sheet of characters).\n *\n * The primary advantage of this render mode over `text` is that all of your textures are pre-generated and loaded,\n * meaning that rendering is fast, and changing text is much faster than Text.\n *\n * The primary disadvantage is that supporting character sets other than latin, such as CJK languages,\n * may be impractical due to the number of characters.\n *\n * <b>Pre-loaded BitmapFonts:</b>\n *\n *\n * PixiJS enables the loading of BitmapFonts through its Asset Manager, supporting both XML and FNT formats.\n * Additionally, PixiJS is compatible with MSDF (Multi-channel Signed Distance Field) and SDF (Signed Distance Field) fonts.\n * These advanced font types allow for scaling without quality degradation and must be created with specific tools,\n * such as the one available at https://msdf-bmfont.donmccurdy.com/.\n *\n * <b>Dynamically Generated BitmapFonts:</b>\n *\n *\n * PixiJS also offers the capability to generate BitmapFonts dynamically. This means that fonts are created in real-time\n * based on specified styles, eliminating the need for pre-loading. This process is initiated simply by assigning a style\n * to a BitmapText object, which then automatically generates the required font.\n *\n * However, dynamically generating a large number of fonts may lead to significant memory use. To prevent this,\n * PixiJS smartly attempts to reuse fonts that closely match the desired style parameters. For instance, if a text style\n * requires a font size of 80 but a similar font of size 100 has already been generated, PixiJS will scale the existing\n * font to fit the new requirement, rather than creating a new font from scratch.\n *\n * For those who prefer to manage BitmapFonts manually, PixiJS provides the BitmapFont.install method. This method\n * allows for the pre-generation and preparation of fonts, making them readily available for use by specifying the\n * fontFamily in your text styling.\n *\n * This approach ensures efficient font management within PixiJS, balancing between dynamic generation for flexibility\n * and manual management for optimized performance.\n * @example\n * import { BitmapText, BitmapFont } from 'pixi.js';\n *\n * // generate a dynamic font behind the scenes:\n * const text = new BitmapText({\n * text: 'Hello Pixi!',\n * style: {\n * fontFamily: 'Arial',\n * fontSize: 24,\n * fill: 0xff1010,\n * align: 'center',\n * }\n * });\n *\n * // pre install\n * BitmapFont.install({\n * name: 'myFont',\n * style:{\n * fontFamily: 'Arial',\n * }\n * })\n *\n * // new bitmap text with preinstalled font\n * const text = new BitmapText({\n * text: 'Hello Pixi!',\n * style: {\n * fontFamily: 'myFont',\n * fontSize: 24,\n * fill: 0xff1010,\n * align: 'center',\n * }\n * }\n *\n * // load a font from an xml file\n * const font = await Assets.load('path/to/myLoadedFont.fnt');\n *\n * // new bitmap text with loaded font\n * const text = new BitmapText({\n * text: 'Hello Pixi!',\n * style: {\n * fontFamily: 'myLoadedFont', // the name of the font in the fnt file\n * fontSize: 24,\n * fill: 0xff1010,\n * align: 'center',\n * }\n * }\n * @memberof scene\n */\nexport class BitmapText extends AbstractText<TextStyle, TextStyleOptions> implements View\n{\n public readonly renderPipeId: string = 'bitmapText';\n\n /**\n * **Note:** Our docs parser struggles to properly understand the constructor signature.\n * This is the correct signature.\n * ```ts\n * new BitmapText(options?: TextOptions);\n * ```\n * @param { text.TextOptions } options - The options of the bitmap text.\n */\n constructor(options?: TextOptions);\n /** @deprecated since 8.0.0 */\n constructor(text?: TextString, options?: Partial<TextStyle>);\n constructor(...args: [TextOptions?] | [TextString, Partial<TextStyle>])\n {\n const options = ensureOptions(args, 'BitmapText');\n\n options.style ??= options.style || {};\n options.style.fill ??= 0xffffff;\n\n super(options, TextStyle);\n }\n\n protected _updateBounds()\n {\n const bounds = this._bounds;\n const anchor = this._anchor;\n\n const bitmapMeasurement = BitmapFontManager.measureText(this.text, this._style);\n const scale = bitmapMeasurement.scale;\n const offset = bitmapMeasurement.offsetY * scale;\n\n let width = bitmapMeasurement.width * scale;\n let height = bitmapMeasurement.height * scale;\n\n const stroke = this._style._stroke;\n\n if (stroke)\n {\n width += stroke.width;\n height += stroke.width;\n }\n\n bounds.minX = (-anchor._x * width);\n bounds.maxX = bounds.minX + width;\n bounds.minY = (-anchor._y * (height + offset));\n bounds.maxY = bounds.minY + height;\n }\n}\n"],"names":[],"mappings":";;;;;AAgGO,MAAM,mBAAmB,YAChC,CAAA;AAAA,EAcI,eAAe,IACf,EAAA;AAhHJ,IAAA,IAAA,EAAA,CAAA;AAiHQ,IAAM,MAAA,OAAA,GAAU,aAAc,CAAA,IAAA,EAAM,YAAY,CAAA,CAAA;AAEhD,IAAA,OAAA,CAAQ,KAAR,KAAA,OAAA,CAAQ,KAAU,GAAA,OAAA,CAAQ,SAAS,EAAC,CAAA,CAAA;AACpC,IAAQ,CAAA,EAAA,GAAA,OAAA,CAAA,KAAA,EAAM,IAAd,KAAA,EAAA,CAAc,IAAS,GAAA,QAAA,CAAA,CAAA;AAEvB,IAAA,KAAA,CAAM,SAAS,SAAS,CAAA,CAAA;AApB5B,IAAA,IAAA,CAAgB,YAAuB,GAAA,YAAA,CAAA;AAAA,GAqBvC;AAAA,EAEU,aACV,GAAA;AACI,IAAA,MAAM,SAAS,IAAK,CAAA,OAAA,CAAA;AACpB,IAAA,MAAM,SAAS,IAAK,CAAA,OAAA,CAAA;AAEpB,IAAA,MAAM,oBAAoB,iBAAkB,CAAA,WAAA,CAAY,IAAK,CAAA,IAAA,EAAM,KAAK,MAAM,CAAA,CAAA;AAC9E,IAAA,MAAM,QAAQ,iBAAkB,CAAA,KAAA,CAAA;AAChC,IAAM,MAAA,MAAA,GAAS,kBAAkB,OAAU,GAAA,KAAA,CAAA;AAE3C,IAAI,IAAA,KAAA,GAAQ,kBAAkB,KAAQ,GAAA,KAAA,CAAA;AACtC,IAAI,IAAA,MAAA,GAAS,kBAAkB,MAAS,GAAA,KAAA,CAAA;AAExC,IAAM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