CoreText 中的行距和段落对齐

发布于 2024-10-22 01:53:48 字数 284 浏览 2 评论 0原文

我正在使用 CoreText 渲染多列文本。但是,当我将第一段的第一个字母设置为比文本其余部分更大的粗体字体时,我遇到了 2 个问题(都在附图中可见):

  1. 第一行下方的间距太大(我理解这是因为第一个字符可能是 ag,y,p,q 等。

  2. 第一行下面的行现在不与下一列中的相应行对齐。

第一 关于如何克服这两个问题将不胜感激,谢谢。 在此处输入图像描述

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):

  1. 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.

  2. 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.
enter image description here

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

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

发布评论

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

评论(2

养猫人 2024-10-29 01:53:48

根据文档 kCTParagraphStyleSpecifierMaximumLineHeight 应该可以解决该问题,但不幸的是,至少在 IOS 4.3 上似乎不起作用。

CTParagraphStyleSetting theSettings[5] = 
{
    { kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), &spaceBetweenParaghraphs },
    { kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), &topSpacing },
    { kCTParagraphStyleSpecifierLineSpacing, sizeof(CGFloat), &spaceBetweenLines },
    { kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(CGFloat), &lineHeight},
    { kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(CGFloat), &lineHeight}
};

CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, 5);

公平地说,文档说它在操作系统 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.

CTParagraphStyleSetting theSettings[5] = 
{
    { kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), &spaceBetweenParaghraphs },
    { kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), &topSpacing },
    { kCTParagraphStyleSpecifierLineSpacing, sizeof(CGFloat), &spaceBetweenLines },
    { kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(CGFloat), &lineHeight},
    { kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(CGFloat), &lineHeight}
};

CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, 5);

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.

揪着可爱 2024-10-29 01:53:48

解决这个问题的唯一方法似乎是使用解决方法,即为第一列创建 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.

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