Skip to content

Commit 4f38347

Browse files
authored
Preferences API (#271)
1 parent bedc008 commit 4f38347

File tree

167 files changed

+17842
-8206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+17842
-8206
lines changed

.github/workflows/checks.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ env:
1313
jobs:
1414
build:
1515
name: Build
16-
runs-on: macos-11
16+
runs-on: macos-12
17+
if: ${{ !github.event.pull_request.draft }}
1718
env:
1819
scheme: ${{ 'Readium-Package' }}
19-
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
20+
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer
2021

2122
steps:
2223
- name: Checkout
@@ -38,6 +39,7 @@ jobs:
3839
lint:
3940
name: Lint
4041
runs-on: macos-11
42+
if: ${{ !github.event.pull_request.draft }}
4143
env:
4244
scripts: ${{ 'Sources/Navigator/EPUB/Scripts' }}
4345

@@ -58,6 +60,7 @@ jobs:
5860
int-dev:
5961
name: Integration (Local)
6062
runs-on: macos-11
63+
if: ${{ !github.event.pull_request.draft }}
6164
defaults:
6265
run:
6366
working-directory: TestApp
@@ -76,6 +79,7 @@ jobs:
7679
int-spm:
7780
name: Integration (Swift Package Manager)
7881
runs-on: macos-11
82+
if: ${{ !github.event.pull_request.draft }}
7983
defaults:
8084
run:
8185
working-directory: TestApp
@@ -100,6 +104,7 @@ jobs:
100104
int-carthage:
101105
name: Integration (Carthage)
102106
runs-on: macos-11
107+
if: ${{ !github.event.pull_request.draft }}
103108
defaults:
104109
run:
105110
working-directory: TestApp

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,40 @@ All notable changes to this project will be documented in this file. Take a look
1616

1717
* New `VisualNavigatorDelegate` APIs to handle keyboard events (contributed by [@lukeslu](https://github.com/readium/swift-toolkit/pull/267)).
1818
* This can be used to turn pages with the arrow keys, for example.
19+
* [Support for custom fonts with the EPUB navigator](Documentation/Guides/EPUB%20Fonts.md).
20+
* 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](Documentation/Guides/Navigator%20Preferences.md) and [migration guide](Documentation/Migration%20Guide.md).
21+
* New EPUB user preferences:
22+
* `fontWeight` - Base text font weight.
23+
* `textNormalization` - Normalize font style, weight and variants, which improves accessibility.
24+
* `imageFilter` - Filter applied to images in dark theme (darken, invert colors)
25+
* `language` - Language of the publication content.
26+
* `readingProgression` - Direction of the reading progression across resources, e.g. RTL.
27+
* `typeScale` - Scale applied to all element font sizes.
28+
* `paragraphIndent` - Text indentation for paragraphs.
29+
* `paragraphSpacing` - Vertical margins for paragraphs.
30+
* `hyphens` - Enable hyphenation.
31+
* `ligatures` - Enable ligatures in Arabic.
32+
* New PDF user preferences:
33+
* `backgroundColor` - Background color behind the document pages.
34+
* `offsetFirstPage` - Indicate if the first page should be displayed in its own spread.
35+
* `pageSpacing` - Spacing between pages in points.
36+
* `readingProgression` - Direction of the reading progression across resources, e.g. RTL.
37+
* `scrollAxis` - Scrolling direction when `scroll` is enabled.
38+
* `scroll` - Indicate if pages should be handled using scrolling instead of pagination.
39+
* `spread` - Enable dual-page mode.
40+
* `visibleScrollbar` - Indicate whether the scrollbar should be visible while scrolling.
41+
* The new `DirectionalNavigationAdapter` component helps you to turn pages with the arrows and space keyboard keys or taps on the edge of the screen.
1942

2043
### Deprecated
2144

2245
#### Streamer
2346

2447
* `PublicationServer` is deprecated. See the [the migration guide](Documentation/Migration%20Guide.md#2.5.0) to migrate the HTTP server.
2548

49+
#### Navigator
50+
51+
* The EPUB `UserSettings` component is deprecated and replaced by the new Preferences API. [Take a look at the user guide](Documentation/Guides/Navigator%20Preferences.md) and [migration guide](Documentation/Migration%20Guide.md).
52+
2653
### Changed
2754

2855
#### Navigator
Lines changed: 3 additions & 0 deletions
Loading

Documentation/Guides/EPUB Fonts.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Font families in the EPUB navigator
2+
3+
Readium allows users to customize the font family used to render a reflowable EPUB, by changing the [EPUB navigator preferences](Navigator%20Preferences.md).
4+
5+
:warning: 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.
6+
7+
## Available font families
8+
9+
iOS ships with a large collection of font families that you can use directly in the EPUB preferences. [Take a look at the Apple catalog of System Fonts](https://developer.apple.com/fonts/system-fonts/).
10+
11+
To improve readability, Readium embeds three additional font families designed for accessibility:
12+
13+
* [OpenDyslexic](https://opendyslexic.org/)
14+
* [AccessibleDfA](https://github.com/Orange-OpenSource/font-accessible-dfa), by Orange
15+
* [iA Writer Duospace](https://github.com/iaolo/iA-Fonts/tree/master/iA%20Writer%20Duospace), by iA
16+
17+
You can use all the iOS System Fonts out of the box with the EPUB navigator:
18+
19+
```swift
20+
epubNavigator.submitPreferences(EPUBPreferences(
21+
fontFamily: "Palatino"
22+
))
23+
```
24+
25+
Alternatively, extend `FontFamily` to benefit from the compiler type safety:
26+
27+
```swift
28+
extension FontFamily {
29+
public static let palatino: FontFamily = "Palatino"
30+
}
31+
32+
epubNavigator.submitPreferences(EPUBPreferences(
33+
fontFamily: .palatino
34+
))
35+
```
36+
37+
For your convenience, a number of [recommended fonts](https://readium.org/readium-css/docs/CSS09-default_fonts) are pre-declared in the `FontFamily` type: Iowan Old Style, Palatino, Athelas, Georgia, Helvetica Neue, Seravek and Arial.
38+
39+
## Setting the available font families in the user interface
40+
41+
If you build your settings user interface with the EPUB Preferences Editor, you can customize the list of available font families using `with(supportedValues:)`.
42+
43+
```swift
44+
epubPreferencesEditor.fontFamily.with(supportedValues: [
45+
nil, // A `nil` value means that the original author font will be used.
46+
.palatino,
47+
.helveticaNeue,
48+
.iaWriterDuospace,
49+
.accessibleDfA,
50+
.openDyslexic
51+
])
52+
```
53+
54+
## How to add custom font families?
55+
56+
To offer more choices to your users, you must embed and declare custom font families. Use the following steps:
57+
58+
1. Get the font files in the desired format, such as .ttf and .otf. [Google Fonts](https://fonts.google.com/) is a good source of free fonts.
59+
2. Add the files to your app target from Xcode.
60+
3. Declare new extensions for your custom font families to make them first-class citizens. This is optional but convenient.
61+
```swift
62+
extension FontFamily {
63+
public static let literata: FontFamily = "Literata"
64+
public static let atkinsonHyperlegible: FontFamily = "Atkinson Hyperlegible"
65+
}
66+
```
67+
4. Configure the EPUB navigator with a declaration of the font faces for all the additional font families.
68+
```swift
69+
let resources = Bundle.main.resourceURL!
70+
let navigator = try EPUBNavigatorViewController(
71+
publication: publication,
72+
initialLocation: locator,
73+
config: .init(
74+
fontFamilyDeclarations: [
75+
CSSFontFamilyDeclaration(
76+
fontFamily: .literata,
77+
fontFaces: [
78+
// Literata is a variable font family, so we can provide a font weight range.
79+
// https://fonts.google.com/knowledge/glossary/variable_fonts
80+
CSSFontFace(
81+
file: resources.appendingPathComponent("Literata-VariableFont_opsz,wght.ttf"),
82+
style: .normal, weight: .variable(200...900)
83+
),
84+
CSSFontFace(
85+
file: resources.appendingPathComponent("Literata-Italic-VariableFont_opsz,wght.ttf"),
86+
style: .italic, weight: .variable(200...900)
87+
)
88+
]
89+
).eraseToAnyHTMLFontFamilyDeclaration(),
90+
91+
CSSFontFamilyDeclaration(
92+
fontFamily: .atkinsonHyperlegible,
93+
fontFaces: [
94+
CSSFontFace(
95+
file: resources.appendingPathComponent("Atkinson-Hyperlegible-Regular.ttf"),
96+
style: .normal, weight: .standard(.normal)
97+
),
98+
CSSFontFace(
99+
file: resources.appendingPathComponent("Atkinson-Hyperlegible-Italic.ttf"),
100+
style: .italic, weight: .standard(.normal)
101+
),
102+
CSSFontFace(
103+
file: resources.appendingPathComponent("Atkinson-Hyperlegible-Bold.ttf"),
104+
style: .normal, weight: .standard(.bold)
105+
),
106+
CSSFontFace(
107+
file: resources.appendingPathComponent("Atkinson-Hyperlegible-BoldItalic.ttf"),
108+
style: .italic, weight: .standard(.bold)
109+
),
110+
]
111+
).eraseToAnyHTMLFontFamilyDeclaration()
112+
]
113+
),
114+
httpServer: GCDHTTPServer.shared
115+
)
116+
```
117+
118+
You are now ready to use your custom font families.
119+

0 commit comments

Comments
 (0)