How do you change the letter-spacing/tracking in core text?
Asked Answered
F

1

8

This could probably also be asked as "Is kCTKernAttributeName a misnomer?"

I need to change the letter spacing/tracking of some text in iOS. (The font I'm using is a little too tight at small sizes.) There are core graphics routines that will change character spacing, but those routines don't handle Unicode. There are other core graphics routines that are defined in terms of glyphs but those seem like a world of hurt, among other things, not having the safety net of reverting back to system fonts for glyphs that don't exist in my font.

So core text seems like the way to do this and core text supports kCTKernAttributeName on CFAttributedString. I think this will do what I want, though this really isn't kerning since kerning is a generally a character-pair attribute and this (appears to be, from the docs) just a uniform adjustment to the glyph advance for all glyphs, i.e., tracking.

If anyone knows before I go down the rather painful path of converting to the core text API ...

Fleischer answered 20/4, 2011 at 16:47 Comment(0)
R
4

kCTKernAttribute name should do what you want. Setting it over a range of text adjusts the inter-glyph spacing consistently, irrespective of the specific glyphs.

I think part of the problem is that kerning seems to have been a virtual synonym of tracking (it's still just "adjust the spacing between (letters or characters) in a piece of text to be printed" in the dictionary that comes with OS X), and is now adopting just the meaning of pair kerning because of the redundancy. Probably an etymologist would be better placed to comment on that side of things...

Ringent answered 20/4, 2011 at 17:20 Comment(1)
Worked great. Thanks! Had to implement shadow color manually, but that wasn't too hard, either.Fleischer

© 2022 - 2024 — McMap. All rights reserved.