Fixed "censored" background color

This commit is contained in:
M66B 2021-08-03 07:55:41 +02:00
parent ab3a06dd20
commit 9b23a59cde
1 changed files with 6 additions and 11 deletions

View File

@ -130,7 +130,7 @@ public class HtmlHelper {
private static final int DEFAULT_FONT_SIZE = 16; // pixels private static final int DEFAULT_FONT_SIZE = 16; // pixels
private static final int DEFAULT_FONT_SIZE_PT = 12; // points private static final int DEFAULT_FONT_SIZE_PT = 12; // points
private static final int GRAY_THRESHOLD = Math.round(255 * 0.2f); private static final int GRAY_THRESHOLD = Math.round(255 * 0.2f);
private static final int COLOR_THRESHOLD = Math.round(255 * 0.1f); private static final double BG_LUM_THRESHOLD = 0.1;
private static final float MIN_LUMINANCE = 0.7f; private static final float MIN_LUMINANCE = 0.7f;
private static final int TAB_SIZE = 2; private static final int TAB_SIZE = 2;
private static final int MAX_ALT = 250; private static final int MAX_ALT = 250;
@ -626,8 +626,11 @@ public class HtmlHelper {
if (color != null) if (color != null)
element.attr("x-color", "true"); element.attr("x-color", "true");
} else /* background */ { } else /* background */ {
if (color != null && !hasColor(color)) if (color != null && view) {
continue; double lum = ColorUtils.calculateLuminance(color);
if (dark ? lum < BG_LUM_THRESHOLD : lum > 1 - BG_LUM_THRESHOLD)
color = Color.TRANSPARENT;
}
if (color != null) if (color != null)
element.attr("x-background", "true"); element.attr("x-background", "true");
@ -1704,14 +1707,6 @@ public class HtmlHelper {
return color; return color;
} }
private static boolean hasColor(int color) {
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
return (Math.abs(r - g) >= COLOR_THRESHOLD ||
Math.abs(r - b) >= COLOR_THRESHOLD);
}
// https://tools.ietf.org/html/rfc3676 // https://tools.ietf.org/html/rfc3676
static String flow(String text) { static String flow(String text) {
boolean continuation = false; boolean continuation = false;