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. How to get the outlines points of a letter for a particular font?

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

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 410 Views
  • 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.
  • DrAuraHxCD Offline
    DrAuraHxCD Offline
    DrAuraHxC
    wrote on last edited by DrAuraHxC
    #1

    ***************************************************************************************
    /!\ 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?

    DrAuraHxCD 1 Reply Last reply
    1
    • DrAuraHxCD DrAuraHxC

      ***************************************************************************************
      /!\ 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?

      DrAuraHxCD Offline
      DrAuraHxCD Offline
      DrAuraHxC
      wrote on last edited by DrAuraHxC
      #2

      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.

      1 Reply Last reply
      1

      • Login

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