Skip to content

Commit

Permalink
implemented generator.getDocumentPixmap
Browse files Browse the repository at this point in the history
  • Loading branch information
marekhrabe committed Aug 16, 2014
1 parent 2401e2c commit 18b7c4a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,55 @@
return overallDeferred.promise;
};

/**
* Get a pixmap representing the pixels of a document.
* Optionally pass settings with the same available params as getPixmap method.
*
* @param {!number} documentId Document ID
* @param {?Object} settings getPixmap settings
*/
Generator.prototype.getDocumentPixmap = function (documentId, settings) {
if (documentId === undefined) {
return Q.reject("Document ID is required");
} else {
return this.getDocumentInfo(documentId, {
compInfo: false,
imageInfo: false,
layerInfo: true,
expandSmartObjects: false,
getTextStyles: false,
getFullTextStyles: false,
selectedLayers: false,
getCompLayerSettings: true,
getDefaultLayerFX: false
}).then(function (document) {
var layerSpec = {
firstLayerIndex: 0,
lastLayerIndex: document.layers[0].index,
hidden: this._computeHiddenLayers(document)
};
return this.getPixmap(documentId, layerSpec, settings);
}.bind(this));
}
};

// recursively walks layers and returns hidden ones
// if parent is hidden, pass flag to hide all children regardless their visibility
Generator.prototype._computeHiddenLayers = function (parent, hideAll) {
var layer, isHidden, hiddenLayers = [];
for (var i = 0, ii = parent.layers.length; i < ii; i++) {
layer = parent.layers[i];
isHidden = hideAll || !layer.visible;
if (isHidden) {
hiddenLayers.push(layer.index);
}
if (layer.type === "layerSection" && layer.layers && layer.layers.length) {
hiddenLayers = hiddenLayers.concat(this._computeHiddenLayers(layer, isHidden));
}
}
return hiddenLayers;
};

/**
* Returns a promise that resolves to an object detailing the path
* present on the specified layer. If there is no path present,
Expand Down

0 comments on commit 18b7c4a

Please sign in to comment.