TTF fonts won't display after upgrading to v9.1.0

Just tried to test an old openfl project I didn’t touch for about a year. Everything compiles but all the text fields only display the default font no matter what I do. I checked the 9.1.0 release note. I see there are some internal changes in the TextField class but didn’t spot any changes in the API. I’ve created a minimal project with a single text field:

import openfl.Assets;
import openfl.display.Sprite;
import openfl.text.TextField;
import openfl.text.TextFormat;

class Main extends Sprite {
	public function new() {
		super();

		final textField = new TextField();
		textField.setTextFormat(new TextFormat(Assets.getFont('assets/UbuntuMono-Regular.ttf').fontName));
		textField.text = 'Hello World';
		textField.autoSize = LEFT;
		addChild(textField);
	}
}

And that’s what I see running any target:
image
(Ignore the blurriness)

For reference Ubuntu Mono should look like that:
image

Downgrading to openfl 9.0.2, lime 7.8.0 and haxe 4.1.4 resolves the issue and the font displays properly.

Am I missing some API change?

Versions:
OpenFL 9.1.0
Lime 7.9.0
Haxe 4.2.3

I’m also also running everything on Linux (Arch) if it matters.

Try textField.defaultTextFormat instead of setTextformat or do setTextFormat after setting text. I dont believe setTextFormat works if there is no text as it changes the text format of a range of text within the textfield.

As per the documentation: Applies the text formatting that the format parameter specifies to the specified text in a text field. At the time of calling the method, you have no text in the textfield because you’re setting textfield.text afterwards.

1 Like

Indeed. This did the trick. Thanks!

The behavior makes sense. But I used to setTextFormat before setting the text for years and it worked somehow :smile: Just checked some other old projects.

You’re actually correct. This behavior does seem to have changed after confirming it myself, but I believe it is the correct behavior. This is precisely why there is a defaultTextFormat and a setTextFormat method, separately in flash to begin with irrc.

Edit: After testing it with flash, this does seem to be the correct behavior. Now that I’m thinking about it, I do recall we changed this behavior in the last release.

3 Likes