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,24 +766,26 @@ 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);
for (String face : faces.split(",")) {
face = face.trim().replace("\"", "");
if ("fairemail".equals(face)) if ("fairemail".equals(face))
return ResourcesCompat.getFont(context, R.font.fantasy); return ResourcesCompat.getFont(context, R.font.fantasy);
else if (face.contains("comic sans")) else if (face.contains("comic sans"))
return ResourcesCompat.getFont(context, R.font.opendyslexic); return ResourcesCompat.getFont(context, R.font.opendyslexic);
else 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); return Typeface.create(family, Typeface.NORMAL);
} }