From d182cbbb79385712e92569b1d57c61aabdb7aaf2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 3 Aug 2009 11:30:08 -0600 Subject: [PATCH] EPUB Output: Pass through font-face rules. Fixes #3042 (Calibre ignores extra_css in recipe) --- src/calibre/ebooks/oeb/stylizer.py | 5 ++++- src/calibre/ebooks/oeb/transforms/flatcss.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index 1d3b0515d4..0c387e3e84 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -17,7 +17,7 @@ from weakref import WeakKeyDictionary from xml.dom import SyntaxErr as CSSSyntaxError import cssutils from cssutils.css import CSSStyleRule, CSSPageRule, CSSStyleDeclaration, \ - CSSValueList, cssproperties + CSSValueList, CSSFontFaceRule, cssproperties from cssutils import profile as cssprofiles from lxml import etree from lxml.cssselect import css_to_xpath, ExpressionError, SelectorSyntaxError @@ -119,6 +119,7 @@ class Stylizer(object): head = xpath(tree, '/h:html/h:head')[0] parser = cssutils.CSSParser(fetcher=self._fetch_css_file, log=logging.getLogger('calibre.css')) + self.font_face_rules = [] for elem in head: if elem.tag == XHTML('style') and elem.text \ and elem.get('type', CSS_MIME) in OEB_STYLES: @@ -210,6 +211,8 @@ class Stylizer(object): elif isinstance(rule, CSSPageRule): style = self.flatten_style(rule.style) self.page_rule.update(style) + elif isinstance(rule, CSSFontFaceRule): + self.font_face_rules.append(rule) return results def flatten_style(self, cssstyle): diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index 8ef5c42ea1..6ffd41ed9c 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -317,7 +317,10 @@ class CSSFlattener(object): items.sort() css = '; '.join("%s: %s" % (key, val) for key, val in items) style = etree.SubElement(head, XHTML('style'), type=CSS_MIME) - style.text = "@page { %s; }" % css + style.text = "\n\t\t@page { %s; }" % css + rules = [r.cssText for r in stylizer.font_face_rules] + for r in rules: + style.text += '\n\t\t'+r+'\n' def replace_css(self, css): manifest = self.oeb.manifest