Forums

OverviewV-Play 1 Support › Custom fonts on Android

Tagged: 

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #4002

    Christian
    V-Play Team

    I’m using a custom font in my game, with a FontLoader element.

    On the PC, it works, but on Android, it doesn’t seem to work, instead the default font is used.

    This is the font I’m trying to use: http://www.dafont.com/spatha.font (spathasans.ttf)

    Is this a known issue/problem?

    #4117

    Alex
    V-Play Team

    Hi,

    thanks to you this is now a known issue, yes. 😉

    As it turns out, the font loader item loads the font as “Spatha”, Android however registers the font as “Spatha Sans” and therefore can’t load the font correctly. We will add a fix for this in the next update, in the meanwhile you can manually override the font name on Android only.

    I guess you have a FontLoader item like

    
      FontLoader {
        id: spatha
        source: "Spatha.ttf"
      }
    

    in your code. Please try to extend the loader according to following snippet:

    
      FontLoader {
        id: spatha
        source: "Spatha.ttf"
    
        Component.onCompleted: {
          // Explicitly set the font name on Android to Spatha Sans
          if (system.platform === System.Android)
            name = "Spatha Sans"
        }
      }
    

    Cheers,
    Alex

    #4118

    Christian
    V-Play Team

    Quote from Alex on January 14, 2013, 15:20
    I guess you have a FontLoader item like

    
      FontLoader {
        id: spatha
        source: "Spatha.ttf"
      }
    

    in your code.

    Yes, exactly like this :)
    Your fix worked, thanks!

    #4119

    Christian
    V-Play Team

    I noticed one more thing: Centering the text seems not to be working on Android, it looks like it’s size is calculated with the original font, because Spatha is generally thinner than the default font, and then horizontally centered texts appear more left than in the middle.

    But on the desktop build, it looks fine.

    #4120

    Alex
    V-Play Team

    That’s unfortunately a side effect of the “name =” work-around (Qt is using the wrong font metrics as you’ve correctly assumed). Let’s give it another try: Remove the Component.onComplete code block posted above again and please build it again like you’ve done before. We’ve pushed a small hotfix update for the platform-related code on the Build Server and font loading should now work like expected. 😉

    Looking forward to your results, if there are still problems it would be great if you can post a small Text item snippet (with parent) how you’ve tried to center it.

    Cheers,
    Alex

    #4121

    Christian
    V-Play Team

    Yes, it works AND is correctly aligned! Very nice :)

    For the reference, this is an example of how we center a text:

    Column {
            anchors.centerIn: parent
            spacing: 5
            Text {
                text: "You solved the level with " + game.moves + " moves!"
                anchors.horizontalCenter: parent.horizontalCenter
                font.pixelSize: buttonSize / 3
                font.family: window.fontName
                color: "white"
            }
    
         //...more items in column
    }
    #4122

    Alex
    V-Play Team

    Great, thanks again for pointing this out!

    #4505

    Saims

    Hi,

    I didn’t want to open a new thread, cause I have the same issue, but the fix doesn’t work for me, so I post it here.

    My fontloader in the main.qml looks like this:

    FontLoader {
            id: fontloaderfont
            source: "fonts/galascript.ttf"
    
            Component.onCompleted: {
                if(system.platform === System.Android){
                    name = "Galascript Sans"
                }
            }
        }

    and I use the fontload e.g. like this:

    Text {
        id: text
        font.pixelSize: 10
        color: "white"
        font.family: fontloaderfont.name
    }

     

    The code works perfectly fine on the PC, whereas on Android the default-font is used.
    Unfortunately I couldn’t test it on iOS, but there the previously used font worked in general, but some text wasn’t displayed (e.g. “Package 1” was “Package “, “Restart” was “Restar “)

    I also tried to remove the onComplete again in the FontLoader, but after doing that, the app wouldn’t even start on Android!

    #4506

    Alex
    V-Play Team

    Hi,

    we recently changed font rendering with the last SDK update, against which version are you building currently? Also, is your used font available for download somewhere so that we can reconstruct the problem?

    Cheers,

    Alex

    #4507

    Saims

    okay, it works with “Gala Script”

    problem solved! :)

    #7545

    Marios

    Hi,I am having the same problem with a custom made font, with a FontLoader element.

    While debugging on the PC it works, but on Android the default font is used and the text element does not align correctly.

    I am using v-play 1.5.0.

    I tried the workaround to set the font name oncompleted but it didn’t work.

    I’ve sent the font to support@v-play.net

    marios

    #7551

    Alex
    V-Play Team

    Hi marios,

    I just tested the code you sent us on a Samsung Galaxy S3 and it worked without any problems.

    What device(s) are you testing on?

    Cheers,
    Alex

    #7553

    Marios

    Hi alex,

    I am testing it on a samsung b5330 and an htc wildfire s.

    Could I be using something else that could mess things up?

    Is there a chance you could test the last test build that is up on the build server?

    Thanks

    #7556

    Alex
    V-Play Team

    Hi marios,

    please create a new project with only the FontLoader and some text and check if the error also appears. If it does appear, it would be very nice if you could send us the logcat output of your device via email again.

    Cheers,
    Alex

    #7557

    Alex
    V-Play Team

    Please also use “sdk”: “daily” in the config.json of your project, as there were some fixes for fonts on Android after 1.5.0.

    You should also be able to upgrade your SDK to the latest version with the SDK Maintenance Tool.

    Cheers,
    Alex

    • This reply was modified 4 years, 2 months ago by  Alex.
Viewing 15 posts - 1 through 15 (of 17 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support