Skip to content

Commit

Permalink
Added OpenDyslexic
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Jun 1, 2021
1 parent a2bd658 commit 9740f29
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ FairEmail uses:
* [Compact Language Detector v3](https://github.com/google/cld3). Copyright 2016 Google Inc. All rights reserved. [Apache License 2.0](https://github.com/google/cld3/blob/master/LICENSE).
* [POI-HMEF](https://poi.apache.org/components/hmef/index.html). Copyright © 2001-2020 The Apache Software Foundation. [Apache Software License v2](https://poi.apache.org/devel/guidelines.html#The+Licensing).
* [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt).
* [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt).
1 change: 1 addition & 0 deletions app/src/main/assets/ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ FairEmail uses:
* [Compact Language Detector v3](https://github.com/google/cld3). Copyright 2016 Google Inc. All rights reserved. [Apache License 2.0](https://github.com/google/cld3/blob/master/LICENSE).
* [POI-HMEF](https://poi.apache.org/components/hmef/index.html). Copyright © 2001-2020 The Apache Software Foundation. [Apache Software License v2](https://poi.apache.org/devel/guidelines.html#The+Licensing).
* [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt).
* [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt).
9 changes: 2 additions & 7 deletions app/src/main/java/eu/faircode/email/HtmlHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.ColorUtils;
import androidx.core.util.PatternsCompat;
import androidx.preference.PreferenceManager;
Expand Down Expand Up @@ -2256,11 +2255,7 @@ public void tail(Node node, int depth) {
}
break;
case "font-family":
String face = value.toLowerCase(Locale.ROOT);
if ("fairemail".equals(face)) {
Typeface typeface = ResourcesCompat.getFont(context, R.font.fantasy);
setSpan(ssb, new CustomTypefaceSpan(face, typeface), start, ssb.length());
} else if ("wingdings".equals(face)) {
if ("wingdings".equalsIgnoreCase(value)) {
for (int i = start; i < ssb.length(); i++) {
int kar = ssb.charAt(i);
if (kar >= 0x20 && kar < 0x20 + WINGDING_TO_UNICODE.length) {
Expand All @@ -2271,7 +2266,7 @@ public void tail(Node node, int depth) {
}
}
} else
setSpan(ssb, new TypefaceSpan(face), start, ssb.length());
setSpan(ssb, StyleHelper.getTypefaceSpan(value, context), start, ssb.length());
break;
case "text-decoration":
if ("line-through".equals(value))
Expand Down
20 changes: 17 additions & 3 deletions app/src/main/java/eu/faircode/email/StyleHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import android.widget.EditText;

import androidx.appcompat.widget.PopupMenu;
import androidx.core.content.res.ResourcesCompat;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceManager;

Expand Down Expand Up @@ -155,7 +156,7 @@ static boolean apply(int action, LifecycleOwner owner, View anchor, EditText etB
SubMenu smenu = popupMenu.getMenu().findItem(R.id.menu_style_font).getSubMenu();
for (int i = 0; i < fontNameNames.length; i++) {
SpannableStringBuilder ssb = new SpannableStringBuilder(fontNameNames[i]);
ssb.setSpan(new TypefaceSpan(fontNameValues[i]), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(getTypefaceSpan(fontNameValues[i], context), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
smenu.add(R.id.group_style_font, i, 0, ssb);
}
smenu.add(R.id.group_style_font, fontNameNames.length, 0, R.string.title_style_font_default);
Expand Down Expand Up @@ -412,11 +413,12 @@ private boolean setFont(MenuItem item) {
int f = edit.getSpanFlags(span);
edit.removeSpan(span);
splitSpan(edit, start, end, s, e, f, false,
new TypefaceSpan(span.getFamily()), new TypefaceSpan(span.getFamily()));
getTypefaceSpan(span.getFamily(), context),
getTypefaceSpan(span.getFamily(), context));
}

if (face != null)
edit.setSpan(new TypefaceSpan(face), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
edit.setSpan(getTypefaceSpan(face, context), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

etBody.setText(edit);
etBody.setSelection(start, end);
Expand Down Expand Up @@ -761,5 +763,17 @@ else if (span instanceof BulletSpanEx)
}
}

static TypefaceSpan getTypefaceSpan(String family, Context context) {
String face = family.toLowerCase(Locale.ROOT);
if ("fairemail".equals(face)) {
Typeface typeface = ResourcesCompat.getFont(context, R.font.fantasy);
return new CustomTypefaceSpan(face, typeface);
} else if (face.contains("comic sans")) {
Typeface typeface = ResourcesCompat.getFont(context, R.font.opendyslexic);
return new CustomTypefaceSpan(face, typeface);
} else
return new TypefaceSpan(face);
}

//TextUtils.dumpSpans(text, new LogPrinter(android.util.Log.INFO, "FairEmail"), "afterTextChanged ");
}
9 changes: 9 additions & 0 deletions app/src/main/res/font/opendyslexic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml -->
<font
app:font="@font/opendyslexic_normal"
app:fontStyle="normal"
app:fontWeight="400" />
<!-- https://opendyslexic.org/ -->
</font-family>
Binary file added app/src/main/res/font/opendyslexic_normal.ttf
Binary file not shown.
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,8 @@
<item>Sans-serif</item>
<item>Monospace</item>
<item>Fantasy</item>
<item>Fantasy</item>
<item>Dyslexia</item>
</string-array>

<!-- https://www.w3.org/TR/css-fonts-4/#generic-font-families -->
Expand All @@ -1900,6 +1902,7 @@
<item>sans-serif</item>
<item>monospace</item>
<item>fantasy</item>
<item>comic sans</item>
</string-array>

<string name="fingerprint" translatable="false">17BA15C1AF55D925F98B99CEA4375D4CDF4C174B</string>
Expand Down

0 comments on commit 9740f29

Please sign in to comment.