Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ArabicText in OpenGl (without QTranslator)
Forum Updated to NodeBB v4.3 + New Features

ArabicText in OpenGl (without QTranslator)

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 742 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StefanK
    wrote on last edited by tekojo
    #1

    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

    S 1 Reply Last reply
    0
    • S StefanK

      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

      S Offline
      S Offline
      StefanK
      wrote on last edited by
      #2

      Can anybody PLEASE compile and start these code on another computer - actually that would be helpfull too.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved