Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link frames that don't start on the first line #368

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading