Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 1 Support › Custom fonts on Android

Tagged: 

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

    Christian
    Felgo 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
    Felgo 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
    Felgo 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
    Felgo 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
    Felgo 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
    Felgo 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
    Felgo 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
    Felgo 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@felgo.com

    marios

    #7551

    Alex
    Felgo 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
    Felgo 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
    Felgo 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 9 years, 11 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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded