Improved font mapper

This commit is contained in:
M66B 2021-06-05 18:12:22 +02:00
parent cc74e500ca
commit 906f41769a
1 changed files with 18 additions and 16 deletions

View File

@ -766,25 +766,27 @@ public class StyleHelper {
} }
static TypefaceSpan getTypefaceSpan(String family, Context context) { static TypefaceSpan getTypefaceSpan(String family, Context context) {
String face = family.toLowerCase(Locale.ROOT); String faces = family.toLowerCase(Locale.ROOT);
if ("fairemail".equals(face)) { if (faces.contains("comic sans"))
Typeface typeface = ResourcesCompat.getFont(context, R.font.fantasy); family = "comic sans ms, sans-serif";
return new CustomTypefaceSpan(family, typeface); return new CustomTypefaceSpan(family, getTypeface(family, context));
} else if (face.contains("comic sans")) {
Typeface typeface = ResourcesCompat.getFont(context, R.font.opendyslexic);
return new CustomTypefaceSpan("comic sans ms, sans-serif", typeface);
} else
return new TypefaceSpan(family);
} }
static Typeface getTypeface(String family, Context context) { static Typeface getTypeface(String family, Context context) {
String face = family.toLowerCase(Locale.ROOT); String faces = family.toLowerCase(Locale.ROOT);
if ("fairemail".equals(face)) for (String face : faces.split(",")) {
return ResourcesCompat.getFont(context, R.font.fantasy); face = face.trim().replace("\"", "");
else if (face.contains("comic sans")) if ("fairemail".equals(face))
return ResourcesCompat.getFont(context, R.font.opendyslexic); return ResourcesCompat.getFont(context, R.font.fantasy);
else else if (face.contains("comic sans"))
return Typeface.create(family, Typeface.NORMAL); return ResourcesCompat.getFont(context, R.font.opendyslexic);
else if (face.equals("times new roman") || face.equals("serif"))
return Typeface.SERIF;
else if (face.equals("arial") || face.equals("sans-serif"))
return Typeface.SANS_SERIF;
}
return Typeface.create(family, Typeface.NORMAL);
} }
//TextUtils.dumpSpans(text, new LogPrinter(android.util.Log.INFO, "FairEmail"), "afterTextChanged "); //TextUtils.dumpSpans(text, new LogPrinter(android.util.Log.INFO, "FairEmail"), "afterTextChanged ");