View Single Post
Old 06-12-2014, 09:03 AM   #34
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,494
Karma: 28005164
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
@DiapDealer: While it is certainly true that using code from the conversion pipeline is not always possible standalone, in this case you can do it with the container pretty easily, like this (insert the following into my previous example:

Code:
# assume we have a parsed stylesheet as I showed before
for rule in sheet.cssRules:
   if rule.type == rule.STYLE_RULE:
        for property in rule.style.keys():
               val = property.propertyValue
                for x in val:
                     if x.type == 'DIMENSION' and x.unit == 'cm':
                           x.cssText = convert(x.value )  # Here convert should convert a float into a string in em units
                            
container.dirty(sheet_name)
This is ofcourse, only a skeleton, it does not handle @media rules or <style> tags or style attributes, but those are all equally trivial, just look around in the files inthe polish directory to learn how to iterate over them.
kovidgoyal is offline   Reply With Quote