Annotations in Epub converter

This commit is contained in:
Kiryl
2022-08-03 14:39:13 +03:00
parent 7453029295
commit 78e3ad8911
16 changed files with 259 additions and 192 deletions

View File

@@ -1,5 +1,5 @@
import re
from typing import Tuple
from colorsys import hls_to_rgb
from webcolors import html4_hex_to_names, hex_to_rgb, rgb_to_name, rgb_percent_to_hex, rgb_to_hex, css3_names_to_hex
@@ -48,7 +48,7 @@ def hex2color_name(color):
return closest_name
def str2closest_html_color_name(s: str):
def str2closest_html_color_name(s: str) -> str:
""" Transform str -> closest color name """
if 'rgb' in s:
rgb_str = 'rgba' if ('rgba' in s) else 'rgb'
@@ -82,7 +82,7 @@ def str2closest_html_color_name(s: str):
return ''
def rgba2rgb(r, g, b, alpha):
def rgba2rgb(r: int, g: int, b: int, alpha: float) -> Tuple[int, int, int]:
""" Transform rgba -> rgb """
r_background, g_background, b_background = 255, 255, 255
r_new = int((1 - alpha) * r_background + alpha * r)
@@ -91,7 +91,7 @@ def rgba2rgb(r, g, b, alpha):
return r_new, g_new, b_new
def str2hex(s: str):
def str2hex(s: str) -> str:
""" Transform str -> hex """
if '#' in s and (len(s) <= 7):
return s.lower()
@@ -131,7 +131,6 @@ def str2hex(s: str):
if __name__ == '__main__':
colors = [
(75, 0, 130), (255, 0, 255),
(139, 69, 19), (46, 139, 87),