Esempio n. 1
0
 def collect_font_face_rules(self, container, processed, spine_name, sheet, sheet_name):
     if sheet_name in processed:
         sheet_rules = processed[sheet_name]
     else:
         sheet_rules = []
         if sheet_name != spine_name:
             processed[sheet_name] = sheet_rules
         for rule, base_name, rule_index in iterrules(container, sheet_name, rules=sheet, rule_type='FONT_FACE_RULE'):
             cssdict = {}
             for prop in iterdeclaration(rule.style):
                 if prop.name == 'font-family':
                     cssdict['font-family'] = [icu_lower(x) for x in parse_font_family(prop.propertyValue.cssText)]
                 elif prop.name.startswith('font-'):
                     cssdict[prop.name] = prop.propertyValue[0].value
                 elif prop.name == 'src':
                     for val in prop.propertyValue:
                         x = val.value
                         fname = container.href_to_name(x, sheet_name)
                         if container.has_name(fname):
                             cssdict['src'] = fname
                             break
                     else:
                         container.log.warn('The @font-face rule refers to a font file that does not exist in the book: %s' % prop.propertyValue.cssText)
             if 'src' not in cssdict:
                 continue
             ff = cssdict.get('font-family')
             if not ff or ff[0] in bad_fonts:
                 continue
             normalize_font_properties(cssdict)
             prepare_font_rule(cssdict)
             sheet_rules.append(cssdict)
     self.font_rule_map[spine_name].extend(sheet_rules)
Esempio n. 2
0
 def collect_font_face_rules(self, container, processed, spine_name, sheet, sheet_name):
     if sheet_name in processed:
         sheet_rules = processed[sheet_name]
     else:
         sheet_rules = []
         if sheet_name != spine_name:
             processed[sheet_name] = sheet_rules
         for rule, base_name, rule_index in iterrules(container, sheet_name, rules=sheet, rule_type='FONT_FACE_RULE'):
             cssdict = {}
             for prop in iterdeclaration(rule.style):
                 if prop.name == 'font-family':
                     cssdict['font-family'] = [icu_lower(x) for x in parse_font_family(prop.propertyValue.cssText)]
                 elif prop.name.startswith('font-'):
                     cssdict[prop.name] = prop.propertyValue[0].value
                 elif prop.name == 'src':
                     for val in prop.propertyValue:
                         x = val.value
                         fname = container.href_to_name(x, sheet_name)
                         if container.has_name(fname):
                             cssdict['src'] = fname
                             break
                     else:
                         container.log.warn('The @font-face rule refers to a font file that does not exist in the book: %s' % prop.propertyValue.cssText)
             if 'src' not in cssdict:
                 continue
             ff = cssdict.get('font-family')
             if not ff or ff[0] in bad_fonts:
                 continue
             normalize_font_properties(cssdict)
             prepare_font_rule(cssdict)
             sheet_rules.append(cssdict)
     self.font_rule_map[spine_name].extend(sheet_rules)