Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #68 from readium/develop
Browse files Browse the repository at this point in the history
1.0.4
  • Loading branch information
aferditamuriqi authored Jul 18, 2018
2 parents 2f18991 + 50ca4a0 commit 06efd16
Show file tree
Hide file tree
Showing 34 changed files with 252 additions and 293 deletions.
7 changes: 5 additions & 2 deletions R2Streamer/DataExtension.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// DataExtension.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 7/5/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
Expand Down
7 changes: 5 additions & 2 deletions R2Streamer/Loggable.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// Loggable.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 3/7/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
Expand Down
7 changes: 5 additions & 2 deletions R2Streamer/Logger.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// Logger.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 3/8/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
Expand Down
7 changes: 5 additions & 2 deletions R2Streamer/LoggerStub.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// LoggerStub.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 3/8/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
Expand Down
7 changes: 5 additions & 2 deletions R2Streamer/R2Streamer.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// R2Streamer.h
// R2Streamer
// r2-streamer-swift
//
// Created by Olivier Körner on 18/01/2017.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

#import <UIKit/UIKit.h>
Expand Down
7 changes: 5 additions & 2 deletions R2Streamer/StringExtension.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// StringExtension.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 2/27/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
Expand Down
Binary file added R2Streamer/fonts/OpenDyslexic-Regular.otf
Binary file not shown.
7 changes: 5 additions & 2 deletions Sources/R2Streamer-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// R2Streamer-Bridging-Header.h
// R2Streamer
// r2-streamer-swift
//
// Created by Olivier Körner on 21/12/2016.
// Copyright © 2016 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

#ifndef R2Streamer_Bridging_Header_h
Expand Down
7 changes: 5 additions & 2 deletions Sources/Streams/DataInputStream.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// DataInputStream.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 4/14/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
Expand Down
7 changes: 5 additions & 2 deletions Sources/Streams/FileInputStream.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// SeekableFileInputStream.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Olivier Körner on 15/01/2017.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
Expand Down
7 changes: 5 additions & 2 deletions Sources/Streams/Seekable.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// Seekable.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Olivier Körner on 11/01/2017.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import Foundation
Expand Down
18 changes: 6 additions & 12 deletions Sources/Streams/ZipInputStream.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// RDUnzipStream.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Olivier Körner on 11/01/2017.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import UIKit
Expand Down Expand Up @@ -81,15 +84,13 @@ internal class ZipInputStream: SeekableInputStream {
}

override internal func open() {
//objc_sync_enter(zipArchive)
do {
try zipArchive.openCurrentFile()
_streamStatus = .open
} catch {
print("ERROR: could not ZipArchive.openCurrentFile()")
_streamStatus = .error
_streamError = error
//objc_sync_exit(zipArchive)
}
}

Expand All @@ -100,11 +101,6 @@ internal class ZipInputStream: SeekableInputStream {
}

override internal func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength: Int) -> Int {
// guard _streamStatus == .open else {
// print("Stream not open")
// return -1
// }
//log(level: .debug, "\(fileInZipPath) read \(maxLength) bytes")
let bytesRead = zipArchive.readDataFromCurrentFile(buffer, maxLength: UInt64(maxLength))
if Int(bytesRead) < maxLength {
_streamStatus = .atEnd
Expand All @@ -114,15 +110,13 @@ internal class ZipInputStream: SeekableInputStream {

override internal func close() {
zipArchive.closeCurrentFile()
//objc_sync_exit(zipArchive)
_streamStatus = .closed
}

override internal func seek(offset: Int64, whence: SeekWhence) throws {
assert(whence == .startOfFile, "Only seek from start of stream is supported for now.")
assert(offset >= 0, "Since only seek from start of stream if supported, offset must be >= 0")

//log(level: .debug, "ZipInputStream \(fileInZipPath) offset \(offset)")

do {
try zipArchive.seek(Int(offset))
} catch {
Expand Down
52 changes: 42 additions & 10 deletions Sources/fetcher/ContentFilter.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// FetcherEpub.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 4/12/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import R2Shared
Expand Down Expand Up @@ -157,6 +160,18 @@ final internal class ContentFiltersEpub: ContentFilters {
guard var resourceHtml = String.init(data: data, encoding: String.Encoding.utf8) else {
return stream
}

// Inserting in <HTML>
guard let htmlContentStart = resourceHtml.endIndex(of: "<html") else {
print("Invalid resource")
abort()
}

// User properties injection
let style = " style=\" " + buildUserPropertiesString(publication: publication) + "\""

resourceHtml = resourceHtml.insert(string: style, at: htmlContentStart)

// Inserting at the start of <HEAD>.
guard let headStart = resourceHtml.endIndex(of: "<head>") else {
print("Invalid resource")
Expand Down Expand Up @@ -200,10 +215,13 @@ final internal class ContentFiltersEpub: ContentFilters {
let scriptTouchHandling = getHtmlScript(forResource: "\(baseUrl)scripts/touchHandling.js")

let scriptUtils = getHtmlScript(forResource: "\(baseUrl)scripts/\(utilsJS)")

let fontStyle = getHtmlFontStyle(forResource: "\(baseUrl)fonts/OpenDyslexic-Regular.otf", fontFamily: "OpenDyslexic")

resourceHtml = resourceHtml.insert(string: cssAfter, at: headEnd)
resourceHtml = resourceHtml.insert(string: scriptTouchHandling, at: headEnd)
resourceHtml = resourceHtml.insert(string: scriptUtils, at: headEnd)
resourceHtml = resourceHtml.insert(string: fontStyle, at: headEnd)

let enhancedData = resourceHtml.data(using: String.Encoding.utf8)
let enhancedStream = DataInputStream(data: enhancedData!)
Expand Down Expand Up @@ -261,34 +279,48 @@ final internal class ContentFiltersEpub: ContentFilters {

return prefix + resourceName + suffix
}


fileprivate func getHtmlFontStyle(forResource resourceName: String, fontFamily: String) -> String {
return "<style type=\"text/css\">@font-face{font-family: \"\(fontFamily)\"; src:url('\(resourceName)') format('opentype');}</style>\n"
}

fileprivate func buildUserPropertiesString(publication: Publication) -> String {
var userPropertiesString = ""

for property in publication.userProperties.properties {
userPropertiesString += property.name + ": " + property.toString() + "; "
}

return userPropertiesString
}

}

let ltrPreset:[ReadiumCSSKey:Bool] = [
let ltrPreset:[ReadiumCSSName: Bool] = [
.hyphens: false,
.ligatures: false]

let rtlPreset:[ReadiumCSSKey:Bool] = [.hyphens: false,
let rtlPreset:[ReadiumCSSName: Bool] = [.hyphens: false,
.wordSpacing: false,
.letterSpacing: false,
.ligatures: true]

let cjkHorizontalPreset: [ReadiumCSSKey:Bool] = [
.textAlignement: false,
let cjkHorizontalPreset: [ReadiumCSSName: Bool] = [
.textAlignment: false,
.hyphens: false,
.paraIndent: false,
.wordSpacing: false,
.letterSpacing: false]

let cjkVerticalPreset: [ReadiumCSSKey:Bool] = [
let cjkVerticalPreset: [ReadiumCSSName: Bool] = [
.columnCount: false,
.textAlignement: false,
.textAlignment: false,
.hyphens: false,
.paraIndent: false,
.wordSpacing: false,
.letterSpacing: false]

let userSettingsUIPreset:[ContentLayoutStyle: [ReadiumCSSKey:Bool]] = [
let userSettingsUIPreset:[ContentLayoutStyle: [ReadiumCSSName: Bool]] = [
.ltr: ltrPreset,
.rtl: rtlPreset,
.cjkVertical: cjkVerticalPreset,
Expand Down
5 changes: 4 additions & 1 deletion Sources/fetcher/DrmDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 10/11/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import R2Shared
Expand Down
7 changes: 5 additions & 2 deletions Sources/fetcher/Fetcher.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// EpubFetcher.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Olivier Körner on 21/12/2016.
// Copyright © 2016 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import R2Shared
Expand Down
7 changes: 5 additions & 2 deletions Sources/fetcher/FontDecoder.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//
// Decoder.swift
// R2Streamer
// r2-streamer-swift
//
// Created by Alexandre Camilleri on 4/13/17.
// Copyright © 2017 Readium. All rights reserved.
//
// Copyright 2018 Readium Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style license which is detailed
// in the LICENSE file present in the project repository where this source code is maintained.
//

import R2Shared
Expand Down
Loading

0 comments on commit 06efd16

Please sign in to comment.