gpt4 book ai didi

ios - 为什么使用 CoreText 渲染文本布局,文本可以显示在 1px 宽度的路径中?

转载 作者:可可西里 更新时间:2023-11-01 05:56:48 25 4
gpt4 key购买 nike

我写了一段代码,使用 CoreText 布局一些文本,如下图所示。红色矩形是文本区域,黑色矩形是图像或其他对象的空区域。我使用 kCTFrameClippingPathsAttributeName 告诉 CoreText,黑色矩形不会显示文本。

core text text layout

详细图片如下:

enter image description here

为什么有些文字会在这个位置撕裂?红色矩形和黑色矩形只有很小的面积,宽度只有1px,为什么会出现文字?

右边的红色矩形框是(533, 40, 440, 668),右边的小矩形框是(534, 98, 440, 399)

这样的代码:

CGPathRef textArea; 

// An array of clipping paths
NSMutableArray * clippingPaths = [NSMutableArray array];
for (TNPageMedium *medium in self.media) {
NSDictionary *clippingPathDict = @{(NSString *)kCTFramePathClippingPathAttributeName:(__bridge id)path};
[clippingPaths addObject:clippingPathDict];
}

NSDictionary *optionsDict = @{(NSString*)kCTFrameClippingPathsAttributeName : clippingPaths};

// create frame using texAreaPath, an optionDictionary contains clipping paths
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(pos, 0), textAreaPath, (__bridge CFDictionaryRef)(optionsDict));

// Draw Frame
CTFrameDraw(frame, context);

最佳答案

看起来您的 attributedString 缺少段落样式信息。

我猜你从 NSString 创建了 NSAttributedString,并且没有在属性字典中提供 kCTParagraphStyleAttributeName 键值。

关于ios - 为什么使用 CoreText 渲染文本布局,文本可以显示在 1px 宽度的路径中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13564245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com