Пример #1
0
 def do_test(self):
     decl = safe_parser().parseString(self.value)
     transform_sheet(self.rules, decl)
     css = decl.cssText
     if isinstance(css, bytes):
         css = css.decode('utf-8')
     self.set_result(css)
Пример #2
0
 def do_test(self):
     decl = safe_parser().parseString(self.value)
     transform_sheet(self.rules, decl)
     css = decl.cssText
     if isinstance(css, bytes):
         css = css.decode('utf-8')
     self.result.load_text('/* %s */\n\n%s' % (_('Resulting stylesheet'), css), 'css')
Пример #3
0
 def do_test(self):
     decl = safe_parser().parseString(self.value)
     transform_sheet(self.rules, decl)
     css = decl.cssText
     if isinstance(css, bytes):
         css = css.decode('utf-8')
     self.result.load_text('/* %s */\n\n%s' % (_('Resulting stylesheet'), css), 'css')
Пример #4
0
 def replace_css(self, css):
     manifest = self.oeb.manifest
     for item in manifest.values():
         if item.media_type in OEB_STYLES:
             manifest.remove(item)
     id, href = manifest.generate('css', 'stylesheet.css')
     sheet = css_parser.parseString(css, validate=False)
     if self.transform_css_rules:
         from calibre.ebooks.css_transform_rules import transform_sheet
         transform_sheet(self.transform_css_rules, sheet)
     item = manifest.add(id, href, CSS_MIME, data=sheet)
     self.oeb.manifest.main_stylesheet = item
     return href
Пример #5
0
    def collect_global_css(self):
        global_css = defaultdict(list)
        for item in self.items:
            stylizer = self.stylizers[item]
            if float(self.context.margin_top) >= 0:
                stylizer.page_rule['margin-top'] = '%gpt'%\
                        float(self.context.margin_top)
            if float(self.context.margin_bottom) >= 0:
                stylizer.page_rule['margin-bottom'] = '%gpt'%\
                        float(self.context.margin_bottom)
            items = sorted(stylizer.page_rule.items())
            css = ';\n'.join("%s: %s" % (key, val) for key, val in items)
            css = ('@page {\n%s\n}\n' % css) if items else ''
            rules = [
                css_text(r)
                for r in stylizer.font_face_rules + self.embed_font_rules
            ]
            raw = '\n\n'.join(rules)
            css += '\n\n' + raw
            global_css[css].append(item)

        gc_map = {}
        manifest = self.oeb.manifest
        for css in global_css:
            href = None
            if css.strip():
                id_, href = manifest.generate('page_css', 'page_styles.css')
                sheet = css_parser.parseString(css, validate=False)
                if self.transform_css_rules:
                    from calibre.ebooks.css_transform_rules import transform_sheet
                    transform_sheet(self.transform_css_rules, sheet)
                manifest.add(id_, href, CSS_MIME, data=sheet)
            gc_map[css] = href

        ans = {}
        for css, items in iteritems(global_css):
            for item in items:
                ans[item] = gc_map[css]
        return ans
Пример #6
0
    def collect_global_css(self):
        global_css = defaultdict(list)
        for item in self.oeb.spine:
            stylizer = self.stylizers[item]
            if float(self.context.margin_top) >= 0:
                stylizer.page_rule['margin-top'] = '%gpt'%\
                        float(self.context.margin_top)
            if float(self.context.margin_bottom) >= 0:
                stylizer.page_rule['margin-bottom'] = '%gpt'%\
                        float(self.context.margin_bottom)
            items = sorted(stylizer.page_rule.items())
            css = ';\n'.join("%s: %s" % (key, val) for key, val in items)
            css = ('@page {\n%s\n}\n'%css) if items else ''
            rules = [r.cssText for r in stylizer.font_face_rules +
                    self.embed_font_rules]
            raw = '\n\n'.join(rules)
            css += '\n\n' + raw
            global_css[css].append(item)

        gc_map = {}
        manifest = self.oeb.manifest
        for css in global_css:
            href = None
            if css.strip():
                id_, href = manifest.generate('page_css', 'page_styles.css')
                sheet = cssutils.parseString(css, validate=False)
                if self.transform_css_rules:
                    from calibre.ebooks.css_transform_rules import transform_sheet
                    transform_sheet(self.transform_css_rules, sheet)
                manifest.add(id_, href, CSS_MIME, data=sheet)
            gc_map[css] = href

        ans = {}
        for css, items in global_css.iteritems():
            for item in items:
                ans[item] = gc_map[css]
        return ans
Пример #7
0
 def do_test(self):
     decl = safe_parser().parseString(self.value)
     transform_sheet(self.rules, decl)
     self.result.load_text(
         '/* %s */\n\n%s' % (_('Resulting stylesheet'), decl.cssText),
         'css')
Пример #8
0
 def do_test(self):
     decl = safe_parser().parseString(self.value)
     transform_sheet(self.rules, decl)
     self.result.load_text('/* %s */\n\n%s' % (_('Resulting stylesheet'), decl.cssText), 'css')