From 17577438d2d5cdf8b183f766c382f15110975e34 Mon Sep 17 00:00:00 2001 From: neowinston Date: Wed, 30 Mar 2016 16:10:56 -0400 Subject: [PATCH 1/4] Update Main.storyboard Added Cover Image Preview --- Example/Example/Base.lproj/Main.storyboard | 73 +++++++++++++++++++--- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/Example/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard index 449b42dc2..37dd7baae 100644 --- a/Example/Example/Base.lproj/Main.storyboard +++ b/Example/Example/Base.lproj/Main.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -17,34 +18,86 @@ - - + + + + + + + + - - + + + + + + + + + + + + + + + + + From 08f70773ced12e7b8b496097a0263e0e95b98427 Mon Sep 17 00:00:00 2001 From: neowinston Date: Wed, 30 Mar 2016 16:12:48 -0400 Subject: [PATCH 2/4] Update ViewController.swift --- Example/Example/ViewController.swift | 46 +++++++++++++++++++--------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index 18b7b10e5..052566317 100755 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -11,35 +11,51 @@ import FolioReaderKit class ViewController: UIViewController { + @IBOutlet + var coverImageView : UIImageView! + + // http://www.readbeyond.it/ebooks.html + let epubSampleFiles = [ + "The Silver Chair", // standard eBook + "The Adventures Of Sherlock Holmes - Adventure I", // audio-eBook + ] + override func viewDidLoad() { super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + coverImageView.layer.borderWidth = 4 + coverImageView.layer.masksToBounds = true + coverImageView.layer.borderColor = UIColor(red: 255.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0).CGColor } @IBAction func didOpen(sender: AnyObject) { openEpub(sender.tag); } - + + @IBAction func getEpubCoverImage(sender: AnyObject) { + showEpubCover(sender.tag); + } + func openEpub(sampleNum:Int) { let config = FolioReaderConfig() config.shouldHideNavigationOnTap = sampleNum == 1 ? true : false -// config.allowSharing = false -// config.tintColor = UIColor.blueColor() -// config.toolBarTintColor = UIColor.redColor() -// config.toolBarBackgroundColor = UIColor.purpleColor() -// config.menuTextColor = UIColor.brownColor() -// config.menuBackgroundColor = UIColor.lightGrayColor() + //config.allowSharing = false + //config.tintColor = UIColor.blueColor() + //config.toolBarTintColor = UIColor.redColor() + //config.toolBarBackgroundColor = UIColor.purpleColor() + //config.menuTextColor = UIColor.brownColor() + //config.menuBackgroundColor = UIColor.lightGrayColor() - // http://www.readbeyond.it/ebooks.html - let epubSampleFiles = [ - "The Silver Chair", // standard eBook - "The Adventures Of Sherlock Holmes - Adventure I", // audio-eBook - ] - let epubName = epubSampleFiles[sampleNum-1]; let bookPath = NSBundle.mainBundle().pathForResource(epubName, ofType: "epub") - FolioReader.presentReader(parentViewController: self, withEpubPath: bookPath!, andConfig: config) } + + func showEpubCover(sampleNum:Int) { + let epubName = epubSampleFiles[sampleNum-1]; + let bookPath = NSBundle.mainBundle().pathForResource(epubName, ofType: "epub") + coverImageView.image = FolioReader.getCoverImage(bookPath!) + } -} \ No newline at end of file +} From 38350e90a317b6f48998212217a801164118620d Mon Sep 17 00:00:00 2001 From: neowinston Date: Wed, 30 Mar 2016 16:15:26 -0400 Subject: [PATCH 3/4] Update FolioReaderKit.swift --- Source/FolioReaderKit.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/FolioReaderKit.swift b/Source/FolioReaderKit.swift index 612be959e..4aad5b571 100755 --- a/Source/FolioReaderKit.swift +++ b/Source/FolioReaderKit.swift @@ -65,6 +65,7 @@ public class FolioReader { var isReaderOpen = false var isReaderReady = false + var nightMode: Bool { get { return FolioReader.defaults.valueForKey(kNightMode) as! Bool } set (value) { @@ -111,6 +112,16 @@ public class FolioReader { FolioReader.defaults.synchronize() } } + + // MARK: - Get Cover Image + + /** + Read Cover Image and Return an IUImage + */ + + public class func getCoverImage(epubPath: String) -> UIImage { + return FREpubParser().parseCoverImage(epubPath) + } // MARK: - Present Folio Reader @@ -522,4 +533,4 @@ extension Array { subscript(safe index: Int) -> Element? { return indices ~= index ? self[index] : nil } -} \ No newline at end of file +} From 149ccad34af1d33b7b0bfa13912c1e891523e4a9 Mon Sep 17 00:00:00 2001 From: neowinston Date: Wed, 30 Mar 2016 16:16:28 -0400 Subject: [PATCH 4/4] Update FREpubParser.swift --- Source/EPUBCore/FREpubParser.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Source/EPUBCore/FREpubParser.swift b/Source/EPUBCore/FREpubParser.swift index f51089556..ecc2dd81d 100755 --- a/Source/EPUBCore/FREpubParser.swift +++ b/Source/EPUBCore/FREpubParser.swift @@ -16,6 +16,23 @@ class FREpubParser: NSObject, SSZipArchiveDelegate { var resourcesBasePath: String! private var epubPathToRemove: String? + /** + Parse the Cover Image from an epub file. + Returns an UIImage. + */ + func parseCoverImage(epubPath: String)-> UIImage { + + let book = readEpub(epubPath: epubPath) + + // Read the cover image + let coverImageID = book.metadata.findMetaByName("cover") + if (coverImageID != nil && book.resources.containsById(coverImageID!)) { + book.coverImage = book.resources.getById(coverImageID!) + } + + return UIImage(contentsOfFile: book.coverImage.fullHref)! + } + /** Unzip, delete and read an epub file. Returns a FRBook. @@ -37,6 +54,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate { return book } + /** Read an unziped epub file. Returns a FRBook.