def find_style_rules(self): ''' Extract all font related style information from all stylesheets into a dict mapping classes to font properties specified by that class. All the heavy lifting has already been done by the CSS flattening code. ''' rules = defaultdict(dict) for item in self.oeb.manifest: if not hasattr(item.data, 'cssRules'): continue for i, rule in enumerate(item.data.cssRules): if rule.type != rule.STYLE_RULE: continue props = {k:v for k,v in get_font_properties(rule).iteritems() if v} if not props: continue for sel in rule.selectorList: sel = sel.selectorText if sel and sel.startswith('.'): # We dont care about pseudo-selectors as the worst that # can happen is some extra characters will remain in # the font sel = sel.partition(':')[0] rules[sel[1:]].update(props) self.style_rules = dict(rules)
def find_style_rules(self): ''' Extract all font related style information from all stylesheets into a dict mapping classes to font properties specified by that class. All the heavy lifting has already been done by the CSS flattening code. ''' rules = defaultdict(dict) for item in self.oeb.manifest: if not hasattr(item.data, 'cssRules'): continue for i, rule in enumerate(item.data.cssRules): if rule.type != rule.STYLE_RULE: continue props = { k: v for k, v in get_font_properties(rule).iteritems() if v } if not props: continue for sel in rule.selectorList: sel = sel.selectorText if sel and sel.startswith('.'): # We dont care about pseudo-selectors as the worst that # can happen is some extra characters will remain in # the font sel = sel.partition(':')[0] rules[sel[1:]].update(props) self.style_rules = dict(rules)