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

Cannot use both regular and solid fonts together in the same Qt/QML application #12787

Closed
mhoeher opened this issue Apr 5, 2018 · 9 comments
Closed

Comments

@mhoeher
Copy link

mhoeher commented Apr 5, 2018

I often use Font Awesome in Qt/QML applications. In v4, this was quite straightforward, all that needed to be done was using a FontLoader and then set the font.family attribute of text elements to the font family (which could be retrieved via the FontLoader).

With v5, we now have several font files (e.g. there are 3 *.ttf files in the Free version). Generally, it is possible to use multiple FontLoaders to load all of them. However, I noticed that the font family for the regular and solid variants are the same. Hence, I cannot easily switch between the two by setting the font.family attribute of text objects.

I would have expected to be able to select the variant by one of the following:

  • Setting the font.weight property. This did not work out for some reasons - maybe a Qt issue?
  • Setting the font.styleName property, i.e. Solid vs Regular. However, this also did not work (because all the font files are set to Regular).

For the time being, I worked around the issue by editing the file fa-solid-900.ttf with FontForge and setting the font family to Font Awesome 5 Free Solid. With the modified *.ttf file I can easily switch between the two styles in my QML application. It would however be cool if Font Awesome would work out of the box with Qt/QML ;-)

Thanks for considering!

Btw: The brands font file seems to work just fine, however, this is probably due to it uses a different font family name compared to the other two.

@tagliala
Copy link
Member

tagliala commented Apr 6, 2018

Hi!

Thanks for being part of the Font Awesome Community.

Sorry but I cannot help. Let's wait for some feedback by the community

Setting the font.weight property. This did not work out for some reasons - maybe a Qt issue?

Please check with another font (with separate files for each style)

Setting the font.styleName property, i.e. Solid vs Regular. However, this also did not work (because all the font files are set to Regular).

@robmadole is there something we can do about this?

@mhoeher
Copy link
Author

mhoeher commented Apr 6, 2018

Hi @tagliala,

thanks for the hint! I tried to reproduce this with another Font (I tried with Comfortaa) by doing the following:

  1. I downloaded the font and unzipped it.
  2. I put a file font-weight-comfortaa.qml file into the unzipped folder.
  3. I ran qmlscene font-weight-comfortaa.qml.

The results:
On standard output it prints:

qml: Comfortaa
qml: Comfortaa

as expected. And the rendering is as follows:

image

Which looks as expected. Then, I tried the same with Font Awesome:

  1. Downloaded and extracted.
  2. Put a file font-weight-fontawesome.qml into the folder /web-fonts-with-css/webfonts/.
  3. I ran qmlscene font-weight-fontawesome.qml.

The result: On standard out it prints:

qml: Font Awesome 5 Free
qml: Font Awesome 5 Free

And the result is this:

image

Here, my expectation would have been that the lighter variants would use the icons from the regular font while the bolder ones use the one from the solid one.

@robmadole
Copy link
Member

@mhoeher I'm not sure I can be of much use to you. Those fonts are using different weight classes. I'm not sure how Qt handles that. You might try using the .OTF files instead if that's possible.

@mhoeher
Copy link
Author

mhoeher commented Apr 10, 2018

Hi @robmadole,

I modified my sample from above and replaced the *.ttf fonts with the *.otf ones, however, the result is the same. :-(

@huyder
Copy link

huyder commented Jul 25, 2018

One of our application we are using is using the qt QFontDatabase (https://doc.qt.io/qt-5/qfontdatabase.html#addApplicationFont) class and we are having a similar problem with it not being able to distinguish between the light/regular/solid TTF webfonts. The developer of that software company informed us that the cause of the issue is because all these TTF fonts have the exact same name: "Font Awesome 5 Pro".

Can you please add "Light", "Regular", and "Solid" to the name of these fonts so that libraries like Qt can distinguish them?

@tagliala
Copy link
Member

Maybe this is the same issue as #13320

@mhoeher
Copy link
Author

mhoeher commented Jul 29, 2018

Hi @tagliala,

after your hint I tried my example from above with the most recent release. The good news: Using the *.otf font files from the desktop release package, I now get the expected result:

image

So it seems there were some fixes for these files :-)

In addition, I tried with the .ttf fonts from the web fonts zip, but using these, I still get the wrong output shown in my earlier post.

@tagliala
Copy link
Member

Glad you've solved.

.ttf files are not supposed to be used on the desktop, because they are generated for the web by a webfont script

@mhoeher
Copy link
Author

mhoeher commented Jul 29, 2018

Okay, then I think this issue can be considered done ;-)

@mhoeher mhoeher closed this as completed Jul 29, 2018
pestophagous added a commit to 219-design/qt-qml-project-template-with-ci that referenced this issue May 23, 2020
the ttf file was modified to give it a unique font name. steps were:

    sudo apt install fonttools # to install '/usr/bin/ttx'

    ttx fa-solid-900.ttf # produces a TTX file
    sed -i 's/Font Awesome 5/Font Awesome Solid 5/' fa-solid-900.ttx
    rm fa-solid-900.ttf
    ttx fa-solid-900.ttx # converts back to TTF

unique font name was assigned to avoid issues described at:

    FortAwesome/Font-Awesome#12787
    https://stackoverflow.com/a/49956771/10278
pestophagous added a commit to 219-design/qt-qml-project-template-with-ci that referenced this issue May 23, 2020
the ttf file was modified to give it a unique font name. steps were:

    sudo apt install fonttools # to install '/usr/bin/ttx'

    ttx fa-solid-900.ttf # produces a TTX file
    sed -i 's/Font Awesome 5/Font Awesome Solid 5/' fa-solid-900.ttx
    rm fa-solid-900.ttf
    ttx fa-solid-900.ttx # converts back to TTF

unique font name was assigned to avoid issues described at:

    FortAwesome/Font-Awesome#12787
    https://stackoverflow.com/a/49956771/10278
pestophagous added a commit to pestophagous/heory that referenced this issue Mar 2, 2021
the ttf file was modified to give it a unique font name. steps were:

    sudo apt install fonttools # to install '/usr/bin/ttx'

    ttx fa-solid-900.ttf # produces a TTX file
    sed -i 's/Font Awesome 5/Font Awesome Solid 5/' fa-solid-900.ttx
    rm fa-solid-900.ttf
    ttx fa-solid-900.ttx # converts back to TTF

unique font name was assigned to avoid issues described at:

    FortAwesome/Font-Awesome#12787
    https://stackoverflow.com/a/49956771/10278
pestophagous added a commit to pestophagous/heory that referenced this issue Mar 2, 2021
the ttf file was modified to give it a unique font name. steps were:

    sudo apt install fonttools # to install '/usr/bin/ttx'

    ttx fa-solid-900.ttf # produces a TTX file
    sed -i 's/Font Awesome 5/Font Awesome Solid 5/' fa-solid-900.ttx
    rm fa-solid-900.ttf
    ttx fa-solid-900.ttx # converts back to TTF

unique font name was assigned to avoid issues described at:

    FortAwesome/Font-Awesome#12787
    https://stackoverflow.com/a/49956771/10278
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants