Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toJSON() on Text doesn't save the font style when using the "font" shorthand #4141

Closed
divillysausages opened this issue Nov 3, 2018 · 1 comment · Fixed by #4183
Closed

Comments

@divillysausages
Copy link

I'm using a Google font in my project, loaded like this:

<!DOCTYPE html>
<html>
	<head>
		<style>
			@font-face {
				font-family: 'GameFont';
				src: url( 'assets/LuckiestGuy-Regular.ttf' )
			}
			
			.fontPreload {
				font-family: 'GameFont';
				position: absolute;
				left:-100px;
			}
		</style>
	</head>
	<body>
		<div class="fontPreload">.</div>
	</body>
</html>

In game, I'm displaying a Text field like so:

const t = scene.add.text( 100, 100, `This is some game text. and some more here and here`, {
	font: "20px GameFont",
	color: "#ffffff"
})

It displays correctly in game.

If I print out the result of toJSON(), it's missing the font name and size:

{
  ...
  "data": {
    "autoRound": true,
    "text": "This is some game text. and some more here and here",
    "style": {
      "fontFamily": "Courier",
      "fontSize": "16px",
      "fontStyle": "",
      "backgroundColor": null,
      "color": "#ffffff",
      "testString": "|MÉqgy",
      ...
    },
    ...
}

If, when creating the Text object, I don't use the font shorthand, the JSON result is correct:

const t = scene.add.text( 100, 100, `This is some game text. and some more here and here`, {
	fontFamily: "GameFont",
        fontSize: 20,
	color: "#ffffff"
})
{
  ...
  "data": {
    "autoRound": true,
    "text": "This is some game text. and some more here and here",
    "style": {
      "fontFamily": "GameFont",
      "fontSize": "20px",
      ...
      }
    },
    ...
  }
}
DottieDot added a commit to DottieDot/phaser that referenced this issue Nov 22, 2018
DottieDot added a commit to DottieDot/phaser that referenced this issue Nov 22, 2018
…n using the font shorthand & fixes phaserjs#4141

I noticed this while investigating phaserjs#4141
photonstorm added a commit that referenced this issue Dec 12, 2018
@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants