在不规则形状内渲染 CoreText

发布于 2024-10-19 18:53:58 字数 1173 浏览 6 评论 0原文

我正在寻找有关实现一个视图的指导,该视图在带有孔的多边形内渲染 NSAttributedString,包装和回流文本以适应几何形状。问题不在于 CoreText,而在于将不规则形状划分为有序的矮矩形序列的一般问题。

类似的问题尚未得到完全解答:

CoreText 处理与文本布局和显示相关的大量繁重工作,因此我忍不住怀疑我是在重新发明轮子。出于此问题的目的,请假设我可以检查适合给定矩形的子字符串,同时考虑自动换行和连字符。

编辑:从那时起,我决定只从左到右扫描绘图,以适应边界之间的情况。尽管我打破了自然单词边界,但它看起来有点随意,所以我仍然希望了解其他应用程序如何换行文本的指导。

编辑#2:现在看起来不错,因为它支持基本的自动换行并避免渲染非常短的行。我的问题一定是太模糊了。感谢您的关注。

编辑 #3: Amorya 指出 CTFramesetter 现在接受任何 CGPath

I'm looking for guidance on implementing a view that renders an NSAttributedString within a polygon with holes, wrapping and reflowing text to fit the geometry. It's not CoreText that's the issue, but the general problem of partitioning an irregular shape into an ordered sequence of squat rectangles.

Similar questions haven't been answered fully:

CoreText handles an unbelievable amount of the grunt work associated with text layout and display, so I can't help but suspect that I'm reinventing a wheel. For the purposes of this question, please assume that I can check the substring that fits within a given rectangle, taking into account word wrap and hyphenation.

Edit: I've since decided to just sweep left-to-right drawing as much as fits between boundaries. It looks a bit haphazard even though I'm breaking at natural word boundaries, so I'd still appreciate guidance on how other applications wrap text.

Edit #2: It looks decent now that it supports basic word wrap and avoids rendering very short lines. My question must have been too vague. Thanks for looking.

Edit #3: Amorya points out that CTFramesetter now accepts any CGPath.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动次打次papapa 2024-10-26 18:53:58

我写了一篇关于使用核心文本实现文本换行的博客文章:

http ://blog.amyworrall.com/post/11098565269/text-wrap-with-core-text

该功能是 iOS 4.3 和 MacOS X Lion 中的新增功能。现在,您可以首先在非矩形路径内绘制,然后传入其他路径以掩盖流(即,您环绕的孔)。

I wrote a blog post about achieving text wrap with Core Text:

http://blog.amyworrall.com/post/11098565269/text-wrap-with-core-text

The feature is new in iOS 4.3 and MacOS X Lion. You can now firstly draw inside non-rectangular paths, and secondly pass in other paths to mask the flow (i.e. be the holes you wrap around).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文