def __call__(self, container): changed = False for name, mt in container.mime_map.iteritems(): if mt in OEB_STYLES: sheet = container.parsed(name) if fix_sheet(sheet, self.css_name, self.font_name): container.dirty(name) changed = True elif mt in OEB_DOCS: for style in container.parsed(name).xpath( '//*[local-name()="style"]'): if style.get('type', 'text/css') == 'text/css' and style.text: sheet = container.parse_css(style.text) if fix_sheet(sheet, self.css_name, self.font_name): style.text = force_unicode(sheet.cssText, 'utf-8') pretty_script_or_style(container, style) container.dirty(name) changed = True for elem in container.parsed(name).xpath( '//*[@style and contains(@style, "font-family")]'): style = container.parse_css(elem.get('style'), is_declaration=True) if change_font_in_declaration(style, self.css_name, self.font_name): elem.set( 'style', force_unicode(style.cssText, 'utf-8').replace('\n', ' ')) container.dirty(name) changed = True return changed
def fix_sheet(sheet, css_name, font_name): changed = False for rule in sheet.cssRules: if rule.type in (CSSRule.FONT_FACE_RULE, CSSRule.STYLE_RULE): changed = change_font_in_declaration(rule.style, css_name, font_name) or changed return changed
def __call__(self, container): changed = False for name, mt in container.mime_map.iteritems(): if mt in OEB_STYLES: sheet = container.parsed(name) if fix_sheet(sheet, self.css_name, self.font_name): container.dirty(name) changed = True elif mt in OEB_DOCS: for style in container.parsed(name).xpath('//*[local-name()="style"]'): if style.get('type', 'text/css') == 'text/css' and style.text: sheet = container.parse_css(style.text) if fix_sheet(sheet, self.css_name, self.font_name): style.text = force_unicode(sheet.cssText, 'utf-8') pretty_script_or_style(container, style) container.dirty(name) changed = True for elem in container.parsed(name).xpath('//*[@style and contains(@style, "font-family")]'): style = container.parse_css(elem.get('style'), is_declaration=True) if change_font_in_declaration(style, self.css_name, self.font_name): elem.set('style', force_unicode(style.cssText, 'utf-8').replace('\n', ' ')) container.dirty(name) changed = True return changed