Skip to content

Commit

Permalink
v4.0
Browse files Browse the repository at this point in the history
- Added Element level exports
- Merged Symbol export into SLE
- Reworked UI to accomodate new views/controls
- Usability improvements
  • Loading branch information
TomByrne committed Oct 19, 2017
1 parent 32a586b commit e95ef85
Show file tree
Hide file tree
Showing 26 changed files with 1,250 additions and 288 deletions.
2 changes: 1 addition & 1 deletion EntryScripts/Smart Layer Export.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if(!doc || !app.documents.length){
try{
var toolBuilder = new smartExport.ExportToolBuilder(app.activeDocument, "Smart Layer Export");
var loadSuccess = toolBuilder.loadPrefLayer("Export Settings", "nyt_exporter_info");
if (loadSuccess) toolBuilder.showDialog(true, true, false);
if (loadSuccess) toolBuilder.showDialog(true, true, true, true);

}catch(e){
alert("Error opening panel:\n"+e);
Expand Down
130 changes: 130 additions & 0 deletions SmartCore/Button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
(function(pack){
function Button(container, label, style){
this.init(container, label, style);
return this;
}

Button.STYLE_MAIN_TAB = "mainTab";
Button.STYLE_MAIN_TAB_OUTPUT = "mainTab.output";


Button.prototype={
onClick:null,

init:function(container, label, style){
var scopedThis = this;

this.nativeButton = container.add("button", undefined, label);
this.nativeButton.onClick = closure(this, this.onButtonClick);

if(style != null){
var g = this.nativeButton.graphics;
this.hPadding = 0;
this.vPadding = 0;
this.backingOffset = 0;
var origFont = this.nativeButton.graphics.font;
if(style == Button.STYLE_MAIN_TAB || style == Button.STYLE_MAIN_TAB_OUTPUT){
var darkGrey = 0x40 / 0xff;
var normalGrey = 0x49 / 0xff;

this.normalBacking = g.newBrush(g.BrushType.SOLID_COLOR, [darkGrey, darkGrey, darkGrey, 1]);
this.activeBacking = g.newBrush(g.BrushType.SOLID_COLOR, [normalGrey, normalGrey, normalGrey, 1]);

//this.normalPen = g.newPen (g.PenType.SOLID_COLOR, [1, 1, 1, 1], 1);
this.activePen = g.newPen (g.PenType.SOLID_COLOR, [1, 1, 1, 1], 5);

this.textPen = g.newPen (g.PenType.SOLID_COLOR, [1, 1, 1, 1], 1);
this.font = ScriptUI.newFont( origFont.name, ScriptUI.FontStyle.BOLD, 20 );
this.hPadding = 8;
this.vPadding = 8;
this.uppercase = true;
this.backingOffset = -1;

if(style == Button.STYLE_MAIN_TAB_OUTPUT){
this.normalBacking = g.newBrush(g.BrushType.SOLID_COLOR, [darkGrey * 0.9, darkGrey * 0.9, darkGrey, 1]);
this.activePen = g.newPen (g.PenType.SOLID_COLOR, [0.9, 0.9, 1, 1], 5);
}
}
this.nativeButton.onDraw = closure(this, this.doDraw);
}
},
doDraw:function(){
var but = this.nativeButton;
var g = but.graphics;
var width;
var height;
if(but.size != null){
width = but.size[0];
height = but.size[1];
}else{
var measurements = g.measureString (but.text, this.font, but.maximumSize ? but.maximumSize[0] - this.hPadding * 2 : null);
width = measurements[0] + this.hPadding * 2;
height = measurements[0] + this.vPadding * 2;
}
g.rectPath(this.backingOffset, this.backingOffset, width - this.backingOffset * 2, height - this.backingOffset * 2);
if(but.active && this.activeBacking){
g.fillPath(this.activeBacking);
}else{
if(this.normalBacking != null) g.fillPath(this.normalBacking);
}

g.newPath();
g.moveTo(0, 0);
g.lineTo(0, height);
if(but.active && this.activePen){
g.strokePath(this.activePen);
}else{
if(this.normalPen != null) g.strokePath(this.normalPen);
}

if(but.text){
var measurements = g.measureString (but.text, this.font, width - this.hPadding * 2);
var x = (width - measurements[0]) / 2;
var y = (height - measurements[1]) / 2;

var text = but.text;
if(this.uppercase){
text = text.toUpperCase();
}
g.drawString(text, this.textPen, x, y, this.font);
}
},
setSize:function(w, h){
if(w == null || h == null){
this.nativeButton.size = null;
}else{
this.nativeButton.size = [w, h];
if(this.path != null){
this.path
}
}
},
setAlignment:function(h, v){
if(h == null || v == null){
this.nativeButton.alignment = null;
}else{
this.nativeButton.alignment = [h, v];
}
},
setText:function(text){
this.nativeButton.text = text;
this.nativeButton.notify("onDraw");
},
setHelpTip:function(text){
this.nativeButton.helpTip = text;
},
setActive:function(active){
this.nativeButton.active = active;
this.nativeButton.notify("onDraw");
},
setEnabled:function(enabled){
this.nativeButton.enabled = enabled;
this.nativeButton.notify("onDraw");
},
onButtonClick:function(){
if(this.onClick) this.onClick();
}
};

pack.Button = Button;
})(smartExport)
125 changes: 76 additions & 49 deletions SmartCore/DocUtils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

var vis = (layerVis ? layerVis[j] : layer.visible );
if (layerCheck==null || layerCheck(layer, vis)) {
//var layerBounds = this.getLayerBounds(layer);
//var layerBounds = this.getLayerBounds(docRef, layer);
//if(layerBounds && this.intersects(artboardRect, layerBounds)){
var newLayer = this.copyLayer(docRef, copyDoc, artboard, copyArtboard, artboardRect, layer, copyDoc.layers.add(), doInnerPadding, outlineText, ungroup, docRef.rulerOrigin, ignoreWarnings, hasBoundErrorRef, offset);
this.setLayerDepth(newLayer, count);
Expand Down Expand Up @@ -69,8 +69,16 @@
var toRect = toArtboard.artboardRect;
return {x:toRect[0] - artboardRect[0], y:toRect[3] - artboardRect[3]};
}

DocUtils.getLayerIndex = function(layers, layer){
for(var i=0; i<layers.length; i++)
{
if(layers[i] == layer) return i;
}
return -1;
}

DocUtils.copyLayer = function(fromDoc, toDoc, fromArtboard, toArtboard, artboardRect, fromLayer, toLayer, doInnerPadding, outlineText, ungroup, rulerOrigin, ignoreWarnings, hasBoundErrorRef, offset) {
DocUtils.copyLayer = function(fromDoc, toDoc, fromArtboard, toArtboard, artboardRect, fromLayer, toLayer, doInnerPadding, outlineText, ungroup, rulerOrigin, ignoreWarnings, hasBoundErrorRef, offset, elemFilter) {
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

toLayer.artworkKnockout = fromLayer.artworkKnockout;
Expand Down Expand Up @@ -108,7 +116,8 @@
}
}

this.copyIntoLayer(fromDoc, fromLayer, toLayer, ignoreWarnings, artboardRect);
var layerPath = (DocUtils.getLayerIndex(fromDoc.layers, fromLayer) + 1) + "";
this.copyIntoLayer(fromDoc, fromLayer, toLayer, ignoreWarnings, artboardRect, layerPath, elemFilter);
if(doInnerPadding)this.innerPadLayer(toLayer, toArtboard);
if(outlineText)this.doOutlineLayer(toLayer);
if(ungroup)this.doUngroupLayer(toLayer);
Expand Down Expand Up @@ -143,62 +152,54 @@
item.remove();
}
}
DocUtils.getLayerBounds = function(layer, artboardRect) {
DocUtils.getLayerBounds = function(doc, layer, artboardRect, elemFilter, parentPath) {
var rect;
var items = layer.pageItems;
var items = DocUtils.getAllPageItems(doc, layer, true);

if(parentPath == null) parentPath = (DocUtils.getLayerIndex(doc.layers, layer) + 1) + "";
parentPath += ":";

var childFilter = elemFilter;
for(var i=0; i<items.length; ++i){
var item = items[i];
var path = parentPath + (i+1);

if(item.guides || item.hidden){
continue;
if(elemFilter){
var filter = elemFilter(item, path);
if(!filter) continue;
if(filter != 'explore') childFilter = null; // clear so all descendants get included
}
var visBounds = this.getItemBounds(item);
if(visBounds==null)continue;

if(artboardRect && !DocUtils.intersects(artboardRect, visBounds))continue;

if(rect==null){
rect = visBounds;
var isLayer = (item.typename=="Layer");
var itemBounds;
if(isLayer){
if(!item.visible)continue;
itemBounds = this.getLayerBounds(doc, item, artboardRect, childFilter, path);
}else{
if(rect[0]>visBounds[0]){
rect[0] = visBounds[0];
}
if(rect[1]<visBounds[1]){
rect[1] = visBounds[1];
}
if(rect[2]<visBounds[2]){
rect[2] = visBounds[2];
}
if(rect[3]>visBounds[3]){
rect[3] = visBounds[3];
}
if(item.guides || item.hidden) continue;
itemBounds = this.getItemBounds(item, childFilter, path);
}
}
for(var i=0; i<layer.layers.length; ++i){
var childLayer = layer.layers[i];

if(!childLayer.visible)continue;

var childRect = this.getLayerBounds(childLayer, artboardRect);
if(childRect==null)continue;
if(itemBounds == null) continue;
if(artboardRect && !DocUtils.intersects(artboardRect, itemBounds)) continue;

if(rect==null){
rect = childRect;
rect = itemBounds;
}else{
if(rect[0]>childRect[0]){
rect[0] = childRect[0];
if(rect[0]>itemBounds[0]){
rect[0] = itemBounds[0];
}
if(rect[1]<childRect[1]){
rect[1] = childRect[1];
if(rect[1]<itemBounds[1]){
rect[1] = itemBounds[1];
}
if(rect[2]<childRect[2]){
rect[2] = childRect[2];
if(rect[2]<itemBounds[2]){
rect[2] = itemBounds[2];
}
if(rect[3]>childRect[3]){
rect[3] = childRect[3];
if(rect[3]>itemBounds[3]){
rect[3] = itemBounds[3];
}
}
}

if(rect && rect[0]<rect[2] && rect[1]>rect[3]){
return rect;
}else{
Expand All @@ -213,24 +214,39 @@
return this.intersects(artRect, rect);
}

DocUtils.copyIntoLayer = function(doc, fromLayer, toLayer, ignoreWarnings, artboardRect) {
DocUtils.copyIntoLayer = function(doc, fromLayer, toLayer, ignoreWarnings, artboardRect, parentPath, elemFilter) {
var items = this.getAllPageItems(doc, fromLayer, ignoreWarnings);
try{
this.copyItems(doc, items, toLayer, ignoreWarnings, artboardRect);
this.copyItems(doc, items, toLayer, ignoreWarnings, artboardRect, parentPath, elemFilter);
}catch(e){
alert("Copy items failed: "+e);
}
}

DocUtils.copyItems = function(doc, fromList, toLayer, ignoreWarnings, artboardRect) {
DocUtils.copyItems = function(doc, fromList, toLayer, ignoreWarnings, artboardRect, parentPath, elemFilter) {
parentPath += ":";
var visWas = toLayer.visible;
toLayer.visible = true;
for(var i=0; i<fromList.length; ++i){
var item = fromList[i];
if(item.typename=="Layer"){
var path = parentPath + (i+1);
var isLayer = (item.typename=="Layer");
if(isLayer){
if(item.visible && (item.pageItems.length || item.layers.length)){
this.copyIntoLayer(doc, item, toLayer, ignoreWarnings, artboardRect)
this.copyIntoLayer(doc, item, toLayer, ignoreWarnings, artboardRect, path, elemFilter)
}
}else if(elemFilter != null){

var filter = elemFilter(item, path);
if(!filter) continue;

if(item.typename == "GroupItem" && filter == 'explore'){
DocUtils.copyItems(doc, item.pageItems, toLayer, ignoreWarnings, artboardRect, path, elemFilter);
}else{
item.duplicate(toLayer, ElementPlacement.PLACEATEND);
}


}else{
if(item.hidden || !DocUtils.intersects(artboardRect, item.visibleBounds)){
continue;
Expand Down Expand Up @@ -386,18 +402,28 @@
}
}

DocUtils.getItemBounds = function(parent){
DocUtils.getItemBounds = function(parent, elemFilter, parentPath){
if(parent.typename=="GroupItem"){
parentPath += ":";
var rect;
var maskRect;
var items = parent.pageItems;
var childFilter = elemFilter;
for(var i=0; i<items.length; ++i){
var item = items[i];
var path = parentPath + (i + 1);

if(elemFilter){
var filter = elemFilter(item, path);
if(!filter) continue;
if(filter != 'explore') childFilter = null; // clear so all descendants get included
}

if(item.guides || item.hidden){
continue;
}
var visBounds = item.visibleBounds;
//var visBounds = item.visibleBounds;
var visBounds = DocUtils.getItemBounds(item, childFilter, path);
if(visBounds==null)continue;
else if(parent.clipped && item.clipping){
maskRect = visBounds;
Expand Down Expand Up @@ -435,6 +461,7 @@
rect[3] = maskRect[3];
}
}

return rect;
}else{
return parent.visibleBounds.concat();
Expand Down
Loading

0 comments on commit e95ef85

Please sign in to comment.