@@ -294,7 +294,7 @@ open class PDFNavigatorViewController: UIViewController, VisualNavigator, Select
294
294
if let locator = locator {
295
295
await go ( to: locator, isJump: false )
296
296
} else if let link = publication. readingOrder. first {
297
- await go ( to: link, pageNumber: 0 , isJump: false )
297
+ await go ( to: link. url ( ) , pageNumber: 0 , isJump: false )
298
298
} else {
299
299
log ( . error, " No initial location and empty reading order " )
300
300
}
@@ -384,25 +384,24 @@ open class PDFNavigatorViewController: UIViewController, VisualNavigator, Select
384
384
private func go( to locator: Locator , isJump: Bool ) async -> Bool {
385
385
let locator = publication. normalizeLocator ( locator)
386
386
387
- guard let link = findLink ( at: locator) else {
387
+ let href : AnyURL ? = {
388
+ if isPDFFile {
389
+ return publication. readingOrder. first? . url ( )
390
+ } else {
391
+ return publication. readingOrder. firstWithHREF ( locator. href) ? . url ( )
392
+ }
393
+ } ( )
394
+ guard let href = href else {
388
395
return false
389
396
}
390
397
391
398
return await go (
392
- to: link ,
399
+ to: href ,
393
400
pageNumber: pageNumber ( for: locator) ,
394
401
isJump: isJump
395
402
)
396
403
}
397
404
398
- private func findLink( at locator: Locator ) -> Link ? {
399
- if isPDFFile {
400
- return publication. readingOrder. first
401
- } else {
402
- return publication. readingOrder. firstWithHREF ( locator. href)
403
- }
404
- }
405
-
406
405
/// Historically, the reading order of a standalone PDF file contained a
407
406
/// single link with the HREF `"/<asset filename>"`. This was fragile if
408
407
/// the asset named changed, or was different on other devices.
@@ -415,20 +414,23 @@ open class PDFNavigatorViewController: UIViewController, VisualNavigator, Select
415
414
publication. readingOrder. count == 1 && publication. readingOrder [ 0 ] . href == " publication.pdf "
416
415
417
416
@discardableResult
418
- private func go( to link: Link , pageNumber: Int ? , isJump: Bool ) async -> Bool {
419
- guard let pdfView = pdfView, let index = publication. readingOrder. firstIndex ( of: link) else {
417
+ private func go< HREF: URLConvertible > ( to href: HREF , pageNumber: Int ? , isJump: Bool ) async -> Bool {
418
+ guard
419
+ let pdfView = pdfView,
420
+ let url = publicationBaseURL. resolve ( href) ,
421
+ let index = publication. readingOrder. firstIndexWithHREF ( href)
422
+ else {
420
423
return false
421
424
}
422
425
423
426
if currentResourceIndex != index {
424
- let url = link. url ( relativeTo: publicationBaseURL)
425
427
guard let document = PDFDocument ( url: url. url) else {
426
- log ( . error, " Can't open PDF document at \( link ) " )
428
+ log ( . error, " Can't open PDF document at \( url ) " )
427
429
return false
428
430
}
429
431
430
432
currentResourceIndex = index
431
- documentHolder. set ( document, at: link . url ( ) )
433
+ documentHolder. set ( document, at: href )
432
434
pdfView. document = document
433
435
updateScaleFactors ( )
434
436
}
@@ -613,7 +615,11 @@ open class PDFNavigatorViewController: UIViewController, VisualNavigator, Select
613
615
}
614
616
615
617
public func go( to link: Link , options: NavigatorGoOptions ) async -> Bool {
616
- await go ( to: link, pageNumber: nil , isJump: true )
618
+ guard let locator = await publication. locate ( link) else {
619
+ return false
620
+ }
621
+
622
+ return await go ( to: locator, options: options)
617
623
}
618
624
619
625
public func goForward( options: NavigatorGoOptions ) async -> Bool {
0 commit comments