Font families are truncated

Charles peacech at gmail.com
Sat Nov 16 00:27:42 GMT 2024


I tested it and Qt 6.8.0 seems to use directwrite by default. Any other
engine still results in truncated names. Directwrite gives a better font
family names.

Qt 6.8.0 (no parameter or using -platform windows:fontengine=directwrite)
Inconsolata SemiCondensed
  SemiCondensed
  SemiCondensed Medium
  SemiCondensed Bold
Inconsolata Condensed
  Condensed
  Condensed Medium
  Condensed Bold
Inconsolata
  Regular
  Medium
  Bold

Qt5/Qt6 with -platform windows:fontengine=gdi/-platform
windows:fontengine=freetype
Inconsolata SemiCondensed Mediu
  Regular
Inconsolata Condensed Medium
  Regular
Inconsolata SemiCondensed
  Medium
  Regular
  Bold
Inconsolata Condensed
  Medium
  Regular
  Bold
Inconsolata Medium
  Regular
Inconsolata
  Medium
  Regular
  Bold

On Fri, Nov 15, 2024 at 11:33 PM John F Sturtz <john at sturtz.org> wrote:

> I'm probably in over my head here.  Don't know how to check whether (Py)Qt
> is compiled with freetype.
>
> Following the instructions at the bottom of the page, I did put the
> qt.conf file shown in the directory where python.exe resides [probably
> wouldn't ultimately be the optimal location for it, but that is what
> QCoreApplication.applicationDirPath() returns, and it seemed the easiest
> thing to try first].
>
> That didn't appear to change the behavior ...
>
> At one point awhile back, I did try to make a push to migrate my code to
> Qt6, but there was one piece of code I never could get to work properly.
> So I abandoned the effort.  :-<
>
> Thanks again!
>
> /John
>
> Charles <peacech at gmail.com>
> Thursday, November 14, 2024 11:27 PM
> If your Qt is compiled with freetype, you can try using it instead, see
>
> https://doc.qt.io/qt-5/qt-conf.html (bottom of page)
>
> https://github.com/qt/qtbase/blob/v5.15.14-lts-lgpl/src/plugins/platforms/windows/qwindowsintegration.cpp#L189
>
> John F Sturtz <john at sturtz.org>
> Thursday, November 14, 2024 11:12 PM
> Alas.  Still working in (Py)Qt5.  I'm probably stuck with it then.
>
> Thanks.
>
> /John
>
>
> Charles <peacech at gmail.com>
> Thursday, November 14, 2024 10:35 PM
> That is the limitation of using GDI font engine. If you are using Qt>=6.7,
> trying using -platform windows:fontengine=directwrite command line
> parameter.
>
> John F Sturtz <john at sturtz.org>
> Thursday, November 14, 2024 9:12 PM
> Greetings again!
>
> This is perhaps a bit of an esoteric question.
>
> I am using QFontDatabase and QFont to query and manipulate some display
> fonts.  On my system, there are some font family/variant combinations that
> have pretty long names.  Several in the Bahnschrift family, for instance
> -- Bahnschrift SemiBold SemiCondensed, Bahnschrift SemiLight
> SemiCondensed, and so on.
>
> The Windows font settings app lists these with their full names.  Also, if
> I query the .ttf file directly:
>
>     path = r'C:\Windows\fonts\bahnschrift.ttf'
>     font = ttLib.TTFont(path)
>     for instance in font["fvar"].instances:
>         style = font["name"].getName(instance.subfamilyNameID, 3, 1, 0x409)
>         print(style)
>
> I get the full names.
>
> However, if I get a list of font families using QFontDatabase().families(),
> the names that are returned are truncated to (oddly) 31 characters.  So,
> for example, Bahnschrift SemiBold SemiConden, Bahnschrift SemiLight
> SemiConde, and the like.
>
> And indeed, if I want to create a QFont object for these, I seem to need
> to use the truncated names:
>
> QFont('Bahnschrift SemiBold SemiConden')        # These work
> QFont('Bahnschrift SemiLight SemiConde')
>
> QFont('Bahnschrift SemiBold SemiCondensed')     # These do not
> QFont('Bahnschrift SemiLight SemiCondensed')
>
> Not a huge deal, but it's a little difficult, because the names PyQt
> seems to recognize aren't the ones I'd want to present to the user (nor
> ones I would have thought to use, but for the fact that QFontDatabase(
> ).families() gave them to me that way).  Any thoughts as to why?
>
> Thanks again, as always!
>
> /John
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20241116/a1c94e44/attachment-0001.htm>


More information about the PyQt mailing list