On Feb 9, 2019, at 12:36 , Devarshi Kulshreshtha <devarshi.bluec...@gmail.com> 
wrote:
> 
> Am I missing any important property in X axis from the calculation due to
> which I am unable to get properly aligned bounding box over each digit?

Yes, you’re Doing It Wrong™. :)

Glyphs are laid out along the line according to their advance widths, not their 
bounding box widths. That means the *width* of the box you draw should be the 
advance width (minus any thickness of the box border that lies outside the box 
rect, minus any spacing you want between the boxes horizontally). The *height* 
of the box should be something big enough to hold the digit (e.g. font ascent + 
font descent). The *origin offset* of the box should be a multiple of the 
advance width.

https://developer.apple.com/documentation/coretext/1511265-ctfontgetadvancesforglyphs
 
<https://developer.apple.com/documentation/coretext/1511265-ctfontgetadvancesforglyphs>

This is still going to be problematic sometimes, depending on the font. There’s 
nothing preventing glyphs from being wider than their advance width, and you 
have no control over that. Also, there’s no guarantee that all the digits have 
the same advance width (“lining numerals”), although it’s typically true of 
fonts made for use on computers. You might want to force a monospaced font for 
the text field. Also, be careful with non-Roman fonts: the conventions for 
digits might be different.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to