Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Commit 268907d

Browse files
Merge pull request #138 from smartmobilefactory/issue/133
Expose font settings - closes #33
2 parents 3ee4176 + ccf1ffb commit 268907d

12 files changed

+205
-183
lines changed

Example/StoryboardExample/Base.lproj/Main.storyboard

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
33
<dependencies>
44
<deployment identifier="iOS"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
@@ -19,27 +19,35 @@
1919
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2020
<subviews>
2121
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="76c-NV-rFk">
22-
<rect key="frame" x="100" y="100" width="500" height="400"/>
22+
<rect key="frame" x="50" y="0.0" width="500" height="400"/>
2323
<connections>
2424
<segue destination="ohM-0F-lQn" kind="embed" id="GwJ-h1-STP"/>
2525
</connections>
2626
</containerView>
2727
</subviews>
2828
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
2929
<constraints>
30-
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="76c-NV-rFk" secondAttribute="bottom" constant="100" id="8t2-cj-MBZ"/>
31-
<constraint firstItem="76c-NV-rFk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="100" id="NRZ-uj-OHl"/>
30+
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="80" id="0D6-Fj-fwv"/>
31+
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="1FY-cA-fGb"/>
32+
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="76c-NV-rFk" secondAttribute="bottom" constant="200" id="8t2-cj-MBZ"/>
33+
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="N9R-fw-Ou2"/>
34+
<constraint firstItem="76c-NV-rFk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="50" id="NRZ-uj-OHl"/>
3235
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" constant="100" id="Oo2-Kp-m9H"/>
3336
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="100" id="QPp-IK-WD4"/>
34-
<constraint firstAttribute="trailing" secondItem="76c-NV-rFk" secondAttribute="trailing" id="ZS5-v1-RfB"/>
37+
<constraint firstAttribute="trailing" secondItem="76c-NV-rFk" secondAttribute="trailing" constant="50" id="ZS5-v1-RfB"/>
3538
<constraint firstItem="76c-NV-rFk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="20" id="aFJ-E1-Z7h"/>
3639
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="76c-NV-rFk" secondAttribute="bottom" constant="100" id="bTg-k8-90V"/>
40+
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="hhc-EW-4bw"/>
3741
<constraint firstAttribute="trailingMargin" secondItem="76c-NV-rFk" secondAttribute="trailing" constant="20" id="vz9-fJ-FdF"/>
3842
</constraints>
3943
<variation key="default">
4044
<mask key="constraints">
45+
<exclude reference="0D6-Fj-fwv"/>
46+
<exclude reference="1FY-cA-fGb"/>
47+
<exclude reference="Oo2-Kp-m9H"/>
4148
<exclude reference="QPp-IK-WD4"/>
4249
<exclude reference="aFJ-E1-Z7h"/>
50+
<exclude reference="hhc-EW-4bw"/>
4351
<exclude reference="vz9-fJ-FdF"/>
4452
<exclude reference="bTg-k8-90V"/>
4553
</mask>

Source/FolioReaderAudioPlayer.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class FolioReaderAudioPlayer: NSObject {
152152

153153
func play() {
154154
if book.hasAudio() {
155-
guard let currentPage = FolioReader.sharedInstance.readerCenter.currentPage else { return }
155+
guard let currentPage = FolioReader.sharedInstance.readerCenter?.currentPage else { return }
156156
currentPage.webView.js("playAudio()")
157157
} else {
158158
readCurrentSentence()
@@ -212,7 +212,7 @@ public class FolioReaderAudioPlayer: NSObject {
212212
func playPrevChapter() {
213213
stopPlayerTimer()
214214
// Wait for "currentPage" to update, then request to play audio
215-
FolioReader.sharedInstance.readerCenter.changePageToPrevious {
215+
FolioReader.sharedInstance.readerCenter?.changePageToPrevious {
216216
if self.isPlaying() {
217217
self.play()
218218
} else {
@@ -224,7 +224,7 @@ public class FolioReaderAudioPlayer: NSObject {
224224
func playNextChapter() {
225225
stopPlayerTimer()
226226
// Wait for "currentPage" to update, then request to play audio
227-
FolioReader.sharedInstance.readerCenter.changePageToNext {
227+
FolioReader.sharedInstance.readerCenter?.changePageToNext {
228228
if self.isPlaying() {
229229
self.play()
230230
}
@@ -293,7 +293,7 @@ public class FolioReaderAudioPlayer: NSObject {
293293
// get the fragment ID so we can "mark" it in the webview
294294
let textParts = textFragment!.componentsSeparatedByString("#")
295295
let fragmentID = textParts[1];
296-
FolioReader.sharedInstance.readerCenter.audioMark(href: currentHref, fragmentID: fragmentID)
296+
FolioReader.sharedInstance.readerCenter?.audioMark(href: currentHref, fragmentID: fragmentID)
297297

298298
return true
299299
}
@@ -353,18 +353,23 @@ public class FolioReaderAudioPlayer: NSObject {
353353
// MARK: TTS Sentence
354354

355355
func speakSentence() {
356-
guard let currentPage = FolioReader.sharedInstance.readerCenter.currentPage else { return }
356+
guard let
357+
readerCenter = FolioReader.sharedInstance.readerCenter,
358+
currentPage = readerCenter.currentPage else {
359+
return
360+
}
361+
357362
let sentence = currentPage.webView.js("getSentenceWithIndex('\(book.playbackActiveClass())')")
358363

359364
if sentence != nil {
360-
let chapter = FolioReader.sharedInstance.readerCenter.getCurrentChapter()
365+
let chapter = readerCenter.getCurrentChapter()
361366
let href = chapter != nil ? chapter!.href : "";
362367
playText(href, text: sentence!)
363368
} else {
364-
if FolioReader.sharedInstance.readerCenter.isLastPage() {
369+
if readerCenter.isLastPage() {
365370
stop()
366371
} else {
367-
FolioReader.sharedInstance.readerCenter.changePageToNext()
372+
readerCenter.changePageToNext()
368373
}
369374
}
370375
}
@@ -378,7 +383,7 @@ public class FolioReaderAudioPlayer: NSObject {
378383
} else {
379384
if synthesizer.speaking {
380385
stopSynthesizer(immediate: false, completion: {
381-
if let currentPage = FolioReader.sharedInstance.readerCenter.currentPage {
386+
if let currentPage = FolioReader.sharedInstance.readerCenter?.currentPage {
382387
currentPage.webView.js("resetCurrentSentenceIndex()")
383388
}
384389
self.speakSentence()
@@ -463,7 +468,7 @@ public class FolioReaderAudioPlayer: NSObject {
463468
the `currentPage` in ReaderCenter may not have updated just yet
464469
*/
465470
func getCurrentChapterName() -> String? {
466-
guard let chapter = FolioReader.sharedInstance.readerCenter.getCurrentChapter() else {
471+
guard let chapter = FolioReader.sharedInstance.readerCenter?.getCurrentChapter() else {
467472
return nil
468473
}
469474

Source/FolioReaderCenter.swift

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -358,25 +358,7 @@ public class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICo
358358
html = html?.stringByReplacingOccurrencesOfString("</head>", withString: toInject)
359359

360360
// Font class name
361-
var classes = ""
362-
let currentFontName = FolioReader.currentFontName
363-
switch currentFontName {
364-
case 0:
365-
classes = "andada"
366-
break
367-
case 1:
368-
classes = "lato"
369-
break
370-
case 2:
371-
classes = "lora"
372-
break
373-
case 3:
374-
classes = "raleway"
375-
break
376-
default:
377-
break
378-
}
379-
361+
var classes = FolioReader.currentFont.cssIdentifier
380362
classes += " "+FolioReader.currentMediaOverlayStyle.className()
381363

382364
// Night mode
@@ -385,26 +367,7 @@ public class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICo
385367
}
386368

387369
// Font Size
388-
let currentFontSize = FolioReader.currentFontSize
389-
switch currentFontSize {
390-
case 0:
391-
classes += " textSizeOne"
392-
break
393-
case 1:
394-
classes += " textSizeTwo"
395-
break
396-
case 2:
397-
classes += " textSizeThree"
398-
break
399-
case 3:
400-
classes += " textSizeFour"
401-
break
402-
case 4:
403-
classes += " textSizeFive"
404-
break
405-
default:
406-
break
407-
}
370+
classes += " \(FolioReader.currentFontSize.cssIdentifier)"
408371

409372
html = html?.stringByReplacingOccurrencesOfString("<html ", withString: "<html class=\"\(classes)\"")
410373

Source/FolioReaderContainer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public class FolioReaderContainer: UIViewController {
5959

6060
// Register custom fonts
6161
FontBlaster.blast(NSBundle.frameworkBundle())
62-
62+
6363
// Register initial defaults
6464
FolioReader.defaults.registerDefaults([
65-
kCurrentFontFamily: 0,
65+
kCurrentFontFamily: FolioReaderFont.Andada.rawValue,
6666
kNightMode: false,
6767
kCurrentFontSize: 2,
6868
kCurrentAudioRate: 1,

0 commit comments

Comments
 (0)