mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Fix #2022847 [ValueError](https://bugs.launchpad.net/calibre/+bug/2022847)
This commit is contained in:
parent
1317d39592
commit
c895bb59ce
@ -6,7 +6,12 @@ Code for the conversion of ebook formats and the reading of metadata
|
|||||||
from various formats.
|
from various formats.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os, re, numbers, sys
|
import numbers
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
from contextlib import suppress
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
|
|
||||||
@ -48,7 +53,7 @@ def return_raster_image(path):
|
|||||||
|
|
||||||
|
|
||||||
def extract_cover_from_embedded_svg(html, base, log):
|
def extract_cover_from_embedded_svg(html, base, log):
|
||||||
from calibre.ebooks.oeb.base import XPath, SVG, XLINK
|
from calibre.ebooks.oeb.base import SVG, XLINK, XPath
|
||||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||||
root = safe_xml_fromstring(html)
|
root = safe_xml_fromstring(html)
|
||||||
|
|
||||||
@ -114,7 +119,7 @@ def render_html_svg_workaround(path_to_html, log, width=590, height=750, root=''
|
|||||||
|
|
||||||
def render_html_data(path_to_html, width, height, root=''):
|
def render_html_data(path_to_html, width, height, root=''):
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
|
from calibre.utils.ipc.simple_worker import WorkerError, fork_job
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
def report_error(text=''):
|
def report_error(text=''):
|
||||||
@ -173,14 +178,15 @@ def unit_convert(value, base, font, dpi, body_font_size=12):
|
|||||||
' Return value in pts'
|
' Return value in pts'
|
||||||
if isinstance(value, numbers.Number):
|
if isinstance(value, numbers.Number):
|
||||||
return value
|
return value
|
||||||
try:
|
with suppress(Exception):
|
||||||
return float(value) * 72.0 / dpi
|
return float(value) * 72.0 / dpi
|
||||||
except:
|
|
||||||
pass
|
|
||||||
result = value
|
result = value
|
||||||
m = UNIT_RE.match(value)
|
m = UNIT_RE.match(value)
|
||||||
if m is not None and m.group(1):
|
if m is not None and m.group(1):
|
||||||
value = float(m.group(1))
|
try:
|
||||||
|
value = float(m.group(1))
|
||||||
|
except ValueError:
|
||||||
|
value = 0
|
||||||
unit = m.group(2)
|
unit = m.group(2)
|
||||||
if unit == '%':
|
if unit == '%':
|
||||||
result = (value / 100.0) * base
|
result = (value / 100.0) * base
|
||||||
|
Loading…
x
Reference in New Issue
Block a user