prevent crash

This commit is contained in:
M66B 2021-08-01 07:13:38 +02:00
parent f52a4e842e
commit 7eaed34d54
2 changed files with 20 additions and 8 deletions

View File

@ -164,10 +164,15 @@ public class HtmlEx {
}
private /* static */ String getTextDirection(Spanned text, int start, int end) {
if (TextDirectionHeuristics.FIRSTSTRONG_LTR.isRtl(text, start, end - start)) {
return " dir=\"rtl\"";
} else {
return " dir=\"ltr\"";
try {
if (TextDirectionHeuristics.FIRSTSTRONG_LTR.isRtl(text, start, end - start)) {
return " dir=\"rtl\"";
} else {
return " dir=\"ltr\"";
}
} catch (Throwable ex) {
eu.faircode.email.Log.e(ex);
return "";
}
}

View File

@ -19,6 +19,9 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_INDIVIDUAL;
import static org.w3c.css.sac.Condition.SAC_CLASS_CONDITION;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
@ -118,9 +121,6 @@ import javax.mail.internet.InternetHeaders;
import javax.mail.internet.MailDateFormat;
import javax.mail.internet.MimeUtility;
import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_INDIVIDUAL;
import static org.w3c.css.sac.Condition.SAC_CLASS_CONDITION;
public class HtmlHelper {
static final int PREVIEW_SIZE = 500; // characters
@ -2625,7 +2625,14 @@ public class HtmlHelper {
case "text-align":
// https://developer.mozilla.org/en-US/docs/Web/CSS/text-align
Layout.Alignment alignment = null;
boolean rtl = TextDirectionHeuristics.FIRSTSTRONG_LTR.isRtl(ssb, start, ssb.length() - start);
boolean rtl;
try {
rtl = TextDirectionHeuristics.FIRSTSTRONG_LTR.isRtl(ssb, start, ssb.length() - start);
} catch (Throwable ex) {
// IllegalArgumentException
Log.e(ex);
rtl = false;
}
switch (value) {
case "left":
case "start":