From 6d2315106750d2371539d57b8c2936cc7e5b4d84 Mon Sep 17 00:00:00 2001 From: mz2 Date: Tue, 17 Mar 2015 02:16:14 +0000 Subject: [PATCH 1/3] Reorders imports so that PARImage+ASCIInput doesn't rely on a prefix header. --- .../contents.xcworkspacedata | 7 +++++++ Core/PARImage+ASCIIInput.h | 17 ++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 ASCIImage.xcodeproj/project.xcworkspace/contents.xcworkspacedata 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..abae713 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,14 @@ 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; +@interface PARImage (ASCIIInput) /// @name Creating Images from ASCII Input From 6820780bd50759331afb701215d67facc6208eb8 Mon Sep 17 00:00:00 2001 From: mz2 Date: Wed, 18 Mar 2015 13:07:47 +0000 Subject: [PATCH 2/3] Adds an optional scale parameter to the ASCIImage drawing context. --- Core/PARImage+ASCIIInput.h | 1 + Core/PARImage+ASCIIInput.m | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Core/PARImage+ASCIIInput.h b/Core/PARImage+ASCIIInput.h index abae713..2e68578 100755 --- a/Core/PARImage+ASCIIInput.h +++ b/Core/PARImage+ASCIIInput.h @@ -27,6 +27,7 @@ extern NSString * const ASCIIContextStrokeColor; extern NSString * const ASCIIContextLineWidth; extern NSString * const ASCIIContextShouldClose; extern NSString * const ASCIIContextShouldAntialias; +extern NSString * const ASCIIContextScale; @interface PARImage (ASCIIInput) diff --git a/Core/PARImage+ASCIIInput.m b/Core/PARImage+ASCIIInput.m index caefe47..81399dc 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,14 @@ + (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; + // 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) From f8e9a56f52b473bdd3e169abda0ec2863d8af3f5 Mon Sep 17 00:00:00 2001 From: mz2 Date: Wed, 18 Mar 2015 14:21:37 +0000 Subject: [PATCH 3/3] Oops, fixes the scale handling (some changes were missing). --- Core/PARImage+ASCIIInput.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/PARImage+ASCIIInput.m b/Core/PARImage+ASCIIInput.m index 81399dc..2641bb3 100755 --- a/Core/PARImage+ASCIIInput.m +++ b/Core/PARImage+ASCIIInput.m @@ -510,6 +510,8 @@ + (PARImage *)mac_imageWithASCIIRepresentation:(NSArray *)rep contextHandler:(vo 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; @@ -526,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); } @@ -540,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]; {