Syntax Highlighting
April 09, 2011

I now have syntax highlighting on my blog. Let’s see how it works with objc:

- (void)drawRect:(CGRect)rect {
   // Drawing code

	CGContextRef ctx = UIGraphicsGetCurrentContext();

	CGContextClearRect(ctx, rect);
	//[[UIColor clearColor] set];
	//CGContextFillRect(ctx, rect);
	if( makeCache ){
		[self updateBitmapContextIfNeeded];
		CGImageRelease(cachedImage);
		cachedImage = CGBitmapContextCreateImage(backingStore);
		makeCache = NO;
	}
	CGContextDrawImage(ctx, CGRectMake(0, 0, CGBitmapContextGetWidth(backingStore), CGBitmapContextGetHeight(backingStore)), cachedImage);


	CGMutablePathRef path = CGPathCreateMutable();
	CGContextSetLineWidth(ctx, 2.5);
	for(NSMutableDictionary* stroke in intermediateStrokes){
		NSMutableArray* points = [stroke objectForKey:@"points"];
		[self drawPointInCurrentContext:points path:path];
	}

	[[UIColor blackColor] set];
	CGContextAddPath(ctx, path);
	CGContextStrokePath(ctx);
	CGPathRelease(path);

	//[super drawRect:rect];


	/*[[UIColor whiteColor] setStroke];
	UIBezierPath* path = [UIBezierPath path];
	[path moveToPoint:CGPointMake(0, 0	)];
	[path addLineToPoint:CGPointMake(320, 480)];
	[path addLineToPoint:CGPointMake(0, 480)];
	*/
}

Looks like it works! :D

<<  Back