Skip to content
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
37 changes: 19 additions & 18 deletions Source/Internal/Text/PDFAttributedTextObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,25 @@ internal class PDFAttributedTextObject: PDFRenderObject {
}
for link in links {
for metric in lineMetrics {
if let intersection = NSRange(location: metric.range.location,
length: metric.range.length).intersection(link.range) {
let startOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location, nil)
let endOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location + intersection.length, nil)

let linkFrame = CGRect(
x: self.frame.origin.x + startOffset,
y: metric.bounds.origin.y,
width: endOffset - startOffset,
height: metric.bounds.height)
attributes.append((attribute: .link(url: URL(string: link.url)!), frame: linkFrame))

if debug {
PDFGraphics.drawRect(in: context,
rect: linkFrame,
outline: .none,
fill: Color.red.withAlphaComponent(0.4))
}
guard let intersection = NSRange(location: metric.range.location, length: metric.range.length).intersection(link.range),
let url = URL(string: link.url) else {
break
}
let startOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location, nil)
let endOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location + intersection.length, nil)

let linkFrame = CGRect(
x: self.frame.origin.x + startOffset,
y: metric.bounds.origin.y,
width: endOffset - startOffset,
height: metric.bounds.height)
attributes.append((attribute: .link(url: url), frame: linkFrame))

if debug {
PDFGraphics.drawRect(in: context,
rect: linkFrame,
outline: .none,
fill: Color.red.withAlphaComponent(0.4))
}
}
}
Expand Down