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 characters using their glyph indices

How to get characters using their glyph indices

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.6k 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.
  • A Offline
    A Offline
    az_personal
    wrote on last edited by
    #1

    Hi,

    I'm working on a GUI application that renders rich edit text to an image. The rendering itself is done by means of drawGlyphRun method of QPainter. I also have to collect some statistics over the rendered characters (using character themselves and the bounding rectangles of their glyphs).

    The problem is that I cannot find a way to calculate character(s) using its(their) glyph index. GlyphRuns for rendering are got using QTextLayout::glyphRuns method. I can get the text from richedit widget to build a map, but the problem is that the glyph indices calculated for that text (Text Glyph Indices) differ from what QTextLayout::glyphRuns gives (Richedit Glyph Indices).

    Text Glyph Indices are calculated using QRawFont::glyphIndexesForString method. The instance of QRawFont is a property of QGlyphRun object (returned by QTextLayout::glyphRuns). So it appears to me that the indices have to be the same (the order might differ). But in reality they differ for the languages when one glyph might correspont to multiple characters (Kannada, for example).

    Does anybody know how to get characters from glyph indices? I could use Richedit Glyph Indices for the calculation in this case.

    Any help is appreciated.

    Thanks!

    1 Reply Last reply
    1
    • haikuH Offline
      haikuH Offline
      haiku
      wrote on last edited by
      #2

      For anyone who comes across this post from Google, I spent some time looking into this and I don't believe it is possible. The root of the problem is that there is a many to one mapping between glyph indices and character codes. Since multiple characters can map to the same glyph it is not possible to go from glyphs to characters as there would be multiple solutions. Even if you selected the first match it would likely not give you what you need.

      One partial solution if you are obtaining your QGlyphRun from a QSGGlyphNode is to use the QSGGlyphNode::m_ownerElement protected member to get the parent QQuickText item that owns the glyph node and then extract the text from there. However since there can be multiple glyph nodes for a single QQuickText item it might be difficult to work out exactly which part of the text you are currently working with. Still its very if you just need some debug info to orient yourself.

      The correct solution would be to use the fonts cmap table to extract the mapping characters but as far as I see Qt provides no logic for doing this so it would be up to you to parse the cmap table and deal with the complexities there.

      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