Files

1 line
40 KiB
Plaintext
Raw Permalink Normal View History

2025-01-04 00:34:03 +01:00
{"version":3,"file":"BitmapText.mjs","sources":["../src/BitmapText.ts"],"sourcesContent":["import { BLEND_MODES, Color, ObservablePoint, Point, Program, settings, Texture, utils } from '@pixi/core';\nimport { Container } from '@pixi/display';\nimport { Mesh, MeshGeometry, MeshMaterial } from '@pixi/mesh';\nimport { BitmapFont } from './BitmapFont';\nimport msdfFrag from './shader/msdf.frag';\nimport msdfVert from './shader/msdf.vert';\nimport { extractCharCode, splitTextToCharacters } from './utils';\n\nimport type { ColorSource, Rectangle, Renderer } from '@pixi/core';\nimport type { IDestroyOptions } from '@pixi/display';\nimport type { TextStyleAlign } from '@pixi/text';\nimport type { IBitmapTextStyle } from './BitmapTextStyle';\n\ninterface PageMeshData\n{\n index: number;\n indexCount: number;\n vertexCount: number;\n uvsCount: number;\n total: number;\n mesh: Mesh;\n vertices?: Float32Array;\n uvs?: Float32Array;\n indices?: Uint16Array;\n}\ninterface CharRenderData\n{\n texture: Texture;\n line: number;\n charCode: number;\n position: Point;\n prevSpaces: number;\n}\n\n// If we ever need more than two pools, please make a Dict or something better.\nconst pageMeshDataDefaultPageMeshData: PageMeshData[] = [];\nconst pageMeshDataMSDFPageMeshData: PageMeshData[] = [];\nconst charRenderDataPool: CharRenderData[] = [];\n\n/**\n * A BitmapText object will create a line or multiple lines of text using bitmap font.\n *\n * The primary advantage of this class over Text is that all of your textures are pre-generated and loading,\n * meaning that rendering is fast, and changing text has no performance implications.\n *\n * Supporting character sets other than latin, such as CJK languages, may be impractical due to the number of characters.\n *\n * To split a line you can use '\\n', '\\r' or '\\r\\n' in your string.\n *\n * PixiJS can auto-generate fonts on-the-fly using BitmapFont or use fnt files provided by:\n * http://www.angelcode.com/products/bmfont/ for Windows or\n * http://www.bmglyph.com/ for Mac.\n *\n * You can also use SDF, MSDF and MTSDF BitmapFonts for vector-like scaling appearance provided by:\n * https://github.com/soimy/msdf-bmfont-xml for SDF and MSDF fnt files or\n * https://github.com/Chlumsky/msdf-atlas-gen for SDF, MSDF and MTSDF json files\n *\n * A BitmapText can only be created when the font is loaded.\n * @example\n * import { BitmapText } from 'pixi.js';\n *\n * // in this case the font is in a file called 'desyrel.fnt'\n * const bitmapText = new BitmapText('text using a fancy font!', {\n * fontName: 'Desyrel',\n * fontSize: 35,\n * align: 'right',\n * });\n * @memberof PIXI\n */\nexport class BitmapText extends Container\n{\n public static styleDefaults: Partial<IBitmapTextStyle> = {\n align: 'left',\n tint: 0xFFFFFF,\n maxWidth: 0,\n letterSpacing: 0,\n };\n\n /** Set to `true` if the BitmapText needs to be redrawn. */\n public dirty: boolean;\n\n /**\n * The resolution / device pixel ratio of the canvas.\n *\n * This is set to automatically match the renderer resolution by default, but can be overridden by setting manually.\n * @default PIXI.settings.RESOLUTION\n */\n _resolution: number;\n _autoResolution: boolean;\n\n /**\n * Private tracker for the width of the overall text.\n * @private\n */\n protected _textWidth: number;\n\n /**\n * Private tracker for the height of the overall text.\n * @private\n */\n protected _textHeight: number;\n\n /**\n * Private tracker for the current text.\n * @private\n */\n protected _text: string;\n\n /**\n * The max width of this bitmap text in pixels. If the text provided is longer than the\n * value provided, line breaks will be automatically inserted in the last whitespace.\n * Disable by setting value to 0\n * @private\n */\n protected _maxWidth: number;\n\n /**\n * The max line height. This is useful when trying to use the total height of the Tex