def convert(infile, outfile): doc = load.load_drawing(infile) extension = os.path.splitext(outfile)[1] fileformat = plugins.guess_export_plugin(extension) if fileformat: saver = plugins.find_export_plugin(fileformat) saver(doc, outfile) else: sys.stderr.write("skconvert: unrecognized extension %s\n" % extension) sys.exit(1)
def main(): import Sketch, Sketch.config Sketch.Issue(None, Sketch.const.INITIALIZE) #plugins.load_plugin_configuration(config.plugin_path) use_bbox = 0 resolution = 72.0 steps = alpha = None import getopt opts, args = getopt.getopt( sys.argv[1:], 'bhr:s:A:', ['help', 'bbox', 'resolution=', 'gradient-steps=', 'alpha-bits=']) for optchar, value in opts: if optchar == '-h' or optchar == '--help': print_usage() return -1 elif optchar == '-b' or optchar == '--bbox': use_bbox = 1 elif optchar == '-r' or optchar == '--resolution': resolution = float(value) elif optchar == '-s' or optchar == '--gradient-steps': steps = float(value) elif optchar == '-A' or optchar == '--alpha-bits': alpha = int(value) if alpha not in (1, 2, 4): sys.stderr.write("sk2ppm: alpha-bits value must be one of" " 1, 2 or 4\n") return -1 if len(args) not in (1, 2): print_usage() return -1 if steps is not None: Sketch.config.preferences.gradient_steps_print = steps filename = args[0] if len(args) > 1: ppmfile = args[1] else: ppmfile = sys.stdout doc = load.load_drawing(filename) context = Context() context.document = doc export_raster(context, ppmfile, resolution, use_bbox, format="ppm", antialias=alpha)
def sk2ps(filename, psfilename, **psargs): # convert the SK file FILENAME into a PostScript file PSFILENAME. # Any keyword arguments are passed to the PostScript device class. doc = load.load_drawing(filename) bbox = doc.BoundingRect(visible=psargs.get('visible', 0), printable=psargs.get('printable', 1)) psargs['bounding_box'] = tuple(bbox) psargs['document'] = doc ps = apply(PostScriptDevice, (psfilename, ), psargs) doc.Draw(ps) ps.Close()
def sk2ps(filename, psfilename, **psargs): # convert the SK file FILENAME into a PostScript file PSFILENAME. # Any keyword arguments are passed to the PostScript device class. doc = load.load_drawing(filename) bbox = doc.BoundingRect(visible = psargs.get('visible', 0), printable = psargs.get('printable', 1)) psargs['bounding_box'] = tuple(bbox) psargs['document'] = doc ps = apply(PostScriptDevice, (psfilename,), psargs) doc.Draw(ps) ps.Close()
def main(): import Sketch, Sketch.config Sketch.Issue(None, Sketch.const.INITIALIZE) # plugins.load_plugin_configuration(config.plugin_path) use_bbox = 0 resolution = 72.0 steps = alpha = None import getopt opts, args = getopt.getopt( sys.argv[1:], "bhr:s:A:", ["help", "bbox", "resolution=", "gradient-steps=", "alpha-bits="] ) for optchar, value in opts: if optchar == "-h" or optchar == "--help": print_usage() return -1 elif optchar == "-b" or optchar == "--bbox": use_bbox = 1 elif optchar == "-r" or optchar == "--resolution": resolution = float(value) elif optchar == "-s" or optchar == "--gradient-steps": steps = float(value) elif optchar == "-A" or optchar == "--alpha-bits": alpha = int(value) if alpha not in (1, 2, 4): sys.stderr.write("sk2ppm: alpha-bits value must be one of" " 1, 2 or 4\n") return -1 if len(args) not in (1, 2): print_usage() return -1 if steps is not None: Sketch.config.preferences.gradient_steps_print = steps filename = args[0] if len(args) > 1: ppmfile = args[1] else: ppmfile = sys.stdout doc = load.load_drawing(filename) context = Context() context.document = doc export_raster(context, ppmfile, resolution, use_bbox, format="ppm", antialias=alpha)