Created
February 28, 2017 21:08
-
-
Save Tolmark12/f187c1efcf195b80e36c7068947d73da to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Generated by CoffeeScript 1.10.0 | |
(function() { | |
var SVGcompiler, console, svgCompiler; | |
console = { | |
log: function(str) { | |
return $.writeln(str); | |
} | |
}; | |
SVGcompiler = (function() { | |
function SVGcompiler() { | |
this.sourceDoc = app.activeDocument; | |
this.createDummyDoc(); | |
this.copyGroupedItemsToDummyDoc(); | |
this.exportSvg(); | |
} | |
SVGcompiler.prototype.runSimpleScript = function() { | |
var basePath, f, thisFile; | |
thisFile = new File($.fileName); | |
basePath = thisFile.path; | |
f = new File(basePath + "/test.script"); | |
return console.log(f.execute()); | |
}; | |
SVGcompiler.prototype.createDummyDoc = function() { | |
var obj; | |
obj = { | |
colorMode: DocumentColorSpace.RGB, | |
height: 200, | |
width: 200 | |
}; | |
return this.dummyDoc = app.documents.add(obj.colorMode, obj.width, obj.height); | |
}; | |
SVGcompiler.prototype.copyGroupedItemsToDummyDoc = function() { | |
var bounds, docHeight, height, i, item, len, newItem, ref, results, svgsLayer, width; | |
docHeight = this.dummyDoc.height; | |
svgsLayer = this.sourceDoc.layers.getByName("svgs"); | |
ref = svgsLayer.groupItems; | |
results = []; | |
for (i = 0, len = ref.length; i < len; i++) { | |
item = ref[i]; | |
newItem = item.duplicate(this.dummyDoc, ElementPlacement.PLACEATEND); | |
newItem.left = 0; | |
newItem.top = docHeight; | |
bounds = newItem.controlBounds; | |
width = Math.ceil(Math.abs(bounds[0] - bounds[2])); | |
height = Math.ceil(Math.abs(bounds[1] - bounds[3])); | |
results.push(newItem.name += "`" + width + "x" + height); | |
} | |
return results; | |
}; | |
SVGcompiler.prototype.exportSvg = function() { | |
var dest, exportOptions, fileSpec, folder, format, options, type; | |
dest = this.sourceDoc.path + "/compiled/" + (this.sourceDoc.name.split('.')[0]); | |
format = "SVG"; | |
options = []; | |
folder = new Folder(this.sourceDoc.path + "/compiled/"); | |
if (!folder.exists) { | |
folder.create(); | |
} | |
exportOptions = new ExportOptionsSVG(); | |
type = ExportType.SVG; | |
fileSpec = new File(dest); | |
exportOptions.embedRasterImages = false; | |
exportOptions.embedAllFonts = false; | |
exportOptions.cssProperties = SVGCSSPropertyLocation.STYLEELEMENTS; | |
this.dummyDoc.exportFile(fileSpec, type, exportOptions); | |
return this.dummyDoc.close(SaveOptions.DONOTSAVECHANGES); | |
}; | |
return SVGcompiler; | |
})(); | |
svgCompiler = new SVGcompiler(); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment