mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Conversion: Add support for the CSS3 rem font size unit
This commit is contained in:
parent
58ac84cb57
commit
d7a206c563
@ -133,7 +133,8 @@ def render_html(path_to_html, width=590, height=750, as_xhtml=True):
|
|||||||
from PyQt4.QtWebKit import QWebPage
|
from PyQt4.QtWebKit import QWebPage
|
||||||
from PyQt4.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
|
from PyQt4.Qt import QEventLoop, QPalette, Qt, QUrl, QSize
|
||||||
from calibre.gui2 import is_ok_to_use_qt
|
from calibre.gui2 import is_ok_to_use_qt
|
||||||
if not is_ok_to_use_qt(): return None
|
if not is_ok_to_use_qt():
|
||||||
|
return None
|
||||||
path_to_html = os.path.abspath(path_to_html)
|
path_to_html = os.path.abspath(path_to_html)
|
||||||
with CurrentDir(os.path.dirname(path_to_html)):
|
with CurrentDir(os.path.dirname(path_to_html)):
|
||||||
page = QWebPage()
|
page = QWebPage()
|
||||||
@ -214,9 +215,9 @@ def calibre_cover(title, author_string, series_string=None,
|
|||||||
if cleanup:
|
if cleanup:
|
||||||
os.remove(font_path)
|
os.remove(font_path)
|
||||||
|
|
||||||
UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc)$')
|
UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc|rem)$')
|
||||||
|
|
||||||
def unit_convert(value, base, font, dpi):
|
def unit_convert(value, base, font, dpi, body_font_size=12):
|
||||||
' Return value in pts'
|
' Return value in pts'
|
||||||
if isinstance(value, (int, long, float)):
|
if isinstance(value, (int, long, float)):
|
||||||
return value
|
return value
|
||||||
@ -250,6 +251,8 @@ def unit_convert(value, base, font, dpi):
|
|||||||
result = value * 2.8346456693
|
result = value * 2.8346456693
|
||||||
elif unit == 'cm':
|
elif unit == 'cm':
|
||||||
result = value * 28.346456693
|
result = value * 28.346456693
|
||||||
|
elif unit == 'rem':
|
||||||
|
result = value * body_font_size
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def generate_masthead(title, output_path=None, width=600, height=60):
|
def generate_masthead(title, output_path=None, width=600, height=60):
|
||||||
|
@ -210,6 +210,7 @@ class Stylizer(object):
|
|||||||
if self.profile is None:
|
if self.profile is None:
|
||||||
# Just in case the default profile is removed in the future :)
|
# Just in case the default profile is removed in the future :)
|
||||||
self.profile = opts.output_profile
|
self.profile = opts.output_profile
|
||||||
|
self.body_font_size = self.profile.fbase
|
||||||
self.logger = oeb.logger
|
self.logger = oeb.logger
|
||||||
item = oeb.manifest.hrefs[path]
|
item = oeb.manifest.hrefs[path]
|
||||||
basename = os.path.basename(path)
|
basename = os.path.basename(path)
|
||||||
@ -630,7 +631,7 @@ class Style(object):
|
|||||||
base = self.width
|
base = self.width
|
||||||
if not font and font != 0:
|
if not font and font != 0:
|
||||||
font = self.fontSize
|
font = self.fontSize
|
||||||
return unit_convert(value, base, font, self._profile.dpi)
|
return unit_convert(value, base, font, self._profile.dpi, body_font_size=self._stylizer.body_font_size)
|
||||||
|
|
||||||
def pt_to_px(self, value):
|
def pt_to_px(self, value):
|
||||||
return (self._profile.dpi / 72.0) * value
|
return (self._profile.dpi / 72.0) * value
|
||||||
|
@ -310,6 +310,8 @@ class CSSFlattener(object):
|
|||||||
except:
|
except:
|
||||||
font_size = self.sbase if self.sbase is not None else \
|
font_size = self.sbase if self.sbase is not None else \
|
||||||
self.context.source.fbase
|
self.context.source.fbase
|
||||||
|
if tag == 'body' and isinstance(font_size, (int, float)):
|
||||||
|
stylizer.body_font_size = font_size
|
||||||
if 'align' in node.attrib:
|
if 'align' in node.attrib:
|
||||||
if tag != 'img':
|
if tag != 'img':
|
||||||
cssdict['text-align'] = node.attrib['align']
|
cssdict['text-align'] = node.attrib['align']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user