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

Commit

Permalink
Simplify Readium CSS injection and use the new file structure
Browse files Browse the repository at this point in the history
Remove injection of Readium's default stylesheet
  • Loading branch information
mickael-menu committed May 25, 2020
1 parent 9ad0a68 commit 8871956
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ internal class ContentFiltersEpub(private val userPropertiesPath: String?, priva
beginIncludes.add("<meta name=\"viewport\" content=\"width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\" />")

beginIncludes.add(getHtmlLink("/"+ Injectable.Style.rawValue +"/$cssStyle-before.css"))
beginIncludes.add(getHtmlLink("/"+ Injectable.Style.rawValue +"/$cssStyle-default.css"))
endIncludes.add(getHtmlLink("/"+ Injectable.Style.rawValue +"/$cssStyle-after.css"))
endIncludes.add(getHtmlScript("/"+ Injectable.Script.rawValue +"/touchHandling.js"))
endIncludes.add(getHtmlScript("/"+ Injectable.Script.rawValue +"/utils.js"))
Expand Down
89 changes: 20 additions & 69 deletions r2-streamer/src/main/java/org/readium/r2/streamer/server/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.content.Context
import android.content.res.AssetManager
import org.nanohttpd.router.RouterNanoHTTPD
import org.readium.r2.shared.Injectable
import org.readium.r2.shared.publication.ContentLayout
import org.readium.r2.shared.publication.Publication
import org.readium.r2.streamer.BuildConfig.DEBUG
import org.readium.r2.streamer.container.Container
Expand Down Expand Up @@ -61,79 +62,29 @@ abstract class AbstractServer(private var port: Int) : RouterNanoHTTPD("127.0.0.
}

fun loadReadiumCSSResources(assets: AssetManager) {
try {
addResource("ltr-after.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/ltr/ReadiumCSS-after.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("ltr-before.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/ltr/ReadiumCSS-before.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("ltr-default.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/ltr/ReadiumCSS-default.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("rtl-after.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/rtl/ReadiumCSS-after.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("rtl-before.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/rtl/ReadiumCSS-before.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("rtl-default.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/rtl/ReadiumCSS-default.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("cjk-vertical-after.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/cjk-vertical/ReadiumCSS-after.css"), "utf-8")
fun load(name: String, layout: ContentLayout) {
try {
addResource("${layout.cssId}-${name}.css", Scanner(assets.open("static/readium-css/${layout.readiumCSSPath}ReadiumCSS-$name.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("cjk-vertical-before.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/cjk-vertical/ReadiumCSS-before.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("cjk-vertical-default.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/cjk-vertical/ReadiumCSS-default.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("cjk-horizontal-after.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/cjk-horizontal/ReadiumCSS-after.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
try {
addResource("cjk-horizontal-before.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/cjk-horizontal/ReadiumCSS-before.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
} catch (e: IOException) {
if (DEBUG) Timber.d(e)
}
}
try {
addResource("cjk-horizontal-default.css", Scanner(assets.open("static/"+ Injectable.Style.rawValue +"/cjk-horizontal/ReadiumCSS-default.css"), "utf-8")
.useDelimiter("\\A").next())
} catch (e: IOException) {
if (DEBUG) Timber.d(e)

for (layout in ContentLayout.values()) {
load("before", layout)
load("default", layout)
load("after", layout)
}
}

private val ContentLayout.readiumCSSPath: String get() = when(this) {
ContentLayout.LTR -> ""
ContentLayout.RTL -> "rtl/"
ContentLayout.CJK_VERTICAL -> "cjk-vertical/"
ContentLayout.CJK_HORIZONTAL -> "cjk-horizontal/"
}

fun loadR2ScriptResources(assets: AssetManager) {
try {
addResource("touchHandling.js", Scanner(assets.open(Injectable.Script.rawValue + "/touchHandling.js"), "utf-8")
Expand Down

0 comments on commit 8871956

Please sign in to comment.