def find_usage_in(self, elem, inherited_style, ff_rules): style = elem_style(self.style_rules, elem.get('class', '') or '', inherited_style) for child in elem: self.find_usage_in(child, style, ff_rules) has_font, existing = used_font(style, ff_rules) if not has_font: return if existing is None: in_book = used_font(style, self.embedded_fonts)[1] if in_book is None: # Try to find the font in the system added = self.embed_font(style) if added is not None: ff_rules.append(added) self.embedded_fonts.append(added) else: # TODO: Create a page rule from the book rule (cannot use it # directly as paths might be different) item = in_book['item'] sheet = self.parser.parseString(in_book['rule'].cssText, validate=False) rule = sheet.cssRules[0] page_sheet = self.get_page_sheet() href = page_sheet.abshref(item.href) rule.style.setProperty('src', 'url(%s)' % href) ff_rules.append(find_font_face_rules(sheet, self.oeb)[0]) page_sheet.data.insertRule(rule, len(page_sheet.data.cssRules))
def find_usage_in(self, elem, inherited_style, ff_rules): style = elem_style(self.style_rules, elem.get('class', '') or '', inherited_style) for child in elem: self.find_usage_in(child, style, ff_rules) has_font, existing = used_font(style, ff_rules) if not has_font: return if existing is None: in_book = used_font(style, self.embedded_fonts)[1] if in_book is None: # Try to find the font in the system added = self.embed_font(style) if added is not None: ff_rules.append(added) self.embedded_fonts.append(added) else: # TODO: Create a page rule from the book rule (cannot use it # directly as paths might be different) item = in_book['item'] sheet = self.parser.parseString(in_book['rule'].cssText, validate=False) rule = sheet.cssRules[0] page_sheet = self.get_page_sheet() href = page_sheet.abshref(item.href) rule.style.setProperty('src', 'url(%s)' % href) ff_rules.append(find_font_face_rules(sheet, self.oeb)[0]) page_sheet.data.insertRule(rule, len(page_sheet.data.cssRules))