Skip to content

Commit 32ea436

Browse files
authored
fix: added link frames that don't start on the first line (#368)
1 parent 572a6c1 commit 32ea436

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Source/Internal/Text/PDFAttributedTextObject.swift

+15-3
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,24 @@ internal class PDFAttributedTextObject: PDFRenderObject {
197197
height: ascent + descent + leading)
198198
lineMetrics.append((line: line, bounds: lineBounds, range: CTLineGetStringRange(line)))
199199
}
200+
200201
for link in links {
202+
guard let url = URL(string: link.url) else {
203+
continue
204+
}
205+
206+
var found = false
201207
for metric in lineMetrics {
202-
guard let intersection = NSRange(location: metric.range.location, length: metric.range.length).intersection(link.range),
203-
let url = URL(string: link.url) else {
204-
break
208+
guard let intersection = NSRange(location: metric.range.location, length: metric.range.length).intersection(link.range) else {
209+
if found {
210+
break
211+
} else {
212+
continue
213+
}
205214
}
215+
216+
found = true
217+
206218
let startOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location, nil)
207219
let endOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location + intersection.length, nil)
208220

0 commit comments

Comments
 (0)