Skip to content

Commit

Permalink
Allow for easier overriding of Text resolution (#8912)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Dec 1, 2022
1 parent 78160b5 commit c2af9e2
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/text/src/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ interface ModernContext2D extends ICanvasRenderingContext2D
*/
export class Text extends Sprite
{
/**
* Override whether or not the resolution of the text is automatically adjusted to match the resolution of the renderer.
* Setting this to false can allow you to get crisper text at lower render resolutions.
* @example
* // renderer has a resolution of 1
* const app = new Application();
*
* Text.defaultResolution = 2;
* Text.defaultAutoResolution = false;
* // text has a resolution of 2
* const text = new Text('This is a PixiJS text');
*/
public static defaultAutoResolution = true;

/**
* If {@link PIXI.Text.defaultAutoResolution} is false, this will be the default resolution of the text.
* If not set it will default to {@link PIXI.settings.RESOLUTION}.
* @example
* Text.defaultResolution = 2;
* Text.defaultAutoResolution = false;
*
* // text has a resolution of 2
* const text = new Text('This is a PixiJS text');
*/
public static defaultResolution: number;

/**
* New rendering behavior for letter-spacing which uses Chrome's new native API. This will
* lead to more accurate letter-spacing results because it does not try to manually draw
Expand Down Expand Up @@ -184,8 +210,8 @@ export class Text extends Sprite
willReadFrequently: true,
});

this._resolution = settings.RESOLUTION;
this._autoResolution = true;
this._resolution = Text.defaultResolution ?? settings.RESOLUTION;
this._autoResolution = Text.defaultAutoResolution;
this._text = null;
this._style = null;
this._styleListener = null;
Expand Down

0 comments on commit c2af9e2

Please sign in to comment.