Font.fontName returns gibberish on Android


I’ve been testing font embedding on Android and I’m having problems with fontName.

While on Windows/Neko/Flash/HTML5 ir returns the proper font name, on Android it just returns some encoded gibberish.

This is the code I’m testing, right now:

        var font:Font = Assets.getFont( "fonts/montserrat.ttf" );
        trace( font );
        trace( font.fontName );
        var tf:TextField = new TextField();
        var td:TextFormat = new TextFormat(
        tf.defaultTextFormat = td;
        tf.text = "TEST";
        tf.autoSize = TextFieldAutoSize.LEFT;
        tf.type = TextFieldType.DYNAMIC;
        tf.multiline = false;
        tf.embedFonts = true;
        tf.selectable = false;
        tf.x = 120;
        tf.y = 120;
        addChild( tf );

For the Android output, using legacy mode works just fine and the font is properly rendered.

But, without legacy mode, tracing returns this:

I/trace   (27320): Main.hx:67: Font
I/trace   (27320): Main.hx:68: ¹ª¢ì³ªò│¹ùæí²ûØÑþëí

I don’t know if I’m doing something wrong in here, but looks like I’m not. :stuck_out_tongue:

Can anybody shed some light into this?

Thanks! :smile:

Just some update on the matter. Besides going for “legacy” mode, if I do this, it works pretty fine on Android:

#if android
    var fo:Font = new Font( "fonts/montserrat.ttf" );
    var fo:Font = Assets.getFont( "fonts/montserrat.ttf" );

I was having a similar problem, except all of my targets were working fine in the morning and then all of the sudden my Android target stopped working properly (the font’s displayed a bunch of gibberish for the fontname just like you stated above).

I tried everything, rebooting my phone, rebooting my computer, reinstalling openfl/lime/etc, using JDK 6, using JDK 7, nothing worked…

Then I tried your suggestion above and BAM! Works again… Thank you so much! I literally spent about 6 hours working on this bug… Drove me nuts!

I’d really like to know what’s causing it though… And I’d like to know even more how it WAS working, then it stopped working… It seemed to happen after I installed StableXUI - but perhaps that was just a coincidence…

Sorry to drum up an old topic here, but I believe this might be due to bad UTF support in older Android NDKs, I updated to the newest (or was the newest?) Android NDK r11e and I don’t believe I have this issue on any Android device I’ve tested. It either is the newer devices or the NDK, but I’m inclined to believe this was a long-standing bug in the C++ standard library support in the NDK which was resolved finally :slight_smile:

1 Like