Files
nothoughts/node_modules/pixi.js/lib/scene/text-bitmap/AbstractBitmapFont.mjs.map
2025-08-04 18:57:35 +02:00

1 line
8.5 KiB
Plaintext

{"version":3,"file":"AbstractBitmapFont.mjs","sources":["../../../src/scene/text-bitmap/AbstractBitmapFont.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3';\nimport { deprecation, v8_0_0 } from '../../utils/logging/deprecation';\n\nimport type { Texture } from '../../rendering/renderers/shared/texture/Texture';\nimport type { FontMetrics } from '../text/canvas/CanvasTextMetrics';\n\n/** @memberof text */\nexport interface CharData\n{\n /** Unique id of character */\n id: number;\n /** x-offset to apply when rendering character */\n xOffset: number;\n /** y-offset to apply when rendering character. */\n yOffset: number;\n /** Advancement to apply to next character. */\n xAdvance: number;\n /** The kerning values for this character. */\n kerning: Record<string, number>;\n /** The texture of the character. */\n texture?: Texture;\n}\n\n/**\n * The raw data of a character in a bitmap font.\n * @memberof text\n */\nexport interface RawCharData extends Omit<CharData, 'texture'>\n{\n /** The page of the font texture that the character is on. */\n page: number;\n /** The x position of the character in the page. */\n x: number;\n /** The y position of the character in the page. */\n y: number;\n /** The width of the character in the page. */\n width: number;\n /** The height of the character in the page. */\n height: number;\n /** The letter of the character. */\n letter: string;\n}\n\n/**\n * The raw data of a bitmap font.\n * @memberof text\n */\nexport interface BitmapFontData\n{\n /** The offset of the font face from the baseline. */\n baseLineOffset: number;\n /** The map of characters by character code. */\n chars: Record<string, RawCharData>;\n /** The map of base page textures (i.e., sheets of glyphs). */\n pages: {\n /** Unique id for bitmap texture */\n id: number;\n /** File name */\n file: string\n }[];\n /** The line-height of the font face in pixels. */\n lineHeight: number;\n /** The size of the font face in pixels. */\n fontSize: number;\n /** The name of the font face. */\n fontFamily: string;\n /** The range and type of the distance field for this font. */\n distanceField?: {\n /** Type of distance field */\n type: 'sdf' | 'msdf' | 'none';\n /** Range of the distance field in pixels */\n range: number;\n };\n}\n\ninterface BitmapFontEvents<Type>\n{\n destroy: [Type];\n}\n\n/**\n * An abstract representation of a bitmap font.\n * @memberof text\n */\nexport abstract class AbstractBitmapFont<FontType>\n extends EventEmitter<BitmapFontEvents<FontType>>\n implements Omit<BitmapFontData, 'chars' | 'pages' | 'fontSize'>\n{\n /** The map of characters by character code. */\n public readonly chars: Record<string, CharData> = Object.create(null);\n\n /**\n * The line-height of the font face in pixels.\n * @type {number}\n */\n public readonly lineHeight: BitmapFontData['lineHeight'] = 0;\n\n /**\n * The name of the font face\n * @type {string}\n */\n public readonly fontFamily: BitmapFontData['fontFamily'] = '';\n /** The metrics of the font face. */\n public readonly fontMetrics: FontMetrics = { fontSize: 0, ascent: 0, descent: 0 };\n /**\n * The offset of the font face from the baseline.\n * @type {number}\n */\n public readonly baseLineOffset: BitmapFontData['baseLineOffset'] = 0;\n /** The range and type of the distance field for this font. */\n public readonly distanceField: BitmapFontData['distanceField'] = { type: 'none', range: 0 };\n /** The map of base page textures (i.e., sheets of glyphs). */\n public readonly pages: { texture: Texture }[] = [];\n /** should the fill for this font be applied as a tint to the text. */\n public applyFillAsTint = true;\n\n /** The size of the font face in pixels. */\n public readonly baseMeasurementFontSize: number = 100;\n protected baseRenderedFontSize = 100;\n\n /**\n * The name of the font face.\n * @deprecated since 8.0.0 Use `fontFamily` instead.\n */\n public get font(): BitmapFontData['fontFamily']\n {\n // #if _DEBUG\n deprecation(v8_0_0, 'BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead.');\n // #endif\n\n return this.fontFamily;\n }\n\n /**\n * The map of base page textures (i.e., sheets of glyphs).\n * @deprecated since 8.0.0 Use `pages` instead.\n */\n public get pageTextures(): AbstractBitmapFont<FontType>['pages']\n {\n // #if _DEBUG\n deprecation(v8_0_0, 'BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead.');\n // #endif\n\n return this.pages;\n }\n\n /**\n * The size of the font face in pixels.\n * @deprecated since 8.0.0 Use `fontMetrics.fontSize` instead.\n */\n public get size(): BitmapFontData['fontSize']\n {\n // #if _DEBUG\n deprecation(v8_0_0, 'BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead.');\n // #endif\n\n return this.fontMetrics.fontSize;\n }\n\n /**\n * The kind of distance field for this font or \"none\".\n * @deprecated since 8.0.0 Use `distanceField.type` instead.\n */\n public get distanceFieldRange(): NonNullable<BitmapFontData['distanceField']>['range']\n {\n // #if _DEBUG\n // eslint-disable-next-line max-len\n deprecation(v8_0_0, 'BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead.');\n // #endif\n\n return this.distanceField.range;\n }\n\n /**\n * The range of the distance field in pixels.\n * @deprecated since 8.0.0 Use `distanceField.range` instead.\n */\n public get distanceFieldType(): NonNullable<BitmapFontData['distanceField']>['type']\n {\n // #if _DEBUG\n // eslint-disable-next-line max-len\n deprecation(v8_0_0, 'BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead.');\n // #endif\n\n return this.distanceField.type;\n }\n\n public destroy(destroyTextures = false): void\n {\n this.emit('destroy', this as unknown as FontType);\n\n this.removeAllListeners();\n\n for (const i in this.chars)\n {\n // texture may not exist if the char is \" \", \\n, \\r, or \\t.\n this.chars[i].texture?.destroy();\n }\n\n (this.chars as null) = null;\n\n if (destroyTextures)\n {\n this.pages.forEach((page) => page.texture.destroy(true));\n (this.pages as any) = null;\n }\n }\n}\n"],"names":[],"mappings":";;;;AAoFO,MAAe,2BACV,YAEZ,CAAA;AAAA,EAHO,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAKH;AAAA,IAAgB,IAAA,CAAA,KAAA,mBAAyC,MAAA,CAAA,MAAA,CAAO,IAAI,CAAA,CAAA;AAMpE;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAgB,UAA2C,GAAA,CAAA,CAAA;AAM3D;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAgB,UAA2C,GAAA,EAAA,CAAA;AAE3D;AAAA,IAAA,IAAA,CAAgB,cAA2B,EAAE,QAAA,EAAU,G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