Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-44003

[REG] QTextDocument rendering to PDF results bad looking font

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Duplicate
    • Affects Version/s: 5.4.0
    • Fix Version/s: 5.4.1
    • Component/s: GUI: Printing
    • Labels:
      None
    • Environment:
      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;
      }
      
      

        Attachments

        1. report531.pdf
          10 kB
        2. report540.pdf
          10 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              johnlayt John Layt
              Reporter:
              qtcomsupport Qt Support
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes