[devdocsgjs/main: 397/1867] Improve dark icon fix detection
- From: Andy Holmes <andyholmes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devdocsgjs/main: 397/1867] Improve dark icon fix detection
- Date: Fri, 19 Nov 2021 23:47:14 +0000 (UTC)
commit 9551fbc29e5e0a6d0bd9e47441036c227cbc38e6
Author: Jasper van Merle <jaspervmerle gmail com>
Date: Mon Sep 17 20:05:47 2018 +0200
Improve dark icon fix detection
lib/tasks/sprites.thor | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/lib/tasks/sprites.thor b/lib/tasks/sprites.thor
index 251a9327..64dd82b4 100644
--- a/lib/tasks/sprites.thor
+++ b/lib/tasks/sprites.thor
@@ -95,12 +95,13 @@ class SpritesCLI < Thor
def needs_dark_icon_fix(icon, bg_color)
# Determine whether the icon needs to be grayscaled if the user has enabled the dark theme
- # The logic comes from https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast
- contrast = icon.pixels.map do |pixel|
+ # The logic is roughly based on https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast
+ contrast = icon.pixels.select {|pixel| ChunkyPNG::Color.a(pixel) > 0}.map do |pixel|
get_contrast(bg_color, pixel)
end
- contrast.max < 7
+ avg = contrast.reduce(:+) / contrast.size.to_f
+ avg < 3.5
end
def get_contrast(base, other)
@@ -173,7 +174,8 @@ class SpritesCLI < Thor
def log_details(items_with_icons, icons_per_row)
logger.debug("Amount of icons: #{items_with_icons.length}")
- logger.debug("Icons per row: #{icons_per_row}")
+ logger.debug("Amount of icons needing the dark icon fix: #{items_with_icons.count {|item|
item[:dark_icon_fix]}}")
+ logger.debug("Amount of icons per row: #{icons_per_row}")
max_type_length = items_with_icons.map {|item| item[:type].length}.max
border = "+#{'-' * (max_type_length + 2)}+#{'-' * 5}+#{'-' * 8}+#{'-' * 15}+"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]