1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 12:44:42 +00:00

Apply styles first

This commit is contained in:
M66B 2020-04-28 09:14:22 +02:00
parent 71a14bfea7
commit 9a14026def

View file

@ -1890,6 +1890,38 @@ public class HtmlHelper {
int start = Integer.parseInt(element.attr("start-index"));
if (debug)
ssb.append("[/" + element.tagName() + "]");
// Apply style
String style = element.attr("style");
if (!TextUtils.isEmpty(style)) {
String[] params = style.split(";");
for (String param : params) {
int semi = param.indexOf(":");
if (semi < 0)
continue;
String key = param.substring(0, semi);
String value = param.substring(semi + 1);
switch (key) {
case "color":
int color = Integer.parseInt(value.substring(1), 16) | 0xFF000000;
ssb.setSpan(new ForegroundColorSpan(color), start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
case "text-decoration":
if ("line-through".equals(value))
ssb.setSpan(new StrikethroughSpan(), start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
}
}
}
// Apply calculated font size
String xFontSize = element.attr("x-font-size");
if (!TextUtils.isEmpty(xFontSize)) {
int size = Helper.dp2pixels(context, Math.round(Float.parseFloat(xFontSize) * DEFAULT_FONT_SIZE));
ssb.setSpan(new AbsoluteSizeSpan(size), start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
// Apply element
switch (element.tagName()) {
case "a":
String href = element.attr("href");
@ -2003,34 +2035,6 @@ public class HtmlHelper {
default:
Log.e("Unknown tag=" + element.tagName());
}
String style = element.attr("style");
if (!TextUtils.isEmpty(style)) {
String[] params = style.split(";");
for (String param : params) {
int semi = param.indexOf(":");
if (semi < 0)
continue;
String key = param.substring(0, semi);
String value = param.substring(semi + 1);
switch (key) {
case "color":
int color = Integer.parseInt(value.substring(1), 16) | 0xFF000000;
ssb.setSpan(new ForegroundColorSpan(color), start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
case "text-decoration":
if ("line-through".equals(value))
ssb.setSpan(new StrikethroughSpan(), start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
}
}
}
String xFontSize = element.attr("x-font-size");
if (!TextUtils.isEmpty(xFontSize)) {
int size = Helper.dp2pixels(context, Math.round(Float.parseFloat(xFontSize) * DEFAULT_FONT_SIZE));
ssb.setSpan(new AbsoluteSizeSpan(size), start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
@ -2042,7 +2046,6 @@ public class HtmlHelper {
return;
ssb.insert(index, "\n");
}
}, document.body());
if (debug)