QFontDatabase/QFont question
John Sturtz
john at sturtz.org
Sun Jan 12 04:38:16 GMT 2025
Thanks again guys! This has been a fascinating journey, and I've
learned a lot.
My rationale for wondering if one could determine whether a font is
variable or static was this: I don't seem to have trouble calling
.setItalic() on the static fonts -- that seems to work fine. Although
as Charles pointed out, if the font in question has an Italic style
option, the Italic version I get from requesting that style sometimes
differs slightly in appearance from the synthesized oblique I get from
.setItalic(). But at least it seems to work. It's only when I use
.setItalic() on variable fonts that things seem to go awry. So I
thought at least if I could distinguish between the two, I could take a
stab at handling them differently.
Interestingly, Maurizio, your idea seems to work. A variable font
should have an 'avar' (axis variations) table. Testing on the fonts I
have installed (including a couple additional variable fonts I added
from Google fonts, just to add to the pile):
>f = QFontDatabase.font(family, style, size)
>q = QtGui.QRawFont.fromFont(f)
>v = q.fontTable('avar')
results in v being True (a non-null byte sequence) for the variable
fonts, and False (b'') for the static fonts. Whether I'll ever succeed
in making any use of that fact remains to be seen, but it's interesting.
In case you're wondering what I'm up to, I'm trying to create a font
picker dialog for an app I'm working on (the same app, BTW, that I was
working on when Maurizio first answered a question for me in 2019). The
idea is to allow the user to choose the font for various display items
in the app window.
As such, I only use fonts that have been given to me by QFontDatabase.
I think that means that what I ask for with QFont() and what I get, as
reported by QFontInfo(), should be the same. I hope, since I'm not
asking for anything QFontDatabase hasn't already told me was there.
And while I maybe wouldn't have described it as an endless journey into
hell (yet), it would be fair to say it has proven to be an arduous task
so far. 😐
Thanks again for the help. This gives me a lot to chew on. Learning
all the time ...
/John
------ Original Message ------
>From "Maurizio Berti" <maurizio.berti at gmail.com>
To "Charles" <peacech at gmail.com>
Cc "John Sturtz" <john at sturtz.org>; pyqt at riverbankcomputing.com
Date 1/11/2025 8:41:25 PM
Subject Re: Re[8]: QFontDatabase/QFont question
>Il giorno dom 12 gen 2025 alle ore 03:04 Charles <peacech at gmail.com> ha
>scritto:
>>variableAxisTags displays the tags that you have set, not the
>>available tags for the font.
>
>I was afraid of that.
>
>Yet, a few hours ago I remembered about QRawFont, and I just found out
>that a QRawFont.fontTable()
><https://doc.qt.io/qt-6/qrawfont.html#fontTable> function has been
>introduced as well since 6.7 (you can access a QRawFont object through
>the static QRawFont.fromFont()).
>As said, I haven't had the opportunity to test variable fonts, so the
>above may still fall into the case mentioned by Charles.
>Still, it's worth a shot.
>
>If it still doesn't provide valid results, and as long as nobody else
>finds a more simple and reliable way to check if a font has variable
>features, you may consider filing a feature request ("Suggestion" in
>the "Issue Type" field) on the Qt bug tracker. Assuming it's actually
>possible.
>
>Just keep in mind that a QFont instance is more of an abstraction
>layer, and does not intrinsically represent a specific font.
>From the description in its documentation
><https://doc.qt.io/qt-6/qfont.html#details> (emphasis mine):
>
>>QFont can be regarded as a query for one or more fonts on the system.
>
>That's why QFontMetrics also provides a constructor that is based on a
>given paint device, which may give different results based on that
>device and its capabilities.
>Font management is tricky (especially for cross-platform aspects), and
>the variable font support introduced since 6.7 is relatively new.
>We may need some time until all these aspects are properly addressed,
>and filing proper reports may be a good thing to carefully consider.
>
>And don't forget that font/text layout and management is an endless
>journey into hell...
>
>Cheers,
>MaurizioB
>
>--
>È difficile avere una convinzione precisa quando si parla delle ragioni
>del cuore. - "Sostiene Pereira", Antonio Tabucchi
>http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20250112/b549d207/attachment.htm>
More information about the PyQt
mailing list