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

Commit

Permalink
Merge pull request #138 from smartmobilefactory/issue/133
Browse files Browse the repository at this point in the history
Expose font settings - closes #33
  • Loading branch information
hebertialmeida committed Sep 16, 2016
2 parents 3ee4176 + ccf1ffb commit 268907d
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 183 deletions.
18 changes: 13 additions & 5 deletions Example/StoryboardExample/Base.lproj/Main.storyboard
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<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">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
Expand All @@ -19,27 +19,35 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="76c-NV-rFk">
<rect key="frame" x="100" y="100" width="500" height="400"/>
<rect key="frame" x="50" y="0.0" width="500" height="400"/>
<connections>
<segue destination="ohM-0F-lQn" kind="embed" id="GwJ-h1-STP"/>
</connections>
</containerView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="76c-NV-rFk" secondAttribute="bottom" constant="100" id="8t2-cj-MBZ"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="100" id="NRZ-uj-OHl"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="80" id="0D6-Fj-fwv"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="1FY-cA-fGb"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="76c-NV-rFk" secondAttribute="bottom" constant="200" id="8t2-cj-MBZ"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="N9R-fw-Ou2"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="50" id="NRZ-uj-OHl"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" constant="100" id="Oo2-Kp-m9H"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="100" id="QPp-IK-WD4"/>
<constraint firstAttribute="trailing" secondItem="76c-NV-rFk" secondAttribute="trailing" id="ZS5-v1-RfB"/>
<constraint firstAttribute="trailing" secondItem="76c-NV-rFk" secondAttribute="trailing" constant="50" id="ZS5-v1-RfB"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="20" id="aFJ-E1-Z7h"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="76c-NV-rFk" secondAttribute="bottom" constant="100" id="bTg-k8-90V"/>
<constraint firstItem="76c-NV-rFk" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="hhc-EW-4bw"/>
<constraint firstAttribute="trailingMargin" secondItem="76c-NV-rFk" secondAttribute="trailing" constant="20" id="vz9-fJ-FdF"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="0D6-Fj-fwv"/>
<exclude reference="1FY-cA-fGb"/>
<exclude reference="Oo2-Kp-m9H"/>
<exclude reference="QPp-IK-WD4"/>
<exclude reference="aFJ-E1-Z7h"/>
<exclude reference="hhc-EW-4bw"/>
<exclude reference="vz9-fJ-FdF"/>
<exclude reference="bTg-k8-90V"/>
</mask>
Expand Down
25 changes: 15 additions & 10 deletions Source/FolioReaderAudioPlayer.swift
Expand Up @@ -152,7 +152,7 @@ public class FolioReaderAudioPlayer: NSObject {

func play() {
if book.hasAudio() {
guard let currentPage = FolioReader.sharedInstance.readerCenter.currentPage else { return }
guard let currentPage = FolioReader.sharedInstance.readerCenter?.currentPage else { return }
currentPage.webView.js("playAudio()")
} else {
readCurrentSentence()
Expand Down Expand Up @@ -212,7 +212,7 @@ public class FolioReaderAudioPlayer: NSObject {
func playPrevChapter() {
stopPlayerTimer()
// Wait for "currentPage" to update, then request to play audio
FolioReader.sharedInstance.readerCenter.changePageToPrevious {
FolioReader.sharedInstance.readerCenter?.changePageToPrevious {
if self.isPlaying() {
self.play()
} else {
Expand All @@ -224,7 +224,7 @@ public class FolioReaderAudioPlayer: NSObject {
func playNextChapter() {
stopPlayerTimer()
// Wait for "currentPage" to update, then request to play audio
FolioReader.sharedInstance.readerCenter.changePageToNext {
FolioReader.sharedInstance.readerCenter?.changePageToNext {
if self.isPlaying() {
self.play()
}
Expand Down Expand Up @@ -293,7 +293,7 @@ public class FolioReaderAudioPlayer: NSObject {
// get the fragment ID so we can "mark" it in the webview
let textParts = textFragment!.componentsSeparatedByString("#")
let fragmentID = textParts[1];
FolioReader.sharedInstance.readerCenter.audioMark(href: currentHref, fragmentID: fragmentID)
FolioReader.sharedInstance.readerCenter?.audioMark(href: currentHref, fragmentID: fragmentID)

return true
}
Expand Down Expand Up @@ -353,18 +353,23 @@ public class FolioReaderAudioPlayer: NSObject {
// MARK: TTS Sentence

func speakSentence() {
guard let currentPage = FolioReader.sharedInstance.readerCenter.currentPage else { return }
guard let
readerCenter = FolioReader.sharedInstance.readerCenter,
currentPage = readerCenter.currentPage else {
return
}

let sentence = currentPage.webView.js("getSentenceWithIndex('\(book.playbackActiveClass())')")

if sentence != nil {
let chapter = FolioReader.sharedInstance.readerCenter.getCurrentChapter()
let chapter = readerCenter.getCurrentChapter()
let href = chapter != nil ? chapter!.href : "";
playText(href, text: sentence!)
} else {
if FolioReader.sharedInstance.readerCenter.isLastPage() {
if readerCenter.isLastPage() {
stop()
} else {
FolioReader.sharedInstance.readerCenter.changePageToNext()
readerCenter.changePageToNext()
}
}
}
Expand All @@ -378,7 +383,7 @@ public class FolioReaderAudioPlayer: NSObject {
} else {
if synthesizer.speaking {
stopSynthesizer(immediate: false, completion: {
if let currentPage = FolioReader.sharedInstance.readerCenter.currentPage {
if let currentPage = FolioReader.sharedInstance.readerCenter?.currentPage {
currentPage.webView.js("resetCurrentSentenceIndex()")
}
self.speakSentence()
Expand Down Expand Up @@ -463,7 +468,7 @@ public class FolioReaderAudioPlayer: NSObject {
the `currentPage` in ReaderCenter may not have updated just yet
*/
func getCurrentChapterName() -> String? {
guard let chapter = FolioReader.sharedInstance.readerCenter.getCurrentChapter() else {
guard let chapter = FolioReader.sharedInstance.readerCenter?.getCurrentChapter() else {
return nil
}

Expand Down
41 changes: 2 additions & 39 deletions Source/FolioReaderCenter.swift
Expand Up @@ -358,25 +358,7 @@ public class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICo
html = html?.stringByReplacingOccurrencesOfString("</head>", withString: toInject)

// Font class name
var classes = ""
let currentFontName = FolioReader.currentFontName
switch currentFontName {
case 0:
classes = "andada"
break
case 1:
classes = "lato"
break
case 2:
classes = "lora"
break
case 3:
classes = "raleway"
break
default:
break
}

var classes = FolioReader.currentFont.cssIdentifier
classes += " "+FolioReader.currentMediaOverlayStyle.className()

// Night mode
Expand All @@ -385,26 +367,7 @@ public class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICo
}

// Font Size
let currentFontSize = FolioReader.currentFontSize
switch currentFontSize {
case 0:
classes += " textSizeOne"
break
case 1:
classes += " textSizeTwo"
break
case 2:
classes += " textSizeThree"
break
case 3:
classes += " textSizeFour"
break
case 4:
classes += " textSizeFive"
break
default:
break
}
classes += " \(FolioReader.currentFontSize.cssIdentifier)"

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

Expand Down
4 changes: 2 additions & 2 deletions Source/FolioReaderContainer.swift
Expand Up @@ -59,10 +59,10 @@ public class FolioReaderContainer: UIViewController {

// Register custom fonts
FontBlaster.blast(NSBundle.frameworkBundle())

// Register initial defaults
FolioReader.defaults.registerDefaults([
kCurrentFontFamily: 0,
kCurrentFontFamily: FolioReaderFont.Andada.rawValue,
kNightMode: false,
kCurrentFontSize: 2,
kCurrentAudioRate: 1,
Expand Down

0 comments on commit 268907d

Please sign in to comment.