如何更改核心文本中的字母间距/字距?
这也可能被问为“kCTKernAttributeName 是用词不当吗?”
我需要更改 iOS 中某些文本的字母间距/字距。 (我使用的字体在小尺寸下有点太紧。)有一些核心图形例程可以更改字符间距,但这些例程不处理 Unicode。还有其他核心图形例程是根据字形定义的,但这些例程似乎是一个充满伤害的世界,除其他外,没有安全网来恢复我的字体中不存在的字形的系统字体。
因此,核心文本似乎是执行此操作的方法,并且核心文本支持 CFAttributedString 上的 kCTKernAttributeName。我认为这会做我想要的,尽管这实际上不是字距调整,因为字距调整通常是一个字符对属性,并且这(从文档看来)只是对所有字形的字形前进的统一调整,即, 追踪。
在我走上转换为核心文本 API 的相当痛苦的道路之前,如果有人知道的话......
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 ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
kCTKernAttribute 名称应该满足您的要求。将其设置在一系列文本上可以一致地调整字形间距,而不管特定的字形如何。
我认为部分问题在于字距调整似乎是跟踪的虚拟同义词(它仍然只是在 OS X 附带的字典中“调整要打印的一段文本(字母或字符)之间的间距”) ,由于冗余,现在仅采用对字距调整的含义。词源学家可能更适合对事物的这一方面进行评论......
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...