CTFramesetter 正在反转文本字符串的行序

问题描述

我有一个自由形式的评论部分,由于篇幅原因,有时需要滚动到第二个 PDF 页面。当我使用以下代码在第一页上绘制字符串的第一部分时,线条以正确的顺序绘制:

let generalCommentText = NSAttributedString(string: generalComments!,attributes: textAttributesRegular10)      
let generalCommentTextRect = CGRect(x: catCurrentX,y: catCurrentY+15,width: 550,height: 50)
generalCommentText.draw(in: generalCommentTextRect)

enter image description here

我正在使用 CTFramesetter 来确定适合第一页可用空间的字符串长度。当我用 CTFramesetter 绘制这些注释时,行顺序是相反的:

let generalCommentText = NSAttributedString(string: generalComments!,attributes: textAttributesRegular10)
let commentRect = CGRect(x: catCurrentX,y:catCurrentY+15,height: 50)
let path = CGMutablePath()
path.addRect(commentRect)
let framesetter = CTFramesetterCreateWithAttributedString(generalCommentText)
let ctframe = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,0),path,nil)
guard let context = UIGraphicsGetCurrentContext() else { return }

//      context.textMatrix = .identity
//      context.translateBy(x: 0,y: 0)
//      context.scaleBy(x: 1.0,y: -1.0)
        
CTFrameDraw(ctframe,context)   

enter image description here

我尝试了三个 context.xxx 行的各种组合,但没有任何变化。我在设置 framesetter 或 ctframe 时正在做/不做的事情正在反转行顺序。 CTFramesetterCreateFrame 中有一个属性 .topToBottom 但这是认值,因此似乎不是它。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)