Skip to content

Commit 800ae57

Browse files
authored
Fix documentation issues (#718)
1 parent 6567cdf commit 800ae57

File tree

7 files changed

+60
-73
lines changed

7 files changed

+60
-73
lines changed

docs/Guides/Content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This is an expensive operation, proceed with caution and cache the result if you
3737
The individual `Content` elements can be iterated through with a regular `for` loop by converting it to a sequence:
3838

3939
```swift
40-
for (element in content.sequence()) {
40+
for element in content.sequence() {
4141
// Process element
4242
}
4343
```

docs/Guides/Getting Started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ let assetRetriever = AssetRetriever(
112112
httpClient: httpClient
113113
)
114114
let publicationOpener = PublicationOpener(
115-
publicationParser: DefaultPublicationParser(
115+
parser: DefaultPublicationParser(
116116
httpClient: httpClient,
117117
assetRetriever: assetRetriever,
118118
pdfFactory: DefaultPDFDocumentFactory()

docs/Guides/Navigator/EPUB Fonts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Font families in the EPUB navigator
22

3-
Readium allows users to customize the font family used to render a reflowable EPUB, by changing the [EPUB navigator preferences](Navigator%20Preferences.md).
3+
Readium allows users to customize the font family used to render a reflowable EPUB, by changing the [EPUB navigator preferences](Preferences.md).
44

55
> [!NOTE]
66
> You cannot change the default font family of a fixed-layout EPUB (with zoomable pages), as it is similar to a PDF or a comic book.

docs/Guides/Navigator/Input.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Here's an example of a simple `InputObserving` implementation that logs all key
1212
navigator.addObserver(InputObserver())
1313

1414
@MainActor final class InputObserver: InputObserving {
15-
func didReceive(_ event: PointerEvent) -> Bool {
15+
func didReceive(_ event: PointerEvent) async -> Bool {
1616
print("Received pointer event: \(event)")
1717
return false
1818
}
19-
20-
func didReceive(_ event: KeyEvent) -> Bool {
19+
20+
func didReceive(_ event: KeyEvent) async -> Bool {
2121
print("Received key event: \(event)")
2222
return false
2323
}
@@ -47,7 +47,7 @@ navigator.addObserver(.click(modifiers: [.shift]) { event in
4747

4848
## Observing keyboard events
4949

50-
Similarly, the `KeyboardObserver` implementation provides an easy method to intercept keyboard events.
50+
Similarly, the `KeyObserver` implementation provides an easy method to intercept keyboard events.
5151

5252
```swift
5353
navigator.addObserver(.key { event in

docs/Guides/Navigator/Navigator.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ class MyNavigatorDelegate: NavigatorDelegate {
111111

112112
override func navigator(_ navigator: Navigator, locationDidChange locator: Locator) {
113113
if let position = locator.locations.position {
114-
print("At position \(position) on \(publication.positions.count)")
114+
print("At position \(position)")
115115
}
116116
if let progression = locator.locations.progression {
117-
return "Progression in the current resource: \(progression)%"
117+
print("Progression in the current resource: \(progression.formatted(.percent))")
118118
}
119119
if let totalProgression = locator.locations.totalProgression {
120-
return "Total progression in the publication: \(progression)%"
120+
print("Total progression in the publication: \(totalProgression.formatted(.percent))")
121121
}
122122

123123
// Save the position in your bookshelf database
@@ -151,8 +151,8 @@ To display a percentage-based progression slider, use the `locations.totalProgre
151151
Given a progression from 0 to 1, you can obtain a `Locator` object from the `Publication`. This can be used to navigate to a specific percentage within the publication.
152152

153153
```swift
154-
if let locator = publication.locate(progression: 0.5) {
155-
navigator.go(to: locator)
154+
if let locator = await publication.locate(progression: 0.5) {
155+
await navigator.go(to: locator)
156156
}
157157
```
158158

@@ -161,9 +161,7 @@ if let locator = publication.locate(progression: 0.5) {
161161
> [!NOTE]
162162
> Readium does not have the concept of pages, as they are not useful when dealing with reflowable publications across different screen sizes. Instead, we use [**positions**](https://readium.org/architecture/models/locators/positions/) which remain stable even when the user changes the font size or device.
163163
164-
Not all Navigators provide positions, but most `VisualNavigator` implementations do. Verify if `publication.positions` is not empty to determine if it is supported.
165-
166-
To find the total positions in the publication, use `publication.positions.count`. You can get the current position with `navigator.currentLocation?.locations.position`.
164+
Not all Navigators provide positions, but most `VisualNavigator` implementations do. To find the total positions in the publication, use `try await publication.positions().get().count`. You can get the current position with `navigator.currentLocation?.locations.position`.
167165

168166
## Navigating with edge taps and keyboard arrows
169167

docs/Guides/Readium LCP.md

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,25 @@ Users need to import a License Document into your application to download the pr
224224
The `LCPService` offers an API to retrieve the full publication from an LCPL on the filesystem.
225225

226226
```swift
227-
let acquisition = lcpService.acquirePublication(
228-
from: lcplURL,
227+
let result = await lcpService.acquirePublication(
228+
from: .file(lcplURL),
229229
onProgress: { progress in
230230
switch progress {
231231
case .indefinite:
232232
// Display an activity indicator.
233233
case .percent(let percent):
234234
// Display a progress bar with percent from 0 to 1.
235235
}
236-
},
237-
completion: { result in
238-
switch result {
239-
case let .success(publication):
240-
// Import the `publication.localURL` file as any publication.
241-
case let .failure(error):
242-
// Display the error message
243-
case .cancelled:
244-
// The acquisition was cancelled before completion.
245-
}
246236
}
247237
)
248-
```
249238

250-
If the user wants to cancel the download, call `cancel()` on the object returned by `LCPService.acquirePublication()`.
239+
switch result {
240+
case let .success(publication):
241+
// Import the `publication.localURL` file as any publication.
242+
case let .failure(error):
243+
// Display the error message.
244+
}
245+
```
251246

252247
After the download is completed, import the `publication.localURL` file into the bookshelf like any other publication file.
253248

@@ -308,7 +303,7 @@ The `allowUserInteraction` and `sender` arguments are forwarded to the `LCPAuthe
308303
When importing the publication to the bookshelf, set `allowUserInteraction` to `false` as you don't need the passphrase for accessing the publication metadata and cover. If you intend to present the publication using a Navigator, set `allowUserInteraction` to `true` as decryption will be required.
309304

310305
> [!TIP]
311-
> To check if a publication is protected with LCP before opening it, you can use `LCPService.isLCPProtected()`.
306+
> To check if an asset is protected with LCP before opening it, you can use `asset.format.conformsTo(.lcp)`.
312307
313308
### Using the opened `Publication`
314309

@@ -370,36 +365,30 @@ An LCP License Document contains metadata such as its expiration date, the remai
370365
Use the `LCPService` to retrieve the `LCPLicense` instance for a publication.
371366

372367
```swift
373-
lcpService.retrieveLicense(
374-
from: publicationURL,
368+
let result = await lcpService.retrieveLicense(
369+
from: asset,
375370
authentication: LCPDialogAuthentication(),
376371
allowUserInteraction: true,
377372
sender: hostViewController
378-
) { result in
379-
switch result {
380-
case .success(let lcpLicense):
381-
if let lcpLicense = lcpLicense {
382-
if let user = lcpLicense.license.user.name {
383-
print("The publication was acquired by \(user)")
384-
}
385-
if let endDate = lcpLicense.license.rights.end {
386-
print("The loan expires on \(endDate)")
387-
}
388-
if let copyLeft = lcpLicense.charactersToCopyLeft {
389-
print("You can copy up to \(copyLeft) characters remaining.")
390-
}
391-
} else {
392-
// The file was not protected by LCP.
393-
}
394-
case .failure(let error):
395-
// Display the error.
396-
case .cancelled:
397-
// The operation was cancelled.
373+
)
374+
375+
switch result {
376+
case .success(let lcpLicense):
377+
if let user = lcpLicense.license.user.name {
378+
print("The publication was acquired by \(user)")
398379
}
380+
if let endDate = lcpLicense.license.rights.end {
381+
print("The loan expires on \(endDate)")
382+
}
383+
if let copyLeft = await lcpLicense.charactersToCopyLeft() {
384+
print("You can copy up to \(copyLeft) characters remaining.")
385+
}
386+
case .failure(let error):
387+
// Display the error.
399388
}
400389
```
401390

402-
If you have already opened a `Publication` with the `Streamer`, you can directly obtain the `LCPLicense` using `publication.lcpLicense`.
391+
If you have already opened a `Publication` with the `PublicationOpener`, you can directly obtain the `LCPLicense` using `publication.lcpLicense`.
403392

404393
## Managing a loan
405394

@@ -410,12 +399,12 @@ Readium LCP allows borrowing publications for a specific period. Use the `LCPLic
410399
Some loans can be returned before the end date. You can confirm this by using `lcpLicense.canReturnPublication`. To return the publication, execute:
411400

412401
```swift
413-
lcpLicense.returnPublication { error in
414-
if let error = error {
415-
// Present the error.
416-
} else {
417-
// The publication was returned.
418-
}
402+
let result = await lcpLicense.returnPublication()
403+
switch result {
404+
case .success:
405+
// The publication was returned.
406+
case .failure(let error):
407+
// Present the error.
419408
}
420409
```
421410

@@ -431,17 +420,17 @@ Readium LCP supports [two types of renewal interactions](https://readium.org/lcp
431420
You need to support both interactions by implementing the `LCPRenewDelegate` protocol. A default implementation is available with `LCPDefaultRenewDelegate`.
432421

433422
```swift
434-
lcpLicense.renewLoan(
423+
let result = await lcpLicense.renewLoan(
435424
with: LCPDefaultRenewDelegate(
436425
presentingViewController: hostViewController
437426
)
438-
) { result in
439-
switch result {
440-
case .success, .cancelled:
441-
// The publication was renewed.
442-
case let .failure(error):
443-
// Display the error.
444-
}
427+
)
428+
429+
switch result {
430+
case .success:
431+
// The publication was renewed.
432+
case let .failure(error):
433+
// Display the error.
445434
}
446435
```
447436

@@ -453,7 +442,7 @@ For an example, [take a look at the Test App](https://github.com/readium/swift-t
453442

454443
## Using the SwiftUI LCP Authentication dialog
455444

456-
If your application is built using SwiftUI, you cannot use `LCPAuthenticationDialog` because it requires a UIKit view controller as its host. Instead, use an `LCPObservableAuthentication` combined with our SwiftUI `LCPDialog` presented as a sheet.
445+
If your application is built using SwiftUI, you cannot use `LCPDialogAuthentication` because it requires a UIKit view controller as its host. Instead, use an `LCPObservableAuthentication` combined with our SwiftUI `LCPDialog` presented as a sheet.
457446

458447
```swift
459448
@main

docs/Migration Guide.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,16 @@ let navigator = try EPUBNavigatorViewController(
435435

436436
### Upgrading to the new Preferences API
437437

438-
The 2.5.0 release introduces a brand new user preferences API for configuring the EPUB and PDF Navigators. This new API is easier and safer to use. To learn how to integrate it in your app, [please refer to the user guide](Guides/Navigator%20Preferences.md).
438+
The 2.5.0 release introduces a brand new user preferences API for configuring the EPUB and PDF Navigators. This new API is easier and safer to use. To learn how to integrate it in your app, [please refer to the user guide](Guides/Navigator/Preferences.md).
439439

440440
If you integrated the EPUB navigator from a previous version, follow these steps to migrate:
441441

442-
1. Get familiar with [the concepts of this new API](Guides/Navigator%20Preferences.md#overview).
442+
1. Get familiar with [the concepts of this new API](Guides/Navigator/Preferences.md#overview).
443443
2. Migrate the local HTTP server from your app, [as explained in the previous section](#migrating-the-http-server).
444-
3. Adapt your user settings interface to the new API using preferences editors. The [Test App](https://github.com/readium/swift-toolkit/blob/2.5.0/TestApp/Sources/Reader/Common/Preferences/UserPreferences.swift) and the [user guide](Guides/Navigator%20Preferences.md#build-a-user-settings-interface) contain examples using SwiftUI.
445-
4. [Handle the persistence of the user preferences](Guides/Navigator%20Preferences.md#save-and-restore-the-user-preferences). The settings are not stored in the User Defaults by the toolkit anymore. Instead, you are responsible for persisting and restoring the user preferences as you see fit (e.g. as a JSON file).
444+
3. Adapt your user settings interface to the new API using preferences editors. The [Test App](https://github.com/readium/swift-toolkit/blob/2.5.0/TestApp/Sources/Reader/Common/Preferences/UserPreferences.swift) and the [user guide](Guides/Navigator/Preferences.md#build-a-user-settings-interface) contain examples using SwiftUI.
445+
4. [Handle the persistence of the user preferences](Guides/Navigator/Preferences.md#save-and-restore-the-user-preferences). The settings are not stored in the User Defaults by the toolkit anymore. Instead, you are responsible for persisting and restoring the user preferences as you see fit (e.g. as a JSON file).
446446
* If you want to migrate the legacy EPUB settings, you can use the helper `EPUBPreferences.fromLegacyPreferences()` which will create a new `EPUBPreferences` object after translating the existing user settings.
447-
5. Make sure you [restore the stored user preferences](Guides/Navigator%20Preferences.md#setting-the-initial-navigator-preferences-and-app-defaults) when initializing the EPUB navigator.
447+
5. Make sure you [restore the stored user preferences](Guides/Navigator/Preferences.md#setting-the-initial-navigator-preferences-and-app-defaults) when initializing the EPUB navigator.
448448

449449
Please refer to the following table for the correspondence between legacy settings (from `UserSettings`) and new ones (`EPUBPreferences`).
450450

0 commit comments

Comments
 (0)