Skip to content

Commit

Permalink
fix: added link frames that don't start on the first line (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
jseibert committed Apr 19, 2024
1 parent 572a6c1 commit 32ea436
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Source/Internal/Text/PDFAttributedTextObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,24 @@ internal class PDFAttributedTextObject: PDFRenderObject {
height: ascent + descent + leading)
lineMetrics.append((line: line, bounds: lineBounds, range: CTLineGetStringRange(line)))
}

for link in links {
guard let url = URL(string: link.url) else {
continue
}

var found = false
for metric in lineMetrics {
guard let intersection = NSRange(location: metric.range.location, length: metric.range.length).intersection(link.range),
let url = URL(string: link.url) else {
break
guard let intersection = NSRange(location: metric.range.location, length: metric.range.length).intersection(link.range) else {
if found {
break
} else {
continue
}
}

found = true

let startOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location, nil)
let endOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location + intersection.length, nil)

Expand Down

0 comments on commit 32ea436

Please sign in to comment.