aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-07-06 13:55:34 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-07-06 13:55:34 +0100
commit547fefa3664eee4839552757a6b3810444127671 (patch)
tree9ecec5d82552cfce6835b62499ee002d4adf76b6
parent070b57bd415d0e4df3d7d311bcce0ce841505b9b (diff)
downloadrspamd-547fefa3664eee4839552757a6b3810444127671.tar.gz
rspamd-547fefa3664eee4839552757a6b3810444127671.zip
[Fix] Fix visibility calculations
-rw-r--r--src/libserver/css/css_rule.cxx3
-rw-r--r--src/libserver/html/html_block.hxx50
2 files changed, 39 insertions, 14 deletions
diff --git a/src/libserver/css/css_rule.cxx b/src/libserver/css/css_rule.cxx
index d8c3a04dd..17301e724 100644
--- a/src/libserver/css/css_rule.cxx
+++ b/src/libserver/css/css_rule.cxx
@@ -413,7 +413,8 @@ css_declarations_block::compile_to_block(rspamd_mempool_t *pool) const -> rspamd
opacity = vals.back().to_number().value_or(opacity);
break;
}
- case css_property_type::PROPERTY_FONT_COLOR: {
+ case css_property_type::PROPERTY_FONT_COLOR:
+ case css_property_type::PROPERTY_COLOR: {
auto color = vals.back().to_color();
if (color) {
block->set_fgcolor(color.value());
diff --git a/src/libserver/html/html_block.hxx b/src/libserver/html/html_block.hxx
index f2bbf1d64..28ab3bae1 100644
--- a/src/libserver/html/html_block.hxx
+++ b/src/libserver/html/html_block.hxx
@@ -179,6 +179,21 @@ struct html_block {
}
}
+ auto is_similar_colors = [](const rspamd::css::css_color &fg, const rspamd::css::css_color &bg) -> bool {
+ auto diff_r = std::abs(fg.r - bg.r);
+ auto diff_g = std::abs(fg.g - bg.g);
+ auto diff_b = std::abs(fg.b - bg.b);
+ auto ravg = (fg.r + bg.r) / 2.0;
+
+ diff_r *= diff_r;
+ diff_g *= diff_g;
+ diff_b *= diff_b;
+
+ auto diff = std::sqrt(2.0 * diff_r + 4.0 * diff_g + 3.0 * diff_b +
+ (ravg * (diff_r - diff_b) / 256.0)) / 256.0;
+
+ return diff < 0.1;
+ };
/* Check if we have both bg/fg colors */
if ((mask & (bg_color_mask|fg_color_mask)) == (bg_color_mask|fg_color_mask)) {
if (fg_color.alpha < 10) {
@@ -189,24 +204,33 @@ struct html_block {
}
if (bg_color.alpha > 10) {
- auto diff_r = std::abs(fg_color.r - bg_color.r);
- auto diff_g = std::abs(fg_color.g - bg_color.g);
- auto diff_b = std::abs(fg_color.b - bg_color.b);
- auto ravg = (fg_color.r + bg_color.r) / 2.0;
-
- diff_r *= diff_r;
- diff_g *= diff_g;
- diff_b *= diff_b;
-
- auto diff = std::sqrt(2.0 * diff_r + 4.0 * diff_g + 3.0 * diff_b +
- (ravg * (diff_r - diff_b) / 256.0)) / 256.0;
-
- if (diff < 0.1) {
+ if (is_similar_colors(fg_color, bg_color)) {
mask |= invisible_flag|transparent_flag;
return;
}
}
}
+ else if (mask & fg_color_mask) {
+ /* Merely fg color */
+ if (fg_color.alpha < 10) {
+ /* Too transparent */
+ mask |= invisible_flag|transparent_flag;
+
+ return;
+ }
+
+ /* Implicit fg color */
+ if (is_similar_colors(fg_color, rspamd::css::css_color::white())) {
+ mask |= invisible_flag|transparent_flag;
+ return;
+ }
+ }
+ else if (mask & bg_color_mask) {
+ if (is_similar_colors(rspamd::css::css_color::black(), bg_color)) {
+ mask |= invisible_flag|transparent_flag;
+ return;
+ }
+ }
mask &= ~(invisible_flag|transparent_flag);
}