Esempio n. 1
0
def main():
    # HIDE DEPRECATION WARINGS ONLY IN RELEASES. SHOW THEM IN DEV. TRUNKS
    warnings.filterwarnings('ignore', category=DeprecationWarning)
    usage = "Usage: %prog [options] svgfilename"
    parser = OptionParser(usage=usage)
    parser.add_option("-i", "--imageexport", action="store_true", dest="imageexport", default=False, help="Use PNG files as export content")
    parser.add_option("-J", "--nojoin", action="store_true", dest="nojoin", default=False, help="Do not join resulting PDFs or PNGs")
    
    for field in ReplacementField.__subclasses__():
        field.install(parser)
    
    (options, args) = parser.parse_args()

    if not args:
        print parser.print_help()
        sys.exit(1)
    
    options.filename = args[0]
    
    maker = InkscapeSlideMaker(options)
    maker.make().join()
Esempio n. 2
0
    def make(self):
    
        # Text which might have fields
        def find_texts(layer):
            return layer.findall('%s/%s' % (e(NS['svg'],'text'), e(NS['svg'],'tspan'))) + \
                    layer.findall('%s/%s' % (e(NS['svg'],'flowRoot'), e(NS['svg'],'flowPara')))
    
        # Get the initial style attribute and keep it
        for l in self.layers:
            label = l.attrib.get(e(NS['ink'],'label')) 
            if 'style' not in l.attrib:
                l.set('style', '')
            # Save initial values
            self.orig_style[label] = l.attrib['style']


        # Contains seq of [('layer', opacity), ('layer', opacity), ..]
        for sl in self.preslides:
            if sl:
                if sl.startswith('+'):
                    sl = sl[1:]
                    sl_layers = self.slides[-1].copy()
                else:
                    sl_layers = {}

                for layer in sl.split(','):
                    elements = layer.strip().split('*')
                    name = elements[0].strip()
                    opacity = None
                    if len(elements) == 2:
                        opacity = float(elements[1].strip())
                    sl_layers[name] = {'opacity': opacity}
                self.slides.append(sl_layers)


        for i, slide_layers in enumerate(self.slides):
            # Increase slide numbers 
            self.slide_number += 1
            for l in self.layers:
                for text in find_texts(l):
                    for field in reversed(ReplacementField.__subclasses__()):
                        field.restore(text)
            
            for l in self.layers:
                label = l.attrib.get(e(NS['ink'],'label'))
                # Set display mode to original
                l.set('style', self.orig_style[label])

                # Don't show it by default...
                set_style(l, 'display', 'none')

                if label in slide_layers:
                    set_style(l, 'display', 'inline')
                    opacity = slide_layers[label]['opacity']
                    if opacity:
                        set_style(l, 'opacity', str(opacity))
                        
                # Update field values
                texts = find_texts(l)
                for field in ReplacementField.__subclasses__():
                    field_texts = [x for x in texts if field.match(x.text)]
                    
                    for field_text in field_texts:
                        field.replace(field_text, self)
                    
            
            svgslide = os.path.abspath(os.path.join(os.curdir,
                                                    "%s.p%d.svg" % (self.options.filename, i)))
            pdfslide = os.path.abspath(os.path.join(os.curdir,
                                                    "%s.p%d.pdf" % (self.options.filename, i)))
            # Use the correct extension if using images
            if self.options.imageexport:
                pdfslide = os.path.abspath(os.path.join(os.curdir,
                                                "_inkscapeslide_%s.p%05d.png" % (self.options.filename, i)))

            # Write the XML to file, "wireframes.p1.svg"
            self.doc.write(svgslide)

            # Determine whether to export pdf's or images (e.g. inkscape -A versus inkscape -e)
            if self.options.imageexport:
                cmd = "inkscape -d 180 -e %s %s" % (pdfslide, svgslide)
            else:
                cmd = "inkscape -A %s %s" % (pdfslide, svgslide)

            # Using subprocess to hide stdout
            subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()
            os.unlink(svgslide)
            self.pdfslides.append(pdfslide)

            print "Generated page %d." % (i+1)
        return self