Exemplo n.º 1
0
 def _convert_impl(self, cssss, resource):
   # CSS Rule List
   cssrl = cssss.cssRules
   # 遍历各个Rule
   for rule in cssss.cssRules:
     if rule.type != 1:
       continue
     # rule的类型是CSSStyleRule
     style = rule.style                  # CSSStyleDeclaration
     properties = style.getProperties()  # list<cssutils.css.Property>
     new_props = []
     for p in properties:
       key = p.name
       value = p.cssValue
       new_prop = None
       if key.endswith('background') or \
          key.endswith('background-image'):
         if value.cssValueType == value.CSS_VALUE_LIST:
           for k in value:
             if k.primitiveType == k.CSS_URI:
               # logging.warning(k.getStringValue())
               uri_path = k.getStringValue()
               # 如果图片时png,且该png不是png8格式(通过命名区分),则进行转换并加上ie6的css hack
               if uri_path.endswith('.png') and not uri_path.endswith('-fs8.png'):
                 # create property _background or _background-image
                 new_uri = self._convert_image(resource, uri_path)
                 if new_uri:
                   new_prop = Property()
                   new_prop.cssText = p.cssText.replace('background', '_background').replace(uri_path, new_uri)
         elif value.cssValueType == value.CSS_PRIMITIVE_VALUE and \
              value.primitiveType == value.CSS_URI:
           uri_path = value.getStringValue()
           # 如果图片时png,且该png不是png8格式(通过命名区分),则进行转换并加上ie6的css hack
           if uri_path.endswith('.png') and not uri_path.endswith('-fs8.png'):
             # create property _background or _background-image
             new_uri = self._convert_image(resource, uri_path)
             if new_uri:
               new_prop = Property('_' + key, cssutils.helper.uri(new_uri))
       if new_prop:
         new_props.append(new_prop)
     # 往rule.style里面添加hack的property
     for x in new_props:
       style.setProperty(x)
   return cssss.cssText