[Qt-interest] Qt does not provide a way to get a font's "em" size?

Nikos Chantziaras realnc at arcor.de
Thu Mar 4 16:42:37 CET 2010


Thanks for the pointers, people.  If you wonder what this is all about, 
the application uses some external routines for rendering documents, and 
those routines would like to get the em size (if available), but they 
also clearly state that the point size translated to pixels (if my 
understanding is correct, this is what QFontInfo::pixelSize() offers) 
should be used as a fall-back if it's not possible to get the em size.

This seems to work quite well, even if it's the fall-back solution, so I 
guess I can live with it :)

On 03/04/2010 05:15 PM, Dan White wrote:
> OK, a bit of digging and searching, and I think I have a clue:
> <http://www.clagnut.com/blog/348/>
> <http://www.w3schools.com/css/css_font.asp>
>
> My understanding from these two links is that the "em-size" is the default font size you set for your document.
> Example:  If you set your default font size to 20 pixels, then .75em would be 15 pixels, 2em would be 40 pixels.
>
> In Qt context, I would use pixelSize and use the "em" value as a multiplier.
>
> “Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
> Bill Waterson (Calvin&  Hobbes)
>
> ----- Nikos Chantziaras<realnc at arcor.de>  wrote:
>> AFAIK, the x-height of a font has nothing to do with the em size.  A
>> fall-back for the em size would actually be pixelSize().  But it's only
>> a fall-back.
>>
>> On 03/04/2010 04:14 PM, Dan White wrote:
>>> How about using xHeight ?
>>>
>>> <http://doc.trolltech.com/4.6/qfontmetrics.html#xHeight>
>>>
>>> “Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
>>> Bill Waterson (Calvin&   Hobbes)
>>>
>>> ----- Nikos Chantziaras<realnc at arcor.de>   wrote:
>>>> I need to get the "em" size of fonts.  This is a design property of
>>>> scalable fonts.  QFontInfo and QFontMetrics don't seem to offer this
>>>> information and I would have to use FreeType directly to query it
>>>> (QFont::freetypeFace()).  That's not a good solution here since the
>>>> application needs to stay cross platform and still be able to get the em
>>>> size.
>>>>
>>>> Is there any portable solution within Qt to get to that information?




More information about the Qt-interest-old mailing list