Repository: pixijs/pixijs
File: src/scene/text/canvas/CanvasTextSystem.ts (TypeScript)

Code before:

    public getTextureSize(text: string, resolution: number, style: TextStyle): { width: number, height: number }
    {
        const measured = CanvasTextMetrics.measureText(text || ' ', style);

        let width = Math.ceil(Math.ceil((Math.max(1, measured.width) + (style.padding * 2))) * resolution);
        let height = Math.ceil(Math.ceil((Math.max(1, measured.height) + (style.padding * 2))) * resolution);

        width = Math.ceil((width) - 1e-6);
        height = Math.ceil((height) - 1e-6);
        width = nextPow2(width);
        height = nextPow2(height);

        return { width, height };
    }

    /**
     * This is a function that will create a texture from a text string, style and resolution.
     * Useful if you want to make a texture of your text and use if for various other pixi things!
     * @param options - The options of the text that will be used to generate the texture.
     * @param options.text - the text to render
     * @param options.style - the style of the text
     * @param options.resolution - the resolution of the texture
     * @returns the newly created texture
     */
    public getTexture(options: TextOptions): Texture
    {
        if (!(options.style instanceof TextStyle))
        {
            options.style = new TextStyle(options.style);
        }

        const { texture, canvasAndContext } = this.createTextureAndCanvas(
            options as {text: string, style: TextStyle, resolution?: number}
        );

        this._renderer.texture.initSource(texture._source);

        CanvasPool.returnCanvasAndContext(canvasAndContext);

        return texture;
    }

    public createTextureAndCanvas(options: {text: string, style: TextStyle, resolution?: number})
    {
        const { text, style } = options;

        const resolution = options.resolution ?? this._renderer.resolution;

        // create a canvas with the word hello on it
        const measured = CanvasTextMetrics.measureText(text || ' ', style);

Review comment (suggestion):
Can you deprecate the old function signature. We shouldn't be making breaking changes to public API's without at least deprecating it first

Code after:
    }

    public getTextureSize(text: string, resolution: number, style: TextStyle): { width: number, height: number }
    {
        const measured = CanvasTextMetrics.measureText(text || ' ', style);

        let width = Math.ceil(Math.ceil((Math.max(1, measured.width) + (style.padding * 2))) * resolution);
        let height = Math.ceil(Math.ceil((Math.max(1, measured.height) + (style.padding * 2))) * resolution);

        width = Math.ceil((width) - 1e-6);
        height = Math.ceil((height) - 1e-6);
        width = nextPow2(width);
        height = nextPow2(height);

        return { width, height };
    }

    /**
     * This is a function that will create a texture from a text string, style and resolution.
     * Useful if you want to make a texture of your text and use if for various other pixi things!
     * @param options - The options of the text that will be used to generate the texture.
     * @param options.text - the text to render
     * @param options.style - the style of the text
     * @param options.resolution - the resolution of the texture
     * @returns the newly created texture
     */
    /** @deprecated since 8.0.0 */
    public getTexture(text: string, resolution: number, style: TextStyle, textKey: string): Texture;
    public getTexture(options: TextOptions): Texture;
    public getTexture(options: TextOptions | string, resolution?: number, style?: TextStyle, _textKey?: string): Texture
    {
        if (typeof options === 'string')
        {
            deprecation('8.0.0', 'CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments');

            options = {
                text: options,
                style,
                resolution,
            };
        }

        if (!(options.style instanceof TextStyle))
        {
            options.style = new TextStyle(options.style);
        }

        const { texture, canvasAndContext } = this.createTextureAndCanvas(
            options as {text: string, style: TextStyle, resolution?: number}
        );