Added OpenDyslexic

pull/199/head
M66B 4 years ago
parent a2bd658931
commit 9740f296ee

@ -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). * [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). * [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). * [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).

@ -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). * [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). * [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). * [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).

@ -54,7 +54,6 @@ import android.util.Patterns;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import androidx.core.util.PatternsCompat; import androidx.core.util.PatternsCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -2256,11 +2255,7 @@ public class HtmlHelper {
} }
break; break;
case "font-family": case "font-family":
String face = value.toLowerCase(Locale.ROOT); if ("wingdings".equalsIgnoreCase(value)) {
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)) {
for (int i = start; i < ssb.length(); i++) { for (int i = start; i < ssb.length(); i++) {
int kar = ssb.charAt(i); int kar = ssb.charAt(i);
if (kar >= 0x20 && kar < 0x20 + WINGDING_TO_UNICODE.length) { if (kar >= 0x20 && kar < 0x20 + WINGDING_TO_UNICODE.length) {
@ -2271,7 +2266,7 @@ public class HtmlHelper {
} }
} }
} else } else
setSpan(ssb, new TypefaceSpan(face), start, ssb.length()); setSpan(ssb, StyleHelper.getTypefaceSpan(value, context), start, ssb.length());
break; break;
case "text-decoration": case "text-decoration":
if ("line-through".equals(value)) if ("line-through".equals(value))

@ -49,6 +49,7 @@ import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.PopupMenu;
import androidx.core.content.res.ResourcesCompat;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -155,7 +156,7 @@ public class StyleHelper {
SubMenu smenu = popupMenu.getMenu().findItem(R.id.menu_style_font).getSubMenu(); SubMenu smenu = popupMenu.getMenu().findItem(R.id.menu_style_font).getSubMenu();
for (int i = 0; i < fontNameNames.length; i++) { for (int i = 0; i < fontNameNames.length; i++) {
SpannableStringBuilder ssb = new SpannableStringBuilder(fontNameNames[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, i, 0, ssb);
} }
smenu.add(R.id.group_style_font, fontNameNames.length, 0, R.string.title_style_font_default); smenu.add(R.id.group_style_font, fontNameNames.length, 0, R.string.title_style_font_default);
@ -412,11 +413,12 @@ public class StyleHelper {
int f = edit.getSpanFlags(span); int f = edit.getSpanFlags(span);
edit.removeSpan(span); edit.removeSpan(span);
splitSpan(edit, start, end, s, e, f, false, 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) 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.setText(edit);
etBody.setSelection(start, end); etBody.setSelection(start, end);
@ -761,5 +763,17 @@ public class StyleHelper {
} }
} }
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 "); //TextUtils.dumpSpans(text, new LogPrinter(android.util.Log.INFO, "FairEmail"), "afterTextChanged ");
} }

@ -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>

@ -1891,6 +1891,8 @@
<item>Sans-serif</item> <item>Sans-serif</item>
<item>Monospace</item> <item>Monospace</item>
<item>Fantasy</item> <item>Fantasy</item>
<item>Fantasy</item>
<item>Dyslexia</item>
</string-array> </string-array>
<!-- https://www.w3.org/TR/css-fonts-4/#generic-font-families --> <!-- https://www.w3.org/TR/css-fonts-4/#generic-font-families -->
@ -1900,6 +1902,7 @@
<item>sans-serif</item> <item>sans-serif</item>
<item>monospace</item> <item>monospace</item>
<item>fantasy</item> <item>fantasy</item>
<item>comic sans</item>
</string-array> </string-array>
<string name="fingerprint" translatable="false">17BA15C1AF55D925F98B99CEA4375D4CDF4C174B</string> <string name="fingerprint" translatable="false">17BA15C1AF55D925F98B99CEA4375D4CDF4C174B</string>

Loading…
Cancel
Save