ArabicText in OpenGl (without QTranslator)
-
Hello,
I have a question regarding using QRawFont to create a texture representing a defined arabic string. In my tests I define a utf8 string, create a QRawFont object and try to get the correct glyphs. Actually I get some arabic glyphs but they are not the expected one. Has anybody an idea with this sample code is not working correctly!?!?QString StdWStringToQString(const std::wstring &str) { #ifdef _MSC_VER return QString::fromUtf16((const ushort *)str.c_str()); #else return QString::fromStdWString(str); #endif } int main(int argc, char *argv[]) { QApplication a(argc, argv); // set encoding for the project //QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf-8")); //QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8")); QGlyphRun glyphs; QVector<quint32> glyphIndexes; QVector<QPointF> positions; // this string I want to have as glyphs const std::wstring sample = L"رأس المستشعر لا يدعم "; QString arabic = StdWStringToQString(sample); QRawFont rawFont; rawFont.loadFromFile("c:\\Windows\\Fonts\\ARIAL.ttf", 72, QFont::PreferFullHinting); glyphIndexes = rawFont.glyphIndexesForString(arabic); for (int i = 0; i < glyphIndexes.count(); i++) positions.append(QPointF(10+i*30, 10)); glyphs.setRawFont(rawFont); glyphs.setGlyphIndexes(glyphIndexes); glyphs.setPositions(positions); QImage drawGlyphs(400, 200, QImage::Format_ARGB32); drawGlyphs.fill(Qt::white); QPainter p(&drawGlyphs); p.setPen(Qt::black); p.drawGlyphRun(QPointF(10, 10), glyphs); QGraphicsScene *pScene = new QGraphicsScene(0, 0, 400, 200); QGraphicsView *pView = new QGraphicsView(pScene); pScene->addPixmap(QPixmap::fromImage(drawGlyphs)); pView->show(); return a.exec(); }
For testing I put the arabic string as the QtWindow title and it was shown correctly - so I guess I have everything on my system to display these signs. Actually I have no idea whats wrong - my understanding of the arabic language is not very good. Maybe its an encoding problem, maybe its a layout problem, maybe its a problem with my system settings or maybe its a bug in my qt version!? Anybody an idea!?
Environment: Window7, VS2010, SystemLanguage = En, Sources encoded in utf-8, QTVersion 4.8.3
-
Can anybody PLEASE compile and start these code on another computer - actually that would be helpfull too.