This repository was archived by the owner on May 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
ADD font face selection #145
Open
vince4
wants to merge
2
commits into
readium:develop
Choose a base branch
from
vince4:feature/font_face_selector
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+15.6 KB
SDKLauncher-Android/app/src/main/assets/font-faces/Noto-Serif/Noto-Serif-700.woff
Binary file not shown.
Binary file added
BIN
+16.8 KB
SDKLauncher-Android/app/src/main/assets/font-faces/Noto-Serif/Noto-Serif-700italic.woff
Binary file not shown.
Binary file added
BIN
+13.5 KB
SDKLauncher-Android/app/src/main/assets/font-faces/Noto-Serif/Noto-Serif-italic.woff
Binary file not shown.
Binary file added
BIN
+15.2 KB
SDKLauncher-Android/app/src/main/assets/font-faces/Noto-Serif/Noto-Serif-regular.woff
Binary file not shown.
27 changes: 27 additions & 0 deletions
27
SDKLauncher-Android/app/src/main/assets/font-faces/Noto-Serif/Noto-Serif.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@font-face { | ||
font-family: 'Noto Serif'; | ||
src: url('Noto-Serif-italic.woff') format('woff'); | ||
font-weight: normal; | ||
font-style: italic; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Noto Serif'; | ||
src: url('Noto-Serif-700.woff') format('woff'); | ||
font-weight: bold; | ||
font-style: normal; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Noto Serif'; | ||
src: url('Noto-Serif-700italic.woff') format('woff'); | ||
font-weight: bold; | ||
font-style: italic; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Noto Serif'; | ||
src: url('Noto-Serif-regular.woff') format('woff'); | ||
font-weight: normal; | ||
font-style: normal; | ||
} |
Binary file added
BIN
+13.9 KB
SDKLauncher-Android/app/src/main/assets/font-faces/Open-Sans/Open-Sans-700.woff
Binary file not shown.
Binary file added
BIN
+14.4 KB
SDKLauncher-Android/app/src/main/assets/font-faces/Open-Sans/Open-Sans-700italic.woff
Binary file not shown.
Binary file added
BIN
+14.7 KB
SDKLauncher-Android/app/src/main/assets/font-faces/Open-Sans/Open-Sans-italic.woff
Binary file not shown.
Binary file added
BIN
+13.9 KB
SDKLauncher-Android/app/src/main/assets/font-faces/Open-Sans/Open-Sans-regular.woff
Binary file not shown.
27 changes: 27 additions & 0 deletions
27
SDKLauncher-Android/app/src/main/assets/font-faces/Open-Sans/Open-Sans.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@font-face { | ||
font-family: 'Open Sans'; | ||
src: url('Open-Sans-italic.woff') format('woff'); | ||
font-weight: normal; | ||
font-style: italic; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Open Sans'; | ||
src: url('Open-Sans-700.woff') format('woff'); | ||
font-weight: bold; | ||
font-style: normal; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Open Sans'; | ||
src: url('Open-Sans-700italic.woff') format('woff'); | ||
font-weight: bold; | ||
font-style: italic; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Open Sans'; | ||
src: url('Open-Sans-regular.woff') format('woff'); | ||
font-weight: normal; | ||
font-style: normal; | ||
} |
Binary file added
BIN
+13.4 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Bold.eot
Binary file not shown.
244 changes: 244 additions & 0 deletions
244
...ncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+139 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Bold.ttf
Binary file not shown.
Binary file added
BIN
+16.2 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Bold.woff
Binary file not shown.
Binary file added
BIN
+26.3 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-BoldItalic.eot
Binary file not shown.
244 changes: 244 additions & 0 deletions
244
...Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-BoldItalic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+285 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-BoldItalic.ttf
Binary file not shown.
Binary file added
BIN
+29.2 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-BoldItalic.woff
Binary file not shown.
Binary file added
BIN
+23.5 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Italic.eot
Binary file not shown.
459 changes: 459 additions & 0 deletions
459
...her-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Italic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+263 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Italic.ttf
Binary file not shown.
Binary file added
BIN
+26.1 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Italic.woff
Binary file not shown.
Binary file added
BIN
+13.5 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Regular.eot
Binary file not shown.
616 changes: 616 additions & 0 deletions
616
...er-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Regular.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+135 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Regular.ttf
Binary file not shown.
Binary file added
BIN
+16.2 KB
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic-Regular.woff
Binary file not shown.
52 changes: 52 additions & 0 deletions
52
SDKLauncher-Android/app/src/main/assets/font-faces/OpenDyslexic/OpenDyslexic.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
@font-face { | ||
font-family: 'OpenDyslexic'; | ||
src: | ||
local('OpenDyslexic'), | ||
local('OpenDyslexic Regular'), | ||
local('OpenDyslexic-Regular'), | ||
url('OpenDyslexic-Regular.eot') format('embedded-opentype'), | ||
url('OpenDyslexic-Regular.woff') format('woff'), | ||
url('OpenDyslexic-Regular.ttf') format('truetype'), | ||
url('OpenDyslexic-Regular.svg') format('svg'); | ||
font-weight: normal; | ||
font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'OpenDyslexic'; | ||
src: | ||
local('OpenDyslexic Italic'), | ||
local('OpenDyslexic-Italic'), | ||
url('OpenDyslexic-Italic.eot') format('embedded-opentype'), | ||
url('OpenDyslexic-Italic.woff') format('woff'), | ||
url('OpenDyslexic-Italic.ttf') format('truetype'), | ||
url('OpenDyslexic-Italic.svg') format('svg'); | ||
font-weight: normal; | ||
font-weight: normal; | ||
font-style: italic; | ||
} | ||
@font-face { | ||
font-family: 'OpenDyslexic'; | ||
src: | ||
local('OpenDyslexic Bold'), | ||
local('OpenDyslexic-Bold'), | ||
url('OpenDyslexic-Bold.eot') format('embedded-opentype'), | ||
url('OpenDyslexic-Bold.woff') format('woff'), | ||
url('OpenDyslexic-Bold.ttf') format('truetype'), | ||
url('OpenDyslexic-Bold.svg') format('svg'); | ||
font-weight: normal; | ||
font-weight: bold; | ||
font-style: normal; | ||
} | ||
@font-face { | ||
font-family: 'OpenDyslexic'; | ||
src: | ||
local('OpenDyslexic Bold Italic'), | ||
local('OpenDyslexic-BoldItalic'), | ||
url('OpenDyslexic-BoldItalic.eot') format('embedded-opentype'), | ||
url('OpenDyslexic-BoldItalic.woff') format('woff'), | ||
url('OpenDyslexic-BoldItalic.ttf') format('truetype'), | ||
url('OpenDyslexic-BoldItalic.svg') format('svg'); | ||
font-weight: normal; | ||
font-weight: bold; | ||
font-style: italic; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,15 +36,18 @@ | |
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.nio.charset.Charset; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.readium.sdk.android.Container; | ||
import org.readium.sdk.android.ManifestItem; | ||
import org.readium.sdk.android.Package; | ||
import org.readium.sdk.android.SpineItem; | ||
import org.readium.sdk.android.launcher.model.BookmarkDatabase; | ||
import org.readium.sdk.android.launcher.model.Font; | ||
import org.readium.sdk.android.launcher.model.OpenPageRequest; | ||
import org.readium.sdk.android.launcher.model.Page; | ||
import org.readium.sdk.android.launcher.model.PaginationInfo; | ||
|
@@ -207,6 +210,7 @@ public byte[] handle(byte[] data, String mime, String uriPath, | |
private Package mPackage; | ||
private OpenPageRequest mOpenPageRequestData; | ||
private TextView mPageInfo; | ||
private ArrayList<Font> mFontArray; | ||
private ViewerSettings mViewerSettings; | ||
private ReadiumJSApi mReadiumJSApi; | ||
private EpubServer mServer; | ||
|
@@ -269,11 +273,18 @@ protected void onCreate(Bundle savedInstanceState) { | |
mPackage, quiet, dataPreProcessor); | ||
mServer.startServer(); | ||
|
||
// Load the page skeleton | ||
mWebview.loadUrl(READER_SKELETON); | ||
mViewerSettings = new ViewerSettings( | ||
ViewerSettings.SyntheticSpreadMode.AUTO, | ||
ViewerSettings.ScrollMode.AUTO, 100, 20); | ||
// Load the page skeleton | ||
mWebview.loadUrl(READER_SKELETON); | ||
|
||
ArrayList<Font> fontList = new ArrayList<>(); | ||
fontList.add(new Font("Open Dyslexic", "OpenDyslexic", "font-faces/OpenDyslexic/OpenDyslexic.css")); | ||
fontList.add(new Font("Open Sans", "Open Sans", "font-faces/Open-Sans/Open-Sans.css")); | ||
fontList.add(new Font("Noto Serif", "Noto Serif", "font-faces/Noto-Serif/Noto-Serif.css")); | ||
mFontArray = fontList; | ||
|
||
mViewerSettings = new ViewerSettings( | ||
ViewerSettings.SyntheticSpreadMode.AUTO, | ||
ViewerSettings.ScrollMode.AUTO, 0, 100, 20); | ||
|
||
mReadiumJSApi = new ReadiumJSApi(new ReadiumJSApi.JSLoader() { | ||
@Override | ||
|
@@ -364,7 +375,7 @@ public void onClick(View v) { | |
private void showSettings() { | ||
FragmentManager fm = getSupportFragmentManager(); | ||
FragmentTransaction fragmentTransaction = fm.beginTransaction(); | ||
DialogFragment dialog = new ViewerSettingsDialog(this, mViewerSettings); | ||
DialogFragment dialog = new ViewerSettingsDialog(this, mViewerSettings, mFontArray); | ||
dialog.show(fm, "dialog"); | ||
fragmentTransaction.commit(); | ||
} | ||
|
@@ -507,10 +518,35 @@ public WebResourceResponse shouldInterceptRequest(WebView view, | |
if (!quiet) | ||
Log.d(TAG, "READER ASSET ..."); | ||
|
||
// reader.html | ||
if (mime.equals("application/xhtml+xml")) { | ||
mime = "text/html"; | ||
} | ||
// Font injection | ||
if (url.matches(ASSET_PREFIX + "\\/?font-faces\\/fonts.js")) { | ||
if (!quiet) | ||
Log.d(TAG, "readiumFontFaces inject ..."); | ||
|
||
if (mFontArray != null && mFontArray.size() > 0) { | ||
try { | ||
JSONArray jsonArray = new JSONArray(); | ||
for (Font fontFace : mFontArray) { | ||
jsonArray.put(fontFace.toJSON()); | ||
} | ||
|
||
String readiumFontFaces = "var readiumFontFaces =" + jsonArray.toString() + ";"; | ||
|
||
return new WebResourceResponse("text/javascript", UTF_8, new ByteArrayInputStream(readiumFontFaces.getBytes())); | ||
} catch (JSONException e) { | ||
return new WebResourceResponse(null, UTF_8, | ||
new ByteArrayInputStream("".getBytes())); | ||
} | ||
} else { | ||
return new WebResourceResponse(null, UTF_8, | ||
new ByteArrayInputStream("".getBytes())); | ||
} | ||
} | ||
|
||
// reader.html | ||
if (mime.equals("application/xhtml+xml")) { | ||
mime = "text/html"; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! Tabulations vs. space characters! :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My apologies, I chose the wrong option on Android Studio |
||
InputStream is = null; | ||
try { | ||
|
@@ -538,12 +574,12 @@ public WebResourceResponse shouldInterceptRequest(WebView view, | |
// iframe(s) | ||
|
||
evaluateJavascript(INJECT_EPUB_RSO_SCRIPT_2); | ||
|
||
return new WebResourceResponse("text/javascript", UTF_8, | ||
new ByteArrayInputStream( | ||
"(function(){})()".getBytes())); | ||
} | ||
|
||
if (cleanedUrl.matches("\\/?readium_MathJax.js")) { | ||
if (!quiet) | ||
Log.d(TAG, "MathJax.js inject ..."); | ||
|
@@ -580,6 +616,25 @@ public WebResourceResponse shouldInterceptRequest(WebView view, | |
return new WebResourceResponse("text/css", UTF_8, is); | ||
} | ||
|
||
if (cleanedUrl.matches(".*\\/?font-faces\\/.*")) { | ||
if (!quiet) | ||
Log.d(TAG, "font-face inject ..."); | ||
|
||
String assetPath = cleanedUrl.substring(cleanedUrl.lastIndexOf("font-faces/")); | ||
|
||
InputStream is = null; | ||
try { | ||
is = getAssets().open(assetPath); | ||
} catch (IOException e) { | ||
|
||
Log.e(TAG, "font-face asset fail!"); | ||
|
||
return super.shouldInterceptRequest(view, url); | ||
} | ||
|
||
return new WebResourceResponse(null, UTF_8, is); | ||
} | ||
|
||
|
||
ManifestItem item = mPackage.getManifestItem(cleanedUrl); | ||
String contentType = item != null ? item.getMediaType() : null; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
font-faces/fonts.js
file missing from this PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, it is dynamically resolved (HTTP route): https://github.com/readium/SDKLauncher-Android/pull/145/files#diff-da5def91bcae4c49b677f23482bf2658R522