JavaScript API¶
Application¶
Top-level methods available from the global acorn object.
acorn.currentDocument()¶
Grab the frontmost Acorn document.
Returns: Document The current document, or null if there are no Acorn documents.
acorn.setPreference_forKey(value, key)¶
Sets a preference for given name. (defaults read com.flyingmeat.Acorn8 to find out what you’ve already changed)
| Parameter | Type | Description |
|---|---|---|
value |
id |
The value of the preference (NSNumber, String) |
key |
String |
The preference name |
acorn.takeLayeredScreenshot()¶
Takes a layered screenshot of all displays and returns a document for each display.
acorn.toolPalette()¶
Returns the tool palette for the current document, an ACToolPalette object.
Bitmap Layer¶
Bitmap layers are an extension of the Layer object and contain raster (bitmap) data.
bitmapLayer.applyCIFilterNamed_withParameters(name, parameters)¶
Applies a Core Image filter directly to the bitmap layer pixels. See also layer.appendFilterWithName. Visit cifilter.app for a nice resource on the various filters you can use.
| Parameter | Type | Description |
|---|---|---|
name |
String |
The Core Image filter name. |
parameters |
Object |
Filter input values keyed by Core Image input name. |
bitmapLayer.applyCIImageFromFilter(image)¶
Replaces the bitmap layer contents with a CIImage.
| Parameter | Type | Description |
|---|---|---|
image |
CIImage |
Image to apply to the layer. |
bitmapLayer.applyCIImageFromFilter_shouldClipToSelection(image, clipToSelection)¶
Applies a CIImage to the bitmap layer, optionally clipping the change to the active selection.
| Parameter | Type | Description |
|---|---|---|
image |
CIImage |
Image to apply to the layer. |
clipToSelection |
Boolean |
True to restrict the result to the selection. |
bitmapLayer.colorAtPoint(point)¶
Returns the color of the bitmap layer at a canvas point.
| Parameter | Type | Description |
|---|---|---|
point |
NSPoint |
Point in canvas coordinates. |
Returns: NSColor The sampled color.
bitmapLayer.fillWithColor_shouldClipToSelection(color, clipToSelection)¶
Fills the bitmap layer, or the active selection, with a color.
| Parameter | Type | Description |
|---|---|---|
color |
NSColor |
Fill color. |
clipToSelection |
Boolean |
True to restrict the fill to the active selection. |
bitmapLayer.floodFillAtPoint(point)¶
Performs a flood fill on the bitmap layer at the given layer point.
| Parameter | Type | Description |
|---|---|---|
point |
NSPoint |
Point in layer coordinates. |
bitmapLayer.frame()¶
Returns the bitmap layer frame in canvas coordinates.
Returns: NSRect The layer frame.
bitmapLayer.frameOrigin()¶
Returns the bitmap layer frame origin.
Returns: NSPoint The frame origin.
bitmapLayer.setFrameOrigin(point)¶
Moves the bitmap layer frame origin.
| Parameter | Type | Description |
|---|---|---|
point |
NSPoint |
New frame origin. |
Document¶
A document is a general container for the whole image and allows access to varous IO routies, as well as the base group which holds layers.
document.autoLevels()¶
Adds a Levels filter to the current layer, and balances the levels automatically
document.beginCroppingWithRect(rect)¶
Starts an interactive crop operation with the given bounds.
| Parameter | Type | Description |
|---|---|---|
rect |
NSRect |
The crop rectangle in canvas coordinates. |
document.bitsPerComponent()¶
Returns the number of bits per color component.
Returns: Number 8, 16, or 32.
document.bitsPerPixel()¶
Returns the number of bits per pixel.
Returns: Number 32, 64, or 128.
document.callFilterNamed(filterOrPlugin)¶
Invokes a filter / plugin via the given string
| Parameter | Type | Description |
|---|---|---|
filterOrPlugin |
String |
The filter or plugin name |
document.canvasSize()¶
Returns the size of the image.
Returns: NSSize The image size.
document.CIImage()¶
Returns a Core Image composite of the document's visible layers.
Returns: CIImage The composited image.
document.colorSpace()¶
Returns the document CGColorSpace.
Returns: CGColorSpaceRef The document color space.
document.copyMerged()¶
Writes a composite of the image to the clipboard.
document.cropToRect(rect)¶
Crops the document to the given rectangle.
| Parameter | Type | Description |
|---|---|---|
rect |
NSRect |
The crop rectangle in canvas coordinates. |
document.currentLayer()¶
Returns the document's selected layer.
Returns: Layer The current layer.
document.DPI()¶
Returns the document resolution in dots per inch.
Returns: double The document DPI.
document.duplicate()¶
Duplicates the image
Returns: Document a copy of the invoked image.
document.firstLayerWithName(layerName)¶
Returns the first layer in the document with the given name.
| Parameter | Type | Description |
|---|---|---|
layerName |
String |
The layer name to find. |
Returns: Layer The matching layer, or null if no layer matches.
document.flipCanvasWithDirection(direction)¶
Flips the canvas in the given direction.
| Parameter | Type | Description |
|---|---|---|
direction |
String |
either "vertical" or "horizontal" |
document.invertSelection()¶
Inverts the current selection
document.layers()¶
Returns the document's top-level layers.
Returns: NSArray The top-level layers.
document.newCGImage()¶
Creates a new CGImage containing the current composited document image.
Returns: CGImageRef A retained CGImage for the document composite.
document.newLayerWithNSImage(image)¶
Adds a new bitmap layer from an NSImage.
| Parameter | Type | Description |
|---|---|---|
image |
NSImage |
The image to place in the new layer. |
document.replaceOccurrencesOfString_withString(target, replacement)¶
Replaces matching text in the document's text shapes.
| Parameter | Type | Description |
|---|---|---|
target |
String |
The text to find. |
replacement |
String |
The replacement text. |
document.resizeImageToSize(size)¶
Resizes the document canvas to the given size without scaling layer contents.
| Parameter | Type | Description |
|---|---|---|
size |
NSSize |
The new canvas size. |
document.scaleCanvasToSize(size)¶
Scales the canvas and all layers to the given size.
| Parameter | Type | Description |
|---|---|---|
size |
NSSize |
The new image size. |
document.scaleImageToHeight(height)¶
Scales the image proportionally to the given height.
| Parameter | Type | Description |
|---|---|---|
height |
Number |
The target height in pixels. |
document.scaleImageToSize(size)¶
Scales the image and all layers to the given size.
| Parameter | Type | Description |
|---|---|---|
size |
NSSize |
The new image size. |
document.scaleImageToWidth(width)¶
Scales the image proportionally to the given width.
| Parameter | Type | Description |
|---|---|---|
width |
Number |
The target width in pixels. |
document.scaleImageWithPercentage(scale)¶
Scales the image by a multiplier.
| Parameter | Type | Description |
|---|---|---|
scale |
Number |
Scale multiplier, where 0.5 is 50 percent and 2.0 is 200 percent. |
document.selectFrame(frame)¶
Adds a rectangular selection to the image
| Parameter | Type | Description |
|---|---|---|
frame |
NSRect |
The selection bounds |
document.setBitsPerPixel(bitsPerPixel)¶
Sets the document bit depth. Valid values are 32, 64, and 128.
| Parameter | Type | Description |
|---|---|---|
bitsPerPixel |
Number |
The target bits per pixel. |
document.setCanvasSize(size)¶
Changes the canvas size without scaling layer contents, anchored at the lower-left corner.
| Parameter | Type | Description |
|---|---|---|
size |
NSSize |
The new canvas size. |
document.setCanvasSize_usingAnchor(size, anchor)¶
Changes the canvas size without scaling layer contents, with an argument to anchor the existing image to a corner.
| Parameter | Type | Description |
|---|---|---|
size |
NSSize |
The new canvas size. |
anchor |
NSString |
The area to anchor to. Valid values are "bottom center", "bottom left", "bottom right", "middle center", "middle left", "middle right", "top center", "top left", "top right" |
document.setDPI(dpi)¶
Sets the document resolution in dots per inch.
| Parameter | Type | Description |
|---|---|---|
dpi |
double |
The new document DPI. |
document.setSelectedLayer(layer)¶
Sets the actively selected layer.
| Parameter | Type | Description |
|---|---|---|
layer |
Layer |
The layer to select |
document.trim()¶
Trims the edge colors out of the image.
document.writeToFile_withUTI(path, uti)¶
Writes the document to a file using the given Uniform Type Identifier.
| Parameter | Type | Description |
|---|---|---|
path |
String |
Destination file path. |
uti |
String |
Uniform Type Identifier for the output format. |
Returns: Boolean True when the write succeeds.
Graphics¶
bezierAnchor.hasLeftSegment()¶
Returns whether the anchor has a segment to its left.
Returns: Boolean True when a left segment exists.
bezierAnchor.hasRightSegment()¶
Returns whether the anchor has a segment to its right.
Returns: Boolean True when a right segment exists.
bezierAnchor.leftCP()¶
Returns the left control point for the anchor.
Returns: NSPoint The left control point.
bezierAnchor.leftSegmentType()¶
Returns the NSBezierPathElement type for the segment to the left of the anchor.
Returns: Number The segment type.
bezierAnchor.location()¶
Returns the anchor location.
Returns: NSPoint The anchor location.
bezierAnchor.rightCP()¶
Returns the right control point for the anchor.
Returns: NSPoint The right control point.
bezierAnchor.rightSegmentType()¶
Returns the NSBezierPathElement type for the segment to the right of the anchor.
Returns: Number The segment type.
bezierAnchor.setLeftCP(point)¶
Sets the left control point for the anchor.
| Parameter | Type | Description |
|---|---|---|
point |
NSPoint |
The new left control point. |
bezierAnchor.setLeftSegmentType(type)¶
Sets the NSBezierPathElement type for the segment to the left of the anchor.
| Parameter | Type | Description |
|---|---|---|
type |
Number |
The segment type. |
bezierAnchor.setLocation(point)¶
Moves the anchor to a new location.
| Parameter | Type | Description |
|---|---|---|
point |
NSPoint |
The new anchor location. |
bezierAnchor.setRightCP(point)¶
Sets the right control point for the anchor.
| Parameter | Type | Description |
|---|---|---|
point |
NSPoint |
The new right control point. |
bezierAnchor.setRightSegmentType(type)¶
Sets the NSBezierPathElement type for the segment to the right of the anchor.
| Parameter | Type | Description |
|---|---|---|
type |
Number |
The segment type. |
bezierAnchor.translateBy(delta)¶
Moves the anchor and its control points by a delta.
| Parameter | Type | Description |
|---|---|---|
delta |
NSPoint |
Translation delta. |
bezierGraphic.ACBezierPath()¶
Returns the Acorn Bezier path for a Bezier graphic.
Returns: BezierPath The graphic's Bezier path.
bezierGraphic.movePointAtIndex_toPoint(index, point)¶
Moves a Bezier path point to a new location.
| Parameter | Type | Description |
|---|---|---|
index |
Number |
Point index. |
point |
NSPoint |
New point location. |
bezierGraphic.path()¶
Returns the Bezier path for a Bezier graphic.
Returns: BezierPath The graphic's Bezier path.
bezierGraphic.pointOfElementAtIndex(index)¶
Returns the point for a Bezier path element.
| Parameter | Type | Description |
|---|---|---|
index |
Number |
Element index. |
Returns: NSPoint The element point.
bezierGraphic.setACBezierPath(path)¶
Replaces a Bezier graphic's Acorn Bezier path.
| Parameter | Type | Description |
|---|---|---|
path |
BezierPath |
The replacement path. |
bezierGraphic.setPath(path)¶
Replaces the Bezier path for a Bezier graphic.
| Parameter | Type | Description |
|---|---|---|
path |
BezierPath |
The replacement path. |
bezierPath.anchorAtIndex(index)¶
Returns the anchor at the given index.
| Parameter | Type | Description |
|---|---|---|
index |
Number |
Anchor index. |
Returns: BezierAnchor The anchor object.
bezierPath.anchorCount()¶
Returns the number of anchors in the Bezier path.
Returns: Number The anchor count.
bezierPath.anchors()¶
Returns the anchors in the Bezier path.
Returns: NSArray The path anchors.
bezierPath.locationForAnchorAtIndex(index)¶
Returns the location for an anchor at the given index.
| Parameter | Type | Description |
|---|---|---|
index |
Number |
Anchor index. |
Returns: NSPoint The anchor location.
bezierPath.resetAnchors()¶
Converts curve anchors to straight line anchors by resetting their control points.
bezierPath.setLocation_forAnchorAtIndex(point, index)¶
Moves the anchor at the given index to a new location.
| Parameter | Type | Description |
|---|---|---|
point |
NSPoint |
New anchor location. |
index |
Number |
Anchor index. |
graphic.bezierPath()¶
Returns the graphic as an NSBezierPath.
Returns: NSBezierPath The graphic path.
graphic.bounds()¶
Returns the graphic bounds.
Returns: NSRect The graphic bounds.
graphic.drawsFill¶
Gets or sets whether the graphic draws its fill.
graphic.fillColor()¶
Returns the graphic fill color.
Returns: NSColor The fill color.
graphic.scaleXBy_yBy(xScale, yScale)¶
Scales a graphic's bounds, stroke, and shadow by the given multipliers.
| Parameter | Type | Description |
|---|---|---|
xScale |
Number |
Horizontal scale multiplier. |
yScale |
Number |
Vertical scale multiplier. |
graphic.setFillColor(color)¶
Sets the graphic fill color.
| Parameter | Type | Description |
|---|---|---|
color |
NSColor |
The new fill color. |
graphic.setStrokeColor(color)¶
Sets the graphic stroke color.
| Parameter | Type | Description |
|---|---|---|
color |
NSColor |
The new stroke color. |
graphic.setStrokeLineWidth(width)¶
Alias for graphic.setStrokeWidth.
| Parameter | Type | Description |
|---|---|---|
width |
Number |
The new stroke width. |
graphic.setStrokeWidth(width)¶
Sets the graphic stroke width.
| Parameter | Type | Description |
|---|---|---|
width |
Number |
The new stroke width. |
graphic.setTextStroke(width)¶
Sets the text stroke width for a text graphic.
| Parameter | Type | Description |
|---|---|---|
width |
Number |
The new text stroke width. |
graphic.strokeColor()¶
Returns the graphic stroke color.
Returns: NSColor The stroke color.
graphic.strokeLineWidth()¶
Alias for graphic.strokeWidth.
Returns: Number The stroke width.
graphic.strokeWidth()¶
Returns the graphic stroke width.
Returns: Number The stroke width.
graphic.textFillColor()¶
Returns the text fill color for a text graphic.
Returns: NSColor The text fill color.
graphic.textStrokeColor()¶
Returns the text stroke color for a text graphic.
Returns: NSColor The text stroke color.
polygonGraphic.scaleXBy_yBy(xScale, yScale)¶
Scales a polygon graphic by the given multipliers.
| Parameter | Type | Description |
|---|---|---|
xScale |
Number |
Horizontal scale multiplier. |
yScale |
Number |
Vertical scale multiplier. |
starGraphic.scaleXBy_yBy(xScale, yScale)¶
Scales a star graphic by the given multipliers.
| Parameter | Type | Description |
|---|---|---|
xScale |
Number |
Horizontal scale multiplier. |
yScale |
Number |
Vertical scale multiplier. |
textGraphic.setHTMLString(html)¶
Replaces a text graphic's contents with HTML.
| Parameter | Type | Description |
|---|---|---|
html |
String |
HTML string to use as text contents. |
textGraphic.setString(string)¶
Replaces a text graphic's plain string contents.
| Parameter | Type | Description |
|---|---|---|
string |
String |
New text contents. |
Group Layer¶
A group layer contains zero or more sub-layers, as well as possibly containing additional group layers which can contain their own layers. Group layer extends Layer.
groupLayer.addBitmapLayer()¶
Adds a new bitmap layer to the group.
Returns: BitmapLayer The new bitmap layer.
groupLayer.addGroupLayer()¶
Adds a new group layer to the group.
Returns: GroupLayer The new group layer.
groupLayer.addShapeLayer()¶
Adds a new shape layer to the group.
Returns: ShapeLayer The new shape layer.
groupLayer.insertCGImage_atIndex_withName(image, index, layerName)¶
Inserts a CGImage into the group as a bitmap layer.
| Parameter | Type | Description |
|---|---|---|
image |
CGImageRef |
Image to insert. |
index |
Number |
Insertion index. |
layerName |
String |
Name for the new layer. |
Returns: BitmapLayer The inserted bitmap layer.
groupLayer.insertCIImage_atIndex_withName(image, index, layerName)¶
Inserts a CIImage into the group as a bitmap layer.
| Parameter | Type | Description |
|---|---|---|
image |
CIImage |
Image to insert. |
index |
Number |
Insertion index. |
layerName |
String |
Name for the new layer. |
Returns: BitmapLayer The inserted bitmap layer.
groupLayer.insertImageWithPath_atIndex_withName(path, index, layerName)¶
Inserts an image file into the group as a bitmap layer.
| Parameter | Type | Description |
|---|---|---|
path |
String |
Path to the image file. |
index |
Number |
Insertion index. |
layerName |
String |
Name for the new layer. |
Returns: BitmapLayer The inserted bitmap layer.
document.insertLayerWithImagePath_atIndex(imagePath, index)¶
Adds a new layer with the image from imagePath, and inserts it at the given index.
| Parameter | Type | Description |
|---|---|---|
imagePath |
String |
Path to the image file. |
index |
Number |
Insertion index. |
Returns: BitmapLayer The inserted bitmap layer.
Layer¶
A base class that all layer types (bitmap, shape, and group) inherit from.
layer.addMask()¶
Adds a mask to the layer. If a selection exists, the mask is initialized from it.
layer.appendFilterWithName(name)¶
Appends a Core Image filter to the layer's filter chain. This will also bring up the filter palette where you can change the various settings for this filter. Visit cifilter.app for a nice resource on the various filters you can use.
| Parameter | Type | Description |
|---|---|---|
name |
String |
The Core Image filter name. |
layer.appendFilterWithName_parameters(name, parameters)¶
Appends a Core Image filter to the layer's filter chain and applies input parameters.
| Parameter | Type | Description |
|---|---|---|
name |
String |
The Core Image filter name. |
parameters |
Object |
Filter input values keyed by Core Image input name. |
layer.autoLevels()¶
Adds a Levels filter to the given layer, and balances the levels automatically
layer.bounds()¶
Returns the layer bounds.
Returns: NSRect The layer bounds.
layer.compositingMode¶
Gets or sets the layer compositing mode as a CGBlendMode value.
layer.layerName¶
Gets or sets the layer name.
layer.layerType()¶
Returns the layer type constant.
Returns: Number The layer type, such as ACBitmapLayer, ACShapeLayer, ACGroupLayer, or ACMaskLayer.
layer.loadFilterPresetWithName(name)¶
Loads a saved layer filter preset onto the layer.
| Parameter | Type | Description |
|---|---|---|
name |
String |
The filter preset name. |
layer.mask()¶
Returns the layer mask.
Returns: MaskLayer The mask layer, or null if the layer has no mask.
layer.maskIsLinked()¶
Returns whether the layer mask moves with the layer. See also setMaskIsLinked
Returns: Boolean True when the mask is linked to the layer.
layer.opacity¶
Gets or sets the layer opacity as a floating-point value from 0.0 to 1.0.
layer.opaqueFrame()¶
Returns the layer's opaque bounds in canvas coordinates. You could use these bounds to trim the image, or start a crop.
Returns: NSRect The opaque layer frame.
layer.renderedCIImage()¶
Returns a Core Image rendering of the layer with opacity, filters, mask, and blending applied.
Returns: CIImage The rendered layer image.
layer.setBlendMode(blendString)¶
Changes the blend (composite) mode of the layer. Valid values are: "passThrough", "normal", "multiply", "screen", "overlay", "darken", "lighten", "colorDodge", "colorBurn", "softLight", "hardLight", "difference", "exclusion", "hue", "saturation", "color", "luminosity", "clear", "copy", "copyOpaqueOnly", "sourceIn", "sourceOut", "sourceAtop", "destinationOver", "destinationIn", "destinationOut", "destinationAtop", "xor", "plusDarker", "plusLighter", "divide", "linearBurn", "linearDodge", "lighterColor", "darkerColor", "subtract", "hardmix", "mask", "pinLight", "vividLight", "linearLight"
| Parameter | Type | Description |
|---|---|---|
blendString |
String |
A string representing the blend (composite) mode. |
layer.setLayerMaskImage(image)¶
Sets the layer mask from a CIImage, creating a mask if needed.
| Parameter | Type | Description |
|---|---|---|
image |
CIImage |
The image to use for the mask. |
layer.setLayerMaskWithImageAtPath(path)¶
Sets the layer mask from an image file path, creating a mask if needed.
| Parameter | Type | Description |
|---|---|---|
path |
String |
Path to the mask image. |
layer.setLayerMaskWithImageAtURL(url)¶
Sets the layer mask from an image URL, creating a mask if needed.
| Parameter | Type | Description |
|---|---|---|
url |
NSURL |
URL for the mask image. |
layer.setMaskIsLinked(linked)¶
Sets whether the layer mask moves with the layer.
| Parameter | Type | Description |
|---|---|---|
linked |
Boolean |
True to link the mask to the layer. |
layer.visible¶
Gets or sets the visibility of a layer.
layer.writeToFile_withUTI_properties(path, uti, dict)¶
Writes the layer to a file using the given Uniform Type Identifier. Use this method to export or save a single layer.
| Parameter | Type | Description |
|---|---|---|
path |
String |
Destination file path. |
uti |
String |
Uniform Type Identifier for the output format. |
properties |
Dictionary |
A dictionary of image properties. The properties are passed to CGImageDestinationAddImage as the properties dictionary. |
Returns: Boolean True when the write succeeds.
Shape Layer¶
Shape layers are an extension of the Layer object, and contain vector graphics (aka - Graphic objects)
shapeLayer.addBezierPath(path)¶
Adds a Bezier path graphic to the shape layer.
| Parameter | Type | Description |
|---|---|---|
path |
NSBezierPath |
Path to add as a shape. |
Returns: BezierGraphic The new Bezier graphic.
shapeLayer.addOvalWithBounds(bounds)¶
Adds an oval graphic to the shape layer.
| Parameter | Type | Description |
|---|---|---|
bounds |
NSRect |
Oval bounds in canvas coordinates. |
Returns: Graphic The new oval graphic.
shapeLayer.addRectangleWithBounds(bounds)¶
Adds a rectangle graphic to the shape layer.
| Parameter | Type | Description |
|---|---|---|
bounds |
NSRect |
Rectangle bounds in canvas coordinates. |
Returns: Graphic The new rectangle graphic.
shapeLayer.addTextWithBounds(bounds)¶
Adds a text graphic to the shape layer.
| Parameter | Type | Description |
|---|---|---|
bounds |
NSRect |
Text bounds in canvas coordinates. |
Returns: TextGraphic The new text graphic.
shapeLayer.graphics()¶
Returns the vector graphics contained by a shape layer. This method will work on a base layer object, but it is only on shape layers that the array will be filled with anything.
Returns: NSArray The layer graphics.
shapeLayer.moveGraphic_toIndex(graphic, index)¶
Moves a graphic to a new index in the shape layer.
| Parameter | Type | Description |
|---|---|---|
graphic |
Graphic |
The graphic to move. |
index |
Number |
The destination index. |
shapeLayer.selectedGraphics()¶
Returns the selected graphics on a shape layer.
Returns: NSArray The selected graphics.
Tool Palette¶
Methods for reading and changing the current tool palette colors. You can get the current tool palette by calling acorn.toolPalette(). Note - an image must be open for it to return a value, as each document has its own palette. (In the past there was a single global palette, but that is no more… for the most part).
toolPalette.backColor()¶
Returns the current back color.
Returns: NSColor The back color.
toolPalette.frontColor()¶
Returns the current front color.
Returns: NSColor The front color.
toolPalette.setBackColor(color)¶
Sets the current back color.
| Parameter | Type | Description |
|---|---|---|
color |
NSColor |
The new back color. |
toolPalette.setFrontColor(color)¶
Sets the current front color.
| Parameter | Type | Description |
|---|---|---|
color |
NSColor |
The new front color. |