Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Core/PARImage+ASCIIInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Foundation/Foundation.h>

// iOS
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
Expand All @@ -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

Expand Down
12 changes: 10 additions & 2 deletions Core/PARImage+ASCIIInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
Expand All @@ -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];
{
Expand Down