-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from tuomassalo/names
Add --shape, --frame and --names options; use mixins instead of SVGExporter subclasses
- Loading branch information
Showing
2 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
from __future__ import absolute_import | ||
import argparse | ||
from swf.movie import SWF | ||
from swf.export import SVGExporter | ||
from swf.export import SVGExporter, SingleShapeSVGExporterMixin, FrameSVGExporterMixin, NamesSVGExporterMixin | ||
|
||
parser = argparse.ArgumentParser(description="Convert an SWF file into an SVG") | ||
parser.add_argument("--swf", type=argparse.FileType('rb'), | ||
help="Location of SWG file to convert", required=True) | ||
parser.add_argument("--svg", type=argparse.FileType('wb'), | ||
help="Location of converted SVG file", required=True) | ||
parser.add_argument("--shape", type=int, | ||
help="Only export shape SHAPE (integer)", required=False) | ||
parser.add_argument("--frame", type=int, | ||
help="Export frame FRAME (0-based index) instead of frame 0", required=False) | ||
parser.add_argument("--names", action='store_true', | ||
help='For each element, extract SWF instanceName to class="n-<name>"', required=False) | ||
|
||
options = parser.parse_args() | ||
argparse.swf_file = options.swf | ||
|
||
# load and parse the SWF | ||
swf = SWF(options.swf) | ||
|
||
export_opts = {} | ||
export_mixins = [] | ||
|
||
|
||
# process the optional arguments | ||
|
||
if options.shape is not None: | ||
export_mixins.append(SingleShapeSVGExporterMixin) | ||
export_opts['shape'] = options.shape | ||
|
||
if options.frame is not None: | ||
export_mixins.append(FrameSVGExporterMixin) | ||
export_opts['frame'] = options.frame | ||
|
||
if options.names: | ||
export_mixins.append(NamesSVGExporterMixin) | ||
|
||
|
||
# create the SVG exporter | ||
svg_exporter = SVGExporter() | ||
|
||
# NB: Construct the class dynamically, since the chosen options dictate which mixins to use. | ||
svg_exporter.__class__ = type('ThisExporter', tuple(export_mixins + [SVGExporter]), {}) | ||
|
||
# export! | ||
svg = swf.export(svg_exporter) | ||
svg = svg_exporter.export(swf, **export_opts) | ||
|
||
# save the SVG | ||
options.svg.write(svg.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters