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

Fonts using QTextCharFormat::setFontStretch rendered incorrectly when printed or exported to PDF

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.11.2
    • GUI: Printing
    • None
    • macOS, Windows

    Description

      The attached zip file textedit-with-stretch.zip contains a lightly modified version of the standard TextEdit example project. Two additional spinboxes have been added to the toolbar: one sets font stretch on the selected text, and the other sets letter spacing on the selected text.

      1. Build and run the project.
      2. Select the QTextEdit text on the first line of the example document.
      3. Set its font size to (say) 36pt.
      4. Using the font stretch spin box, set its stretch to (say) 300.

      EXPECTED: The selected text is shown with an appropriate stretch factor, and all other text in the display is unaffected.
      ACTUAL: As expected.

      5. Click the Export PDF button on the toolbar, and provide a suitable filename and location.
      6. Open the resulting PDF.

      EXPECTED: The PDF looks the same as the on-screen display.
      ACTUAL: The stretched text is stretched as expected, but all of the subsequent Helvetica Bold text in the document is also stretched, and all of the characters overlap because each character is at its original, unstretched position.

      In the supplied example project, you can also flip m_UsePDFWriter to false in textedit.h and recompile to use QPrinter rather than QPdfWriter to produce the PDF. You will see similar results.

      My hypothesis is that there's some kind of font caching going on down in QPainter that is not taking factors like font stretch into account, meaning that QPainter is assuming that it can reuse a font it has already cached because its family (Helvetica) and weight (bold) is the same as an existing one.

      Attachments

        1. exported-pdf.png
          exported-pdf.png
          187 kB
        2. on-screen.png
          on-screen.png
          142 kB
        3. textedit-with-stretch.zip
          73 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            johnlayt John Layt
            dspreadbury Daniel Spreadbury
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes