diff --git a/ASCIImage.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ASCIImage.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..7435c0f --- /dev/null +++ b/ASCIImage.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Core/PARImage+ASCIIInput.h b/Core/PARImage+ASCIIInput.h index 0d54e62..2e68578 100755 --- a/Core/PARImage+ASCIIInput.h +++ b/Core/PARImage+ASCIIInput.h @@ -2,14 +2,7 @@ // Created by Charles Parnot on 5/29/13. // Copyright (c) 2013 Charles Parnot. All rights reserved. - -extern NSString * const ASCIIContextShapeIndex; -extern NSString * const ASCIIContextFillColor; -extern NSString * const ASCIIContextStrokeColor; -extern NSString * const ASCIIContextLineWidth; -extern NSString * const ASCIIContextShouldClose; -extern NSString * const ASCIIContextShouldAntialias; - +#import // iOS #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR @@ -28,8 +21,15 @@ extern NSString * const ASCIIContextShouldAntialias; #endif -@interface PARImage (ASCIIInput) +extern NSString * const ASCIIContextShapeIndex; +extern NSString * const ASCIIContextFillColor; +extern NSString * const ASCIIContextStrokeColor; +extern NSString * const ASCIIContextLineWidth; +extern NSString * const ASCIIContextShouldClose; +extern NSString * const ASCIIContextShouldAntialias; +extern NSString * const ASCIIContextScale; +@interface PARImage (ASCIIInput) /// @name Creating Images from ASCII Input diff --git a/Core/PARImage+ASCIIInput.m b/Core/PARImage+ASCIIInput.m index caefe47..2641bb3 100755 --- a/Core/PARImage+ASCIIInput.m +++ b/Core/PARImage+ASCIIInput.m @@ -11,6 +11,7 @@ NSString * const ASCIIContextLineWidth = @"ASCIIContextLineWidth"; NSString * const ASCIIContextShouldClose = @"ASCIIContextShouldClose"; NSString * const ASCIIContextShouldAntialias = @"ASCIIContextShouldAntialias"; +NSString * const ASCIIContextScale = @"ASCIIContextScale"; #pragma mark - PARImage Cross-Platform Image Class @@ -506,10 +507,16 @@ + (PARImage *)mac_imageWithASCIIRepresentation:(NSArray *)rep contextHandler:(vo NSArray *strictRep = [self strictASCIIRepresentationFromLenientASCIIRepresentation:rep]; NSArray *shapes = [self shapesFromNumbersInStrictASCIIRepresentation:strictRep]; + NSMutableDictionary *imgContext = [NSMutableDictionary dictionary]; + contextHandler(imgContext); + CGFloat scale = imgContext[ASCIIContextScale] ? [imgContext[ASCIIContextScale] doubleValue] : 1.0f; + NSAffineTransform *scaleTransform = [NSAffineTransform new]; + [scaleTransform scaleBy:scale]; + // image size NSUInteger countRows = strictRep.count; NSUInteger countCols = [strictRep[0] length]; - NSSize imageSize = NSMakeSize(countCols, countRows); + NSSize imageSize = NSMakeSize(countCols * scale, countRows * scale); // image is drawn using the block API, so we can handle @2x drawing in HiDPI NSImage *image = [NSImage imageWithSize:imageSize flipped:NO drawingHandler:^BOOL(NSRect dstRect) @@ -521,6 +528,7 @@ + (PARImage *)mac_imageWithASCIIRepresentation:(NSArray *)rep contextHandler:(vo // ... but don't let the handler mess up the graphics context NSMutableDictionary *contextASCII = [NSMutableDictionary dictionaryWithDictionary:@{ASCIIContextShapeIndex: @(shapeIndex)}]; [[NSGraphicsContext currentContext] saveGraphicsState]; + { contextHandler(contextASCII); } @@ -535,7 +543,7 @@ + (PARImage *)mac_imageWithASCIIRepresentation:(NSArray *)rep contextHandler:(vo // bezier path from shape PARBezierPath *path = shouldClose ? [shape closedBezierPath] : [shape bezierPath]; - + [path transformUsingAffineTransform:scaleTransform]; // draw! [[NSGraphicsContext currentContext] saveGraphicsState]; {