From bd62d2db4198a10679f7e24b71d8a555b11f136e Mon Sep 17 00:00:00 2001 From: Anomalocaridid <29845794+Anomalocaridid@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:58:58 -0500 Subject: [PATCH 1/2] fix: expand rgb colors along with rgba colors --- color_manager/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/color_manager/utils.py b/color_manager/utils.py index c03b157f..46db5ab6 100644 --- a/color_manager/utils.py +++ b/color_manager/utils.py @@ -156,12 +156,22 @@ def expand_css_rgba(match) -> str: int(match.group(3)), float(match.group(4)) )) +def expand_css_rgb(match) -> str: + """ Used by the css_to_hex function. """ + return rgb_to_hex(( + int(match.group(1)), int(match.group(2)), + int(match.group(3))) + ) + def css_to_hex(text:str) -> str: """ Returns the given string with css rgba functions and named colors substituted for their corresponding hexadecimal codes. """ text = re.sub(r"rgba\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\)", expand_css_rgba, text) + text = re.sub(r"rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)", + expand_css_rgb, text) + for key in name_to_hex_dict: text = re.sub(key + r"\b", name_to_hex_dict[key], text) From d7d9d8f105bc68a6635e41961699e2045d760839 Mon Sep 17 00:00:00 2001 From: Anomalocaridid <29845794+Anomalocaridid@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:39:59 -0500 Subject: [PATCH 2/2] fix: expand more color formats in svg files --- color_manager/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/color_manager/utils.py b/color_manager/utils.py index 46db5ab6..b0a3e70f 100644 --- a/color_manager/utils.py +++ b/color_manager/utils.py @@ -479,6 +479,8 @@ def recolor(src_path:str, dest_path:str, name:str, replacement) -> None: for path in tqdm(paths, desc="svg", disable=is_empty(paths)): with open(path, 'r') as file: x = file.read() + # .svg files use similar color formats to css + x = css_to_hex(x) x = expand_all_hex(x) colors = get_file_colors(x)