Skip to content

Commit

Permalink
fixed exportable bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
utom committed Jan 3, 2017
1 parent bb10c83 commit f4f6213
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To create your own custom shortcuts, go to Keyboard in your System Preferences a
##Contributors
* Author [@utom](http://utom.design)
* [@cute](http://liguangming.com) ([SketchI18N](https://github.com/cute/SketchI18N)) and [@esseak](https://github.com/esseak)
* [@mkl87](https://github.com/mkl87), [Skykai521](https://github.com/Skykai521), [@whyfind](https://github.com/whyfind) and [@Nora](https://www.behance.net/liyinuo)
* [@mkl87](https://github.com/mkl87), [@Skykai521](https://github.com/Skykai521), [@whyfind](https://github.com/whyfind) and [@Nora](https://www.behance.net/liyinuo)
* @Kai and [@Zih-Hong](http://zihhonglin.com)
* And [Other](https://github.com/utom/sketch-measure/contributors)

Expand Down
47 changes: 28 additions & 19 deletions Sketch Measure.sketchplugin/Contents/Sketch/library/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ SM.extend({
manifestURL = self.pluginSketch + "/i18n/manifest-" + lang + ".json";

if( ( !self.SMVersion || self.SMVersion != this.version ) || ( !self.SMLanguage || self.SMLanguage != self.language ) ){
log("manifest")
self.prefs.setObject_forKey
(self.version, "SMVersion");
self.prefs.setObject_forKey
(self.language, "SMLanguage");
if(NSFileManager.defaultManager().fileExistsAtPath(manifestURL)){
Expand Down Expand Up @@ -2498,45 +2497,55 @@ SM.extend({

}
},
getFormats: function( exportFormats ) {
var formats = [];
for (var i = 0; i < exportFormats.length; i++) {
var format = exportFormats[i];
formats.push({
scale: format.scale(),
suffix: format.name(),
format: format.fileFormat()
})
}
return formats;
},
getExportable: function(layer, savePath){
var self = this,
exportable = [],
size, sizes = layer.exportOptions().exportFormats(),
fileFormat = this.toJSString(sizes[0].fileFormat()),
matchFormat = /png|jpg|tiff|webp/.exec(fileFormat);
var formats =
var exportFormats =
(self.configs.unit == "dp/sp" && matchFormat)? [
{ scale: 1 / self.configs.scale, drawable: "drawable-mdpi/" },
{ scale: 1.5 / self.configs.scale, drawable: "drawable-hdpi/" },
{ scale: 2 / self.configs.scale, drawable: "drawable-xhdpi/" },
{ scale: 3 / self.configs.scale, drawable: "drawable-xxhdpi/" },
{ scale: 4 / self.configs.scale, drawable: "drawable-xxxhdpi/"}
{ scale: 1 / self.configs.scale, drawable: "drawable-mdpi/", format: "png" },
{ scale: 1.5 / self.configs.scale, drawable: "drawable-hdpi/", format: "png" },
{ scale: 2 / self.configs.scale, drawable: "drawable-xhdpi/", format: "png" },
{ scale: 3 / self.configs.scale, drawable: "drawable-xxhdpi/", format: "png" },
{ scale: 4 / self.configs.scale, drawable: "drawable-xxxhdpi/", format: "png" }
]:
(this.configs.unit == "pt" && matchFormat)? [
{ scale: 1 / self.configs.scale, suffix: "" },
{ scale: 2 / self.configs.scale, suffix: "@2x" },
{ scale: 3 / self.configs.scale, suffix: "@3x" }
{ scale: 1 / self.configs.scale, suffix: "", format: "png" },
{ scale: 2 / self.configs.scale, suffix: "@2x", format: "png" },
{ scale: 3 / self.configs.scale, suffix: "@3x", format: "png" }
]:
[
{ scale: 1, drawablePath: "", suffix: "" }
];
self.getFormats(sizes);

for(format of formats) {
var drawable = format.drawable || "",
suffix = format.suffix || "";
for(exportFormat of exportFormats) {
var drawable = exportFormat.drawable || "",
suffix = exportFormat.suffix || "";
self.exportImage({
layer: layer,
path: self.assetsPath,
scale: format.scale,
scale: exportFormat.scale,
name: drawable + layer.name(),
suffix: suffix,
format: fileFormat
format: exportFormat.format
});

exportable.push({
name: self.toJSString(layer.name()),
format: fileFormat,
path: drawable + layer.name() + suffix + ".png"
path: drawable + layer.name() + suffix + "." + exportFormat.format
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
},
"identifier": "com.utom.measure",
"homepage": "http://utom.design/measure/",
"version": "2.4",
"version": "2.4.1",
"description" : "Make it a fun to create spec for developers and teammates",
"authorEmail" : "utombox@gmail.com",
"name" : "Sketch Measure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
},
"identifier": "com.utom.measure",
"homepage": "http://utom.design/measure/",
"version": "2.4",
"version": "2.4.1",
"description" : "Make it a fun to create spec for developers and teammates",
"authorEmail" : "utombox@gmail.com",
"name" : "Sketch Measure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
},
"identifier": "com.utom.measure",
"homepage": "http://utom.design/measure/",
"version": "2.4",
"version": "2.4.1",
"description" : "Make it a fun to create spec for developers and teammates",
"authorEmail" : "utombox@gmail.com",
"name" : "Sketch Measure"
Expand Down
2 changes: 1 addition & 1 deletion Sketch Measure.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
},
"identifier": "com.utom.measure",
"homepage": "http://utom.design/measure/",
"version": "2.4",
"version": "2.4.1",
"description" : "Make it a fun to create spec for developers and teammates",
"authorEmail" : "utombox@gmail.com",
"name" : "Sketch Measure"
Expand Down

0 comments on commit f4f6213

Please sign in to comment.