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">
1 lines • 2.72 kB
Source Map (JSON)
{"version":3,"file":"updateTextBounds.mjs","sources":["../../../../src/scene/text/utils/updateTextBounds.ts"],"sourcesContent":["import { updateQuadBounds } from '../../../utils/data/updateQuadBounds';\nimport { type BatchableSprite } from '../../sprite/BatchableSprite';\nimport { type AbstractText } from '../AbstractText';\nimport { type TextStyle, type TextStyleOptions } from '../TextStyle';\n\n/**\n * Updates the bounds of the given batchable sprite based on the provided text object.\n *\n * This function adjusts the bounds of the batchable sprite to match the dimensions\n * and anchor point of the text's texture. Additionally, it compensates for any padding\n * specified in the text's style to ensure the text is rendered correctly on screen.\n * @param {BatchableSprite} batchableSprite - The sprite whose bounds need to be updated.\n * @param {AbstractText} text - The text object containing the texture and style information.\n * @internal\n */\nexport function updateTextBounds(batchableSprite: BatchableSprite, text: AbstractText<TextStyle, TextStyleOptions>)\n{\n const { texture, bounds } = batchableSprite;\n const padding = text._style._getFinalPadding();\n\n // When HTML text textures are created, they include the padding around the text content\n // to prevent text clipping and provide a buffer zone. This padding is built into\n // the texture itself. However, we don't want this padding to affect the text's\n // actual position on screen.\n\n // First, calculate bounds using the full padded texture\n updateQuadBounds(bounds, text._anchor, texture);\n\n // Then adjust by the padding amount to compensate for the buffer zone\n // This shifts the render position back by the padding amount, ensuring the text\n // appears exactly where intended while maintaining the buffer zone around it.\n const paddingOffset = text._anchor._x * padding * 2;\n const paddingOffsetY = text._anchor._y * padding * 2;\n\n bounds.minX -= padding - paddingOffset;\n bounds.minY -= padding - paddingOffsetY;\n bounds.maxX -= padding - paddingOffset;\n bounds.maxY -= padding - paddingOffsetY;\n}\n"],"names":[],"mappings":";;;AAeO,SAAS,gBAAA,CAAiB,iBAAkC,IAAA,EACnE;AACI,EAAA,MAAM,EAAE,OAAA,EAAS,MAAA,EAAO,GAAI,eAAA;AAC5B,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,MAAA,CAAO,gBAAA,EAAiB;AAQ7C,EAAA,gBAAA,CAAiB,MAAA,EAAQ,IAAA,CAAK,OAAA,EAAS,OAAO,CAAA;AAK9C,EAAA,MAAM,aAAA,GAAgB,IAAA,CAAK,OAAA,CAAQ,EAAA,GAAK,OAAA,GAAU,CAAA;AAClD,EAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,OAAA,CAAQ,EAAA,GAAK,OAAA,GAAU,CAAA;AAEnD,EAAA,MAAA,CAAO,QAAQ,OAAA,GAAU,aAAA;AACzB,EAAA,MAAA,CAAO,QAAQ,OAAA,GAAU,cAAA;AACzB,EAAA,MAAA,CAAO,QAAQ,OAAA,GAAU,aAAA;AACzB,EAAA,MAAA,CAAO,QAAQ,OAAA,GAAU,cAAA;AAC7B;;;;"}