将 NSAttributedString 绘制到非矩形 CGPath 中?
我在 iOS 3.2 应用程序 (iPad) 中生成了一个相当复杂的 NSAttributedString,包括 CTParagraphStyleSetting 类型的格式化选项,特别是 kCTParagraphStyleSpecifierMinimumLineHeight 和 kCTParagraphStyleSpecifierParagraphSpacing 的值。
当我尝试将此属性字符串绘制到非矩形 CGPath 中时,Core Text 会绘制它,但没有定义行间距;也就是说,所有文本都出现在没有行距的段落中。不用说,它看起来不像 CGPath 是简单地使用对 CGPathAddRect() 的一次调用来定义的那样漂亮!
是否有任何我可以指定的设置(到我的 CTFramesetterRef 或与罪魁祸首 CGPath 关联的 CTFrameRef)以避免丢失所有行高信息?
谢谢!
I generate a rather complex NSAttributedString in my iOS 3.2 application (iPad), including formatting options of type CTParagraphStyleSetting, in particular with values for kCTParagraphStyleSpecifierMinimumLineHeight and kCTParagraphStyleSpecifierParagraphSpacing.
When I try to draw this attributed string into a non-rectangular CGPath, Core Text draws it but without the line spacing defined; that is, all text appears crammed in paragraphs without line spacing. Needless to say, it does not look as pretty as if the CGPath was simply defined using a single call to CGPathAddRect()!
Is there any setting I can specify (to my CTFramesetterRef or to the CTFrameRef associated to the culprit CGPath) to avoid losing all line height information?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CoreText 编程指南指示仅允许使用矩形 CGPath:
http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Overview/Overview.html#//apple_ref/文档/uid/TP40005533-CH3-SW1
The CoreText programming guide indicates that only a rectangular CGPath is allowed:
http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Overview/Overview.html#//apple_ref/doc/uid/TP40005533-CH3-SW1
从 iOS 4.2 开始,Core Text 接受非矩形路径。请参阅 CTFramesetterCreateFrame 的文档:
http://developer.apple.com/library/iOS/documentation/Carbon/Reference/CTFramesetterRef/Reference/reference.html#//apple_ref/c/func/CTFramesetterCreateFrame
对于示例,请参阅“在非矩形区域中显示文本”:
https://developer.apple.com/library/iOS/documentation/StringsTextFonts/Conceptual/CoreText_Programming/LayoutOperations/LayoutOperations.html#//apple_ref/doc/uid/TP40005533 -CH12-SW9
As of iOS 4.2, Core Text accepts non-rectangular paths. See the docs for CTFramesetterCreateFrame:
http://developer.apple.com/library/iOS/documentation/Carbon/Reference/CTFramesetterRef/Reference/reference.html#//apple_ref/c/func/CTFramesetterCreateFrame
For a sample, see "Displaying Text in a Nonrectangular Region":
https://developer.apple.com/library/iOS/documentation/StringsTextFonts/Conceptual/CoreText_Programming/LayoutOperations/LayoutOperations.html#//apple_ref/doc/uid/TP40005533-CH12-SW9