From 2b46a16c075d51eaffce7167c8c2539c0feb19b5 Mon Sep 17 00:00:00 2001 From: shirshasa Date: Tue, 1 Jun 2021 18:02:53 +0300 Subject: [PATCH] epub converter: fix colors - add rgba - fix converting to nearest white if not white --- src/util/color_reader.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/color_reader.py b/src/util/color_reader.py index 626b711..45cc8dd 100644 --- a/src/util/color_reader.py +++ b/src/util/color_reader.py @@ -44,9 +44,10 @@ def get_hex_color_name(color): def str2color_name(s: str): if 'rgb' in s: - s = s.replace('rgb', '').replace('(', '').replace(')', '') + rgb_str = 'rgba' if ('rgba' in s) else 'rgb' + s = s.replace(rgb_str, '').replace('(', '').replace(')', '') try: - rgb = [int(x) for x in s.split(',')] + rgb = [int(x) for x in s.split(',')[:3]] rgb = tuple(rgb) except ValueError: return '' @@ -57,6 +58,11 @@ def str2color_name(s: str): elif '#' in s: name = get_hex_color_name(s) + if (name == 'white') and (s.lower() not in ['#ffffff', '#fff']): + return 'gray' + if name == 'grey': + return 'gray' + return name elif s in html4_hex_to_names.items():