Re: Drawing boxes around each digit entered in UITextField (Number Pad)
Re: Drawing boxes around each digit entered in UITextField (Number Pad)
- Subject: Re: Drawing boxes around each digit entered in UITextField (Number Pad)
- From: Quincey Morris <email@hidden>
- Date: Sun, 10 Feb 2019 09:22:21 -0800
On Feb 9, 2019, at 12:36 , Devarshi Kulshreshtha <email@hidden>
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 (email@hidden)
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:
This email sent to email@hidden