packages feed

svg2q-0.3.1: svg2q.m

#import "svg2q.h"


@implementation QLine

@synthesize x1, x2, y1, y2, strokeColor, strokeWidth;

-(void) drawWithContext:(CGContextRef) context { 
	CGContextSetLineWidth(context, self.strokeWidth);
	CGContextSetStrokeColorWithColor(context, self.strokeColor);
	CGContextMoveToPoint(context, self.x1, self.y1);
	CGContextAddLineToPoint(context, self.x2, self.y2);
	CGContextDrawPath(context, kCGPathStroke);
}

@end

@implementation QPath
@synthesize strokeColor, fillColor, strokeWidth;

@end

@implementation QEllipse

@synthesize strokeColor, fillColor, strokeWidth, x, y, radiusX, radiusY;

-(void) drawWithContext:(CGContextRef)context { 
	CGRect frame = CGRectMake(self.x - self.radiusX, self.y - self.radiusY, 2*self.radiusX, 2*self.radiusY);
	CGContextSetFillColorWithColor(context, self.fillColor);
	CGContextSetStrokeColorWithColor(context, strokeColor);
	CGContextSetLineWidth(context, self.strokeWidth);
	CGContextAddEllipseInRect(context, frame);
	CGContextDrawPath(context, kCGPathFillStroke); 
}


@end

@implementation QRect

@synthesize strokeColor, fillColor, strokeWidth, x, y, radiusX, radiusY, width, height;
	
-(void) drawWithContext:(CGContextRef)context {
	if (self.radiusX > self.width / 2) {
		self.radiusX = self.width / 2;
	}
	if (self.radiusY > self.height / 2) {
		self.radiusY = self.height / 2;
	}
	
	CGContextSetLineWidth(context, self.strokeWidth);
	CGContextSetStrokeColorWithColor(context, self.strokeColor);
	CGContextSetFillColorWithColor(context, self.fillColor);
	CGContextMoveToPoint(context, self.x+self.radiusX, self.y);
	CGContextAddLineToPoint(context, self.x + self.width - self.radiusX, self.y);
	CGContextAddQuadCurveToPoint(context, self.x + self.width, self.y, self.x + self.width, self.y+self.radiusY);
	CGContextAddLineToPoint(context, self.x+self.width, self.y+self.height-self.radiusY);
	CGContextAddQuadCurveToPoint(context, self.x + self.width, self.y + self.height, self.x + self.width - self.radiusX, self.y + self.height);
	CGContextAddLineToPoint(context, self.x + self.radiusX, self.y + self.height);
	CGContextAddQuadCurveToPoint(context, self.x, self.y + self.height, self.x, self.y + self.height - self.radiusY);
	CGContextAddLineToPoint(context, self.x, self.y + self.radiusY);
	CGContextAddQuadCurveToPoint(context, self.x, self.y, self.x + self.radiusX, self.y);
	CGContextDrawPath(context, kCGPathFillStroke); 
}
+(void)drawWithContext:(CGContextRef)context andX:(CGFloat)x andY:(CGFloat)y andRadiusX:(CGFloat)rx andRadiusY:(CGFloat)ry andWidth:(CGFloat)w andHeight:(CGFloat)h andStrokeWidth:(CGFloat)sw andStrokeColor:(CGColorRef)sc {
	if (rx > (w/2)) {
		rx = w/2;
	}
	if (ry > (h/2)) {
		ry = h/2;
	}
	CGContextSetLineWidth(context, sw);
	CGContextSetStrokeColorWithColor(context, sc);
	// 1. top left corner
	CGContextMoveToPoint(context, x+rx, y);
	// 2. line to right corner
	CGContextAddLineToPoint(context, x + w - rx, y);
	// 3. top right rounded corner
	CGContextAddQuadCurveToPoint(context, x + w, y, x + w, y+ry);
	// 4. line down the right
	CGContextAddLineToPoint(context, x + w, y + h - ry);
	// 5. lower right corner
	CGContextAddQuadCurveToPoint(context, x + w, y + h, x + w - rx, y + h);
	// 6. lower line to left corner
	CGContextAddLineToPoint(context, x + rx, y + h);
	// 7. lower left corner
	CGContextAddQuadCurveToPoint(context, x, y+h, x, y + h - ry);
	// 8. line from lower left to upper left
	CGContextAddLineToPoint(context, x, y+ry);
	// 9. upper left corner
	CGContextAddQuadCurveToPoint(context, x, y, x+rx, y);
	
	CGContextStrokePath(context);	
}

+(void)drawWithContext:(CGContextRef)context andX:(CGFloat)x andY:(CGFloat)y andRadiusX:(CGFloat)rx andRadiusY:(CGFloat)ry andWidth:(CGFloat)w andHeight:(CGFloat)h andStrokeWidth:(CGFloat)sw andStrokeColor:(CGColorRef)sc andFillColor:(CGColorRef) fc {
	if (rx > (w/2)) {
		rx = w/2;
	}
	if (ry > (h/2)) {
		ry = h/2;
	}
	CGContextSetLineWidth(context, sw);
	CGContextSetStrokeColorWithColor(context, sc);
	CGContextSetFillColorWithColor(context, fc);
	// 1. top left corner
	CGContextMoveToPoint(context, x+rx, y);
	// 2. line to right corner
	CGContextAddLineToPoint(context, x + w - rx, y);
	// 3. top right rounded corner
	CGContextAddQuadCurveToPoint(context, x + w, y, x + w, y+ry);
	// 4. line down the right
	CGContextAddLineToPoint(context, x + w, y + h - ry);
	// 5. lower right corner
	CGContextAddQuadCurveToPoint(context, x + w, y + h, x + w - rx, y + h);
	// 6. lower line to left corner
	CGContextAddLineToPoint(context, x + rx, y + h);
	// 7. lower left corner
	CGContextAddQuadCurveToPoint(context, x, y+h, x, y + h - ry);
	// 8. line from lower left to upper left
	CGContextAddLineToPoint(context, x, y+ry);
	// 9. upper left corner
	CGContextAddQuadCurveToPoint(context, x, y, x+rx, y);
	
	CGContextDrawPath(context, kCGPathFillStroke);
	
}

@end

@implementation QText

@synthesize strokeColor, strokeWidth, fillColor, fontSize, text, x, y;

-(void) drawWithContext:(CGContextRef)context {
	CGContextSetLineWidth(context, self.strokeWidth);
	CGContextSetStrokeColorWithColor(context, self.strokeColor);
	CGContextSetFillColorWithColor(context, self.fillColor);
	CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
	CGContextSetTextDrawingMode(context, kCGTextFillStroke);
	CGContextSelectFont(context, "Helvetica", self.fontSize, kCGEncodingMacRoman);
	CGContextShowTextAtPoint(context, self.x, self.y, [self.text UTF8String], [self.text length]);
	CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));

}

@end