Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

72 lines (51 sloc) 2.833 kB
var acorn = [JSTalk application:"Acorn"];
var doc = [[acorn orderedDocuments] objectAtIndex:0];
var image = [[[NSImage alloc] initWithData:[doc dataRepresentationOfType:"public.png"]] autorelease];
var bitmap = [image bestRepresentationForDevice:nil];
var extent = NSMakeRect(0, 0, [bitmap pixelsWide], [bitmap pixelsHigh]);
var xOffset = 5;
var yOffset = 35;
var curveHeight = 15;
var imageYOffset = 10;
var whiteBorderWidth = 4;
var doubleBorderWidth = whiteBorderWidth * 2;
var newSize = NSMakeSize(extent.size.width + (whiteBorderWidth * 2),
extent.size.height + imageYOffset + (whiteBorderWidth * 2));
var newImage = [[[NSImage alloc] initWithSize:newSize] autorelease];
[newImage lockFocus];
[[NSGraphicsContext currentContext] saveGraphicsState];
var shadow = [[NSShadow alloc] init];
[shadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:.6]];
var shadowOffset = NSMakeSize(0, -(yOffset + 5));
[shadow setShadowOffset:shadowOffset];
[shadow setShadowBlurRadius:5];
shadow.set()
// make a curved path, at the bottom of our image.
bezierPath = NSBezierPath.bezierPath();
[bezierPath moveToPoint:NSMakePoint(xOffset, 40 + yOffset)];
[bezierPath lineToPoint:NSMakePoint(extent.size.width - (xOffset) + doubleBorderWidth, 40 + yOffset)];
[bezierPath lineToPoint:NSMakePoint(extent.size.width - (xOffset) + doubleBorderWidth, 10 + yOffset)];
[bezierPath curveToPoint:NSMakePoint(newSize.width / 2, curveHeight + yOffset)
controlPoint1:NSMakePoint(extent.size.width - (xOffset), 10 + yOffset)
controlPoint2:NSMakePoint(newSize.width *.75, curveHeight + yOffset)];
[bezierPath curveToPoint:NSMakePoint(xOffset, 10 + yOffset)
controlPoint1:NSMakePoint(newSize.width *.25, curveHeight + yOffset)
controlPoint2:NSMakePoint(xOffset, 10 + yOffset)];
[bezierPath fill];
// get rid of our shadow
[[NSGraphicsContext currentContext] restoreGraphicsState];
// draw a white border
[[NSColor whiteColor] set];
[[NSBezierPath bezierPathWithRect:NSMakeRect(0, imageYOffset, newSize.width, extent.size.height + whiteBorderWidth * 2)] fill];
// draw our gray border around the white border
[[NSColor lightGrayColor] set];
[[NSBezierPath bezierPathWithRect:NSMakeRect(.5, imageYOffset + .5 , newSize.width - 1, (extent.size.height - 1) + (whiteBorderWidth * 2))] stroke];
// NSImage takes into account dpi of the image. So we force it's size, to avoid small images.
[image setSize: extent.size];
// draw our image
[image drawAtPoint:NSMakePoint(whiteBorderWidth, imageYOffset + whiteBorderWidth)
fromRect:NSMakeRect(0, 0, extent.size.width, extent.size.height)
operation:NSCompositeCopy
fraction:1];
[newImage unlockFocus];
[[acorn sharedDocumentController] newDocumentWithImageData:[newImage TIFFRepresentation]];
Jump to Line
Something went wrong with that request. Please try again.