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

Wrong character spacing when printing arabic text to PDF output, and wrong text alignment when printing the same text with the same alignment options to a normal printer

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.1.0
    • None
    •  - tried both Windows 7 64bit, and Windows XP (with Qt 4.8)
       - the printer: tried both HP 1018, and HP Laserjet P1005
       - Qt version: tried 4.8, and 5.1 both has the same problem.

    Description

      I'm trying to print an Arabic text to PDF file and to a normal printer using QPrinter. I face two different problems.

      First, when printing to PDF, text appears as if cracked; with spaces between characters (letters) that should be there.

      Second, when printing to a normal printer the text appears correct, but with [B]wrong[/B] text alignment !

      printing code:

      [CODE]void Widget::printDocument(QPainter &painter, QPrinter &printer)

      { qint32 margin = 40 ; QRect rct = printer.paperRect().adjusted(margin, margin, -margin, -margin) ; painter.drawRect(rct) ; QTextOption toption ; toption.setTextDirection(Qt::RightToLeft) ; QFont fontTitle("Arial", 36) ; fontTitle.setBold(true); painter.setFont(fontTitle); QString title = ui->leTitle->text().trimmed() ; toption.setAlignment(Qt::AlignTop|Qt::AlignHCenter); painter.drawText(rct.adjusted(0, 10, 0, 0), title, toption); QFont fontText("Arial", 28) ; painter.setFont(fontText) ; QString text = ui->teText->toPlainText() ; toption.setAlignment(Qt::AlignLeft|Qt::AlignHCenter); painter.drawText(rct.adjusted(0, 10+painter.fontMetrics().height()*4, 0, 0), text, toption); }

      void Widget::on_pbPDF_clicked()

      { QString fileName = QFileDialog::getSaveFileName(this, QString(), QString(), QString("*.pdf(*.pdf)")) ; if(fileName.isEmpty()) return ; QPrinter printer ; printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); QPainter painter(&printer) ; printDocument(painter, printer) ; painter.end() ; QDesktopServices::openUrl(QUrl(fileName)) ; }

      [/CODE]

      attached a sample qt project that shows the problem. and the resulting pdf and how the resulting printed to a normal printer looks like .

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              laknoll Lars Knoll
              ahmedb Ahmed Bedeer
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes