forked from LiveCarta/BookConverter
Add inches->px converter
This commit is contained in:
@@ -57,7 +57,7 @@ class CSSPreprocessor:
|
|||||||
def convert_tag_style_values(size_value: str, is_indent: bool = False) -> str:
|
def convert_tag_style_values(size_value: str, is_indent: bool = False) -> str:
|
||||||
"""
|
"""
|
||||||
Function
|
Function
|
||||||
- converts values of tags from em/%/pt to px
|
- converts values of tags from em/%/pt/in to px
|
||||||
- find closest font-size px
|
- find closest font-size px
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
@@ -71,7 +71,7 @@ class CSSPreprocessor:
|
|||||||
converted value size
|
converted value size
|
||||||
"""
|
"""
|
||||||
size_regexp = re.compile(
|
size_regexp = re.compile(
|
||||||
r"(^-*(\d*\.*\d+)%$)|(^-*(\d*\.*\d+)em$)|(^-*(\d*\.*\d+)pt$)")
|
r"(^-*(\d*\.*\d+)%$)|(^-*(\d*\.*\d+)em$)|(^-*(\d*\.*\d+)pt$)|(^-*(\d*\.*\d+)in$)")
|
||||||
has_style_attrs = re.search(size_regexp, size_value)
|
has_style_attrs = re.search(size_regexp, size_value)
|
||||||
if has_style_attrs:
|
if has_style_attrs:
|
||||||
if has_style_attrs.group(1):
|
if has_style_attrs.group(1):
|
||||||
@@ -85,6 +85,9 @@ class CSSPreprocessor:
|
|||||||
elif has_style_attrs.group(5):
|
elif has_style_attrs.group(5):
|
||||||
size_value = float(size_value.replace("pt", "")) * 4/3
|
size_value = float(size_value.replace("pt", "")) * 4/3
|
||||||
return str(size_value)+'px'
|
return str(size_value)+'px'
|
||||||
|
elif has_style_attrs.group(7):
|
||||||
|
size_value = float(size_value.replace("in", "")) * 96
|
||||||
|
return str(size_value)+'px'
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
return size_value
|
return size_value
|
||||||
|
|||||||
Reference in New Issue
Block a user