Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get the outlines points of a letter for a particular font?



  • ***************************************************************************************
    /!\ Resolved, but I'd like some feedback on how to get the outline points of a letter. /!\
    ***************************************************************************************

    Hi everyone,

    I would like to be able to retrieve the outlines points of a letter for a certain font in order to draw it the way I want.
    I started looking at the QRawFont class. In particular, the glyphIndexesForString method like this :
    auto glyphIndexes = rawFont.glyphIndexesForString( "T" );

    Then I can go through my different polygons like this:

    for ( const auto& glyphIndex : glyphIndexes ) {
      auto painterPath = rawFont.pathForGlyph( glyphIndex );
      auto polys = painterPath.toSubpathPolygons();
    
      for ( std::size_t i = 0 ; i < polys.size() ; ++i ) {
        // polys[i] -> outline point
      }
    }
    

    I can display the points to give you an idea:
    QPathPainter Example

    The problem is that to create a QRawFont you have to create it from a "physical" font file...
    I have at my disposal the list of the fonts of my system thanks to the QFontDatabase class.

    So I create a font (QFont) then I use the static method QRawFont::fromFont().
    For example :

    QFont font( "Times New Roman" );
    auto rawFont = QRawFont::fromFont( font );
    

    but the problem is that my QFont and my QRawFont are different because:
    Fetches the physical representation based on a font query. The physical font returned is the font that will be preferred by Qt in order to display text in the selected writingSystem.

    std::cout << "RawFont : " << rawFont.familyName().toStdString() << std::endl;
    std::cout << "Font : " << font.family().toStdString() << std::endl;
    
    // Result:
    // RawFont : Liberation Serif
    // Font : Times New Roman
    

    Does anyone have an idea how to get the outlines points through QFont only?



  • I think I get it. I was convinced to have this font on my computer but it was not the case so it was normal that QRawFont chose another one.
    However, if anyone knows a way other than the one I outlined above to retrieve the outline points of a letter. I'd be happy to hear about it.

    I'll get this thread resolved in a couple of days so I can get some opinions.


Log in to reply