Skip to content

Commit 94540e1

Browse files
committed
Text supports high dpi resolution for its internal canvas
1 parent 6ddd164 commit 94540e1

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

src/gameobjects/text/TextStyle.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var propertyMap = {
4040
maxLines: [ 'maxLines', 0 ],
4141
fixedWidth: [ 'fixedWidth', 0 ],
4242
fixedHeight: [ 'fixedHeight', 0 ],
43+
resolution: [ 'resolution', 0 ],
4344
rtl: [ 'rtl', false ],
4445
testString: [ 'testString', '|MÉqgy' ],
4546
baselineX: [ 'baselineX', 1.2 ],
@@ -259,6 +260,17 @@ var TextStyle = new Class({
259260
*/
260261
this.fixedHeight;
261262

263+
/**
264+
* The resolution the text is rendered to its internal canvas at.
265+
* The default is 0, which means it will use the resolution set in the Game Config.
266+
*
267+
* @name Phaser.GameObjects.Text.TextStyle#resolution
268+
* @type {number}
269+
* @default 0
270+
* @since 3.12.0
271+
*/
272+
this.resolution;
273+
262274
/**
263275
* Whether the text should render right to left.
264276
*

src/gameobjects/text/static/Text.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ var Text = new Class({
141141
*/
142142
this.text = '';
143143

144-
/**
145-
* The resolution of the text.
146-
*
147-
* @name Phaser.GameObjects.Text#resolution
148-
* @type {number}
149-
* @default 1
150-
* @since 3.0.0
151-
*/
152-
this.resolution = 1;
153-
154144
/**
155145
* Specify a padding value which is added to the line width and height when calculating the Text size.
156146
* Allows you to add extra spacing if the browser is unable to accurately determine the true font dimensions.
@@ -201,6 +191,12 @@ var Text = new Class({
201191
*/
202192
this.dirty = false;
203193

194+
// If resolution wasn't set, then we get it from the game config
195+
if (this.style.resolution === 0)
196+
{
197+
this.style.resolution = scene.sys.game.config.resolution;
198+
}
199+
204200
this.initRTL();
205201

206202
if (style && style.padding)
@@ -951,7 +947,7 @@ var Text = new Class({
951947
var canvas = this.canvas;
952948
var context = this.context;
953949
var style = this.style;
954-
var resolution = this.resolution;
950+
var resolution = style.resolution;
955951
var size = style.metrics;
956952

957953
style.syncFont(canvas, context);
@@ -1004,7 +1000,7 @@ var Text = new Class({
10041000

10051001
context.save();
10061002

1007-
// context.scale(resolution, resolution);
1003+
context.scale(resolution, resolution);
10081004

10091005
if (style.backgroundColor)
10101006
{
@@ -1105,7 +1101,6 @@ var Text = new Class({
11051101
autoRound: this.autoRound,
11061102
text: this.text,
11071103
style: this.style.toJSON(),
1108-
resolution: this.resolution,
11091104
padding: {
11101105
left: this.padding.left,
11111106
right: this.padding.right,

src/gameobjects/text/static/TextCanvasRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
8989

9090
ctx.scale(src.flipX ? -1 : 1, src.flipY ? -1 : 1);
9191

92-
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, -src.displayOriginX, -src.displayOriginY, canvas.width, canvas.height);
92+
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, -src.displayOriginX, -src.displayOriginY, canvas.width / src.style.resolution, canvas.height / src.style.resolution);
9393

9494
ctx.restore();
9595
};

src/gameobjects/text/static/TextWebGLRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var TextWebGLRenderer = function (renderer, src, interpolationPercentage, camera
4242
src.canvasTexture,
4343
src.canvasTexture.width, src.canvasTexture.height,
4444
src.x, src.y,
45-
src.canvasTexture.width, src.canvasTexture.height,
45+
src.canvasTexture.width / src.style.resolution, src.canvasTexture.height / src.style.resolution,
4646
src.scaleX, src.scaleY,
4747
src.rotation,
4848
src.flipX, src.flipY,

0 commit comments

Comments
 (0)