forked from LiveCarta/BookConverter
RGB processing
This commit is contained in:
@@ -5,7 +5,7 @@ from ebooklib import epub
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from itertools import takewhile
|
from itertools import takewhile
|
||||||
|
|
||||||
from src.util.color_reader import str2hex
|
from src.util.color_reader import str2hex, rgb2color_name
|
||||||
from src.livecarta_config import LiveCartaConfig
|
from src.livecarta_config import LiveCartaConfig
|
||||||
|
|
||||||
|
|
||||||
@@ -129,8 +129,7 @@ LIVECARTA_STYLE_ATTRS_MAPPING = {
|
|||||||
'font-variant': lambda x: x,
|
'font-variant': lambda x: x,
|
||||||
'text-align': lambda x: x,
|
'text-align': lambda x: x,
|
||||||
'font': lambda x: '',
|
'font': lambda x: '',
|
||||||
'font-family': lambda x: LiveCartaConfig.FONT_CORRESPONDANCE_TABLE.get(x) or
|
'font-family': lambda x: LiveCartaConfig.FONT_CORRESPONDANCE_TABLE.get(re.sub(r"^\s+|\s+$", "", x.title())),
|
||||||
LiveCartaConfig.FONT_CORRESPONDANCE_TABLE.get(x.capitalize()),
|
|
||||||
'font-size': convert_tag_style_values,
|
'font-size': convert_tag_style_values,
|
||||||
'color': get_text_color,
|
'color': get_text_color,
|
||||||
'background-color': get_bg_color,
|
'background-color': get_bg_color,
|
||||||
@@ -198,7 +197,7 @@ def update_css_styles_to_livecarta_convention(css_rule: cssutils.css.CSSStyleRul
|
|||||||
css_rule.style[style_type.name] = ''
|
css_rule.style[style_type.name] = ''
|
||||||
return
|
return
|
||||||
|
|
||||||
cleaned_value = style_type.value.replace('\"', '').split(', ')[-1]
|
cleaned_value = style_type.value.replace('\"', '')
|
||||||
constraints_on_value = LIVECARTA_STYLE_ATTRS.get(
|
constraints_on_value = LIVECARTA_STYLE_ATTRS.get(
|
||||||
style_type.name)
|
style_type.name)
|
||||||
value_not_in_possible_values_list = cleaned_value not in LIVECARTA_STYLE_ATTRS[
|
value_not_in_possible_values_list = cleaned_value not in LIVECARTA_STYLE_ATTRS[
|
||||||
@@ -215,7 +214,7 @@ def update_css_styles_to_livecarta_convention(css_rule: cssutils.css.CSSStyleRul
|
|||||||
|
|
||||||
def build_css_file_content(css_content: str) -> str:
|
def build_css_file_content(css_content: str) -> str:
|
||||||
"""Build css content with livecarta convention"""
|
"""Build css content with livecarta convention"""
|
||||||
sheet = cssutils.parseString(css_content, validate=False)
|
sheet = cssutils.parseString(css_content.lower(), validate=False)
|
||||||
|
|
||||||
for css_rule in sheet:
|
for css_rule in sheet:
|
||||||
if css_rule.type == css_rule.STYLE_RULE:
|
if css_rule.type == css_rule.STYLE_RULE:
|
||||||
|
|||||||
@@ -103,11 +103,10 @@ def str2hex(s: str):
|
|||||||
return rgb_percent_to_hex((r, g, b))
|
return rgb_percent_to_hex((r, g, b))
|
||||||
|
|
||||||
if 'rgb' in s:
|
if 'rgb' in s:
|
||||||
match = re.search(r'rgba*\(((\d+), *(\d+), *(\d+), (\d\.\d+)*)\)', s)
|
rgba = re.findall('([0-9] *\.?[0-9]+)', s)
|
||||||
if match:
|
r, g, b = int(rgba[0]), int(rgba[1]), int(rgba[2])
|
||||||
r, g, b = int(match.group(2)), int(match.group(3)), int(match.group(4))
|
if len(rgba) == 4:
|
||||||
if match.group(5):
|
alpha = float(rgba[3])
|
||||||
alpha = float(match.group(5))
|
|
||||||
r, g, b = rgba2rgb(r, g, b, alpha)
|
r, g, b = rgba2rgb(r, g, b, alpha)
|
||||||
return rgb_to_hex((r, g, b))
|
return rgb_to_hex((r, g, b))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user