I need an alternative way to print Arabic text in qt
-
I'm trying to print html web page that contains Arabic text in Qt. Everything prints fine, but the Arabic text doesn't print properly.
First i tried this
@ #include "mainwindow.h"
#include "ui_mainwindow.
#include <QtPrintSupport/QPrinter>
#include <QString>
#include <QtPrintSupport/QPrintDialog>
#include <QTextDocument>
#include <QFile>
#include <QDir>
#include <QFileDialog>
#include <QTextCodec>
#include <QtWebKitWidgets/QWebPage>
#include <QtWebKitWidgets/QWebView>
#include <QtWebKitWidgets/QWebFrame>QString htmlItem(QString Item) { QString r=""; r.append( "<td>" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Tahoma'; font-size:9pt; font-weight:600;\">"); r.append(Item); r.append("</span></p></td>"); return r; } QString htmlRow(QString MFC,QString MFT,QString D,QString N) { QString ret ="" ; ret.append("<tr>"); ret.append(htmlItem(MFC)); ret.append(htmlItem(MFT)); ret.append(htmlItem(D)); ret.append(htmlItem(N)); ret.append("</tr>"); return ret; } QString htmlTable(QString rows) { QString ret = ""; ret.append("<table border=\"1\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" align=\"center\" width=\"90%\" cellspacing=\"0\" cellpadding=\"4\">" "<tbody>"); ret.append(rows); ret.append("</tbody></table>"); return ret ; } QString htmlClientName(QString name) { QString retu="<p align=\\"center\" style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\"" "font-family:'Tahoma'; font-size:16pt; font-weight:600;\">"; retu.append(name); retu.append("</span></p>"); return retu; } QString htmlClientPage(QString Table,QString Name) { QString r = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">" "<!-- saved from url=(0045)file:///C:/Users/MG/Desktop/Untitled 1.html " "-->" "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"qrichtext\" content=\"1\"><title>QTextEdit Example</title><style " "type=\"text/css\">" "p, li { white-space: pre-wrap; }" "</style></head><body style=\" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-" "style:normal;\""; r.append(htmlClientName(Name)); r.append(htmlTable(Table)); r.append("</body></html>"); return r; } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString cD=""; cD.append(htmlRow("m","n","b","v")); cD.append(htmlRow("hgfh","n","b","gggg")); cD.append(htmlRow("m","vvvv","bbbbbbb","v")); cD.append(htmlRow("m","ssssss","b","sssssssss")); QString data = htmlClientPage(htmlTable(cD), "محمد جمال "); ui->textEdit->setText(data); #if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) QPrinter printer(QPrinter::HighResolution); QPrintDialog *dlg = new QPrintDialog(&printer, this); if (ui->textEdit->textCursor().hasSelection()) dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection); dlg->setWindowTitle(tr("Print Document")); if (dlg->exec() == QDialog::Accepted) ui->textEdit->print(&printer); delete dlg; #endif }@
The output printed file was like this http://i.imgur.com/ufpoff4.jpg
I searched for how to solve this problem and ended up with sum bugs in Qt when printing arabic text.And i tried some other Qwidgets like QwebView and QwebPage and ended up with more problems.
Now i'm asking if there is an alternative way to use Qt printing like Windows API or something else to solve this problem.
I use SDK : Qt 5.2.1 with Qt Creator 3.0.1 Operating System : Microsoft Windows 8
Edit:I need to mention that Qt prints arabic text to PDF well.
Edit:I'm pretty sure that the problem is not the encoding i searched for this problem and i found these bugs in Qt
https://bugreports.qt-project.org/browse/QTBUG-4452?page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel : i think i relate to this one
-
Hi,
Since you have a way to reproduce this reliably, you should consider opening a bug report providing that minimal example.
-
If you can wait, you should try again with 5.3, there's a lot of work currently done to Qt's printing system which might help.