From 96117bdba9cd156bb059ca96e82172c46ace4d5b Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 4 Aug 2021 09:42:41 +0200 Subject: [PATCH] Improved bg without fg --- app/src/main/java/eu/faircode/email/HtmlHelper.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 0829673f26..558d72fa65 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -637,7 +637,7 @@ public class HtmlHelper { if (color != null) element.attr("x-background", encodeWebColor(color)); - if (dark) { + if (color != null && dark) { boolean fg = false; if (text_color) { fg = (parseColor(kv.get("color")) != null); @@ -650,12 +650,15 @@ public class HtmlHelper { } // Dark theme, background color with no text color: - // force text color - if (!fg) + // force (inverse) text color + if (!fg) { + double lum = (color == Color.TRANSPARENT ? 0 : ColorUtils.calculateLuminance(color)); + int c = (lum < 0.5 ? textColorPrimary : textColorPrimaryInverse); sb.append("color") .append(':') - .append(encodeWebColor(textColorPrimaryInverse)) + .append(encodeWebColor(c)) .append(";"); + } } }