Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
5.4.0
-
None
-
Windows 7
Description
Printing QTextDocument to a PDF results bad looking font with Qt 5.4.0. With Qt 5.3.1 the text in the PDF file looked better. In Qt 5.4.0 the width of the words is the same but the font size seems smaller thus leaving more space in between the characters.
Attached PDF documents show how the text looks like with both versions. The code below can be used to reproduce the issue.
#include <QApplication> #include <QTextDocument> #include <QAbstractTextDocumentLayout> #include <QTextCursor> #include <QPrinter> #include <QFont> int main(int argc, char *argv[]) { QApplication a(argc, argv); QTextDocument doc; QPrinter printer(QPrinter::HighResolution); printer.setPaperSize(QPrinter::A4); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName("report.pdf"); doc.documentLayout()->setPaintDevice(&printer); QTextCursor cursor(&doc); QFont font = doc.defaultFont(); font.setFamily("Calibri"); font.setPointSize(8); doc.setDefaultFont(font); cursor.beginEditBlock(); cursor.insertText("Text Text Text Text Text Text Text Text Text Text"); cursor.insertBlock(); QTextCharFormat format(cursor.charFormat()); format.setFontWeight(QFont::Bold); cursor.setCharFormat(format); cursor.insertText("Bold Text Bold Text Bold Text Bold Text"); cursor.endEditBlock(); doc.print(&printer); return 0; }