CoreText 中的行距和段落对齐
我正在使用 CoreText 渲染多列文本。但是,当我将第一段的第一个字母设置为比文本其余部分更大的粗体字体时,我遇到了 2 个问题(都在附图中可见):
第一行下方的间距太大(我理解这是因为第一个字符可能是 ag,y,p,q 等。
第一行下面的行现在不与下一列中的相应行对齐。
第一 关于如何克服这两个问题将不胜感激,谢谢。
I am using CoreText to render multiple columns of text. However, when I set the first letter of the 1st paragraph to a bold, larger font than the rest of the text, I incur 2 issues (both visible in the attached image):
The spacing underneath the first line is too big (I understand that this is because the 1st character could be a g,y,p,q etc.
Lines below the first line now do not line up with corresponding lines in the next column.
Any advice on how to overcome these 2 issues would be greatly appreciated, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据文档 kCTParagraphStyleSpecifierMaximumLineHeight 应该可以解决该问题,但不幸的是,至少在 IOS 4.3 上似乎不起作用。
公平地说,文档说它在操作系统 v10.5 及更高版本中可用。
kCTParagraphStyleSpecifierMaximumLineHeight
:框架中任何行将占据的最大高度,无论字体大小或任何附加图形的大小如何。超过此高度的字形和图形将与相邻的线重叠。最大高度为 0 意味着没有行高限制。该值始终为非负数。
类型:CGFloat。
默认值:0.0。
应用:CTFramesetter。
适用于 Mac OS X v10.5 及更高版本。
在 CTParagraphStyle.h 中声明。
According to the documentation kCTParagraphStyleSpecifierMaximumLineHeight should have solved the problem, but unfortunately does not seem to work at least on IOS 4.3.
To be fair documentation says it's available in OS v10.5 and later.
kCTParagraphStyleSpecifierMaximumLineHeight
:The maximum height that any line in the frame will occupy, regardless of the font size or size of any attached graphic. Glyphs and graphics exceeding this height will overlap neighboring lines. A maximum height of 0 implies no line height limit. This value is always nonnegative.
Type: CGFloat.
Default: 0.0.
Application: CTFramesetter.
Available in Mac OS X v10.5 and later.
Declared in CTParagraphStyle.h.
解决这个问题的唯一方法似乎是使用解决方法,即为第一列创建 3 个框架,1 个用于 W,1 个用于第一句的其余部分,1 个用于第一列的其余部分。
It seems the only way to fix this is with a workaround, which is to create 3 frames for the first column,1 for the W, 1 for the rest of the first sentence and 1 for the rest of the first column.