PDA

View Full Version : qfont character count



cic1988
24th March 2015, 11:14
Hello,

is it possible to know how many characters defined in a *.ttf file?
i have a custom font *.ttf file after loading it to qfont, would like to know how can i get the total characters in this font.

anyone ideas?

jefftee
25th March 2015, 06:36
Closest thing I see is QFontMetrics. It has QFontMetrics::inFont() method that you could perhaps use to iterate over characters you are interested in, but I don't see anything that actually returns the number of characters in a given font.

cic1988
25th March 2015, 07:54
Hello @jthomps,

that could be the last choice to do it... while if there are only around 100 characters in the font defined i need to iterate 0x0000 to 0xffff.
I dont understand why there is no explicit way to do it while hints could be found in QFontEngine(not an explicit API im using Qt 4.8)

Any better ideas? :)

jefftee
25th March 2015, 08:25
I dont understand why there is no explicit way to do it while hints could be found in QFontEngine(not an explicit API im using Qt 4.8)

Any better ideas? :)
Sorry, I don't have any other ideas and I didn't write/design any of the QFont* classes so I can't speculate why this functionality isn't provided.

Perhaps you could use a separate thread to iterate over all of the 0x0000 through 0xFFFF possibilities and cache the results so you would have to do this only once for each font, etc.

A quick google shows there are other font utilities that can do this, perhaps you could use QProcess to execute one of those utilities and consume the output to cache, etc.

Good luck in your quest for a solution.

ChrisW67
25th March 2015, 21:50
The function probably does not exist for the simple reason nobody saw a reason for needing such a thing or there is no simple measure of "number of characters". What are you trying to achieve? Ae you trying to measure the number of unicode code points coverable with the font, the number of discrete glyphs renderable with the font, or the number of glyph elements the font has to combine into final glyphs. For example, the font will render a glyph for code point 0x000E Shift Out or 0x000F Shift In but they will be the same glyph and probably not a useful character.

jefftee
25th March 2015, 22:03
@ChrisW67, you said it better than I could... :)