c++qtqpainterqfontqt6

QPdfWriter not embedding standard fonts properly since Qt 6.0.0


Since switching to QT 6.0.0 I got problems with QPdfWriter. Every Time I try to print a text, the embedded font couldn't get loaded from various pdf reader (even Adobe reader). I'm as well not getting any errors or anything else on the output.

QPdfWriter writer("C:/Users/GGG/Desktop/lol.pdf");
writer.setResolution(300);
writer.setPageSize(QPageSize(QPageSize::A4));
writer.newPage();
QPainter painter;
painter.begin(&writer);
painter.drawText(600,600,"Hello, this is a test");
painter.end();

My attempts:

  1. Check the doc's and internet -> didn't found anything useful
  2. read out the font (there is one embedded, but faulty)
  3. Change font of QPainter to "Calibri"
  4. check if the font is available with db.hasFamily("Calibri"); (return value = true)
  5. Check graphics card driver -> installed rightly, no updates available .
  6. Rebuild with Qt 5.15.2 (in both cases MinGW64) -> Font is embedded correctly. But gone if I turn back to Qt version 6.0.0
  7. Checked my QT components -> I have installed for Qt 6.0.0: MinGW 8.1.0 64Bit, Sources, Qt 5 compatibility Module, Qt Shader Tools, Qt Debug Information Files.
  8. tried the same with QPrinter which prints Pdf files - same behaviour.

Still no clue what could cause this behavior. Does anyone got the same fault or has a solution?

Information about my system:
Windows 10, 64bit - used fonts are installed
Qt creator 4.14.0 - MinGW64 with Qt 6.0.0


Solution

  • Finally, after research on other forums like forum.qt.io I found out it might be a bug. There's alredy a bugreport open -> https://bugreports.qt.io/browse/QTBUG-89727


    edit: Turned out it was a bug - wich is fixed now. As the bugfixer wrote:

    Very nice and subtle bug - the container size was changed from int32_t to int64_t and the font serialization simply used QByteArray::size() without a cast.

    Bugfix here: https://codereview.qt-project.org/c/qt/qtbase/+/329442