diff --git a/Framework/IJSVG/IJSVG/Source/Layers/IJSVGImageLayer.m b/Framework/IJSVG/IJSVG/Source/Layers/IJSVGImageLayer.m
index d479fc1..fc3972e 100644
--- a/Framework/IJSVG/IJSVG/Source/Layers/IJSVGImageLayer.m
+++ b/Framework/IJSVG/IJSVG/Source/Layers/IJSVGImageLayer.m
@@ -29,15 +29,15 @@
CGImageRef image = _image.CGImage;
CGRect imageDrawRect = _image.intrinsicBounds;
CGRect currentBounds = self.bounds;
- IJSVGViewBoxDrawingBlock drawBlock = ^(CGRect computedRect, CGFloat scale[]) {
+ IJSVGViewBoxDrawingBlock drawBlock = ^(CGFloat scale[]) {
// image will be upside down, so just translate it back on itself
CGContextConcatCTM(ctx, CGAffineTransformMakeScale(1.f, -1.f));
CGContextTranslateCTM(ctx, 0.f, -CGRectGetHeight(imageDrawRect));
CGContextDrawImage(ctx, imageDrawRect, image);
};
- IJSVGContextDrawViewBox(ctx, _image.intrinsicBounds, currentBounds,
- _image.viewBoxAlignment, _image.viewBoxMeetOrSlice,
- drawBlock);
+ IJSVGContextDrawViewBox(ctx, imageDrawRect, currentBounds,
+ _image.viewBoxAlignment,
+ _image.viewBoxMeetOrSlice, drawBlock);
}
@end
diff --git a/Framework/IJSVG/IJSVG/Source/Layers/IJSVGPatternLayer.m b/Framework/IJSVG/IJSVG/Source/Layers/IJSVGPatternLayer.m
index 6a1b36c..cc04452 100644
--- a/Framework/IJSVG/IJSVG/Source/Layers/IJSVGPatternLayer.m
+++ b/Framework/IJSVG/IJSVG/Source/Layers/IJSVGPatternLayer.m
@@ -45,12 +45,13 @@ void IJSVGPatternDrawingCallBack(void* info, CGContextRef ctx)
IJSVGViewBoxAlignment alignment = layer.patternNode.viewBoxAlignment;
IJSVGViewBoxMeetOrSlice meetOrSlice = layer.patternNode.viewBoxMeetOrSlice;
CGRect viewBox = layer.viewBox;
- IJSVGViewBoxDrawingBlock drawBlock = ^(CGRect computedRect, CGFloat scale[]) {
+ IJSVGViewBoxDrawingBlock drawBlock = ^(CGFloat scale[]) {
[IJSVGLayer renderLayer:layer.pattern
inContext:ctx
options:IJSVGLayerDrawingOptionNone];
};
- IJSVGContextDrawViewBox(ctx, viewBox, rect, alignment, meetOrSlice, drawBlock);
+ IJSVGContextDrawViewBox(ctx, viewBox, rect, alignment, meetOrSlice,
+ drawBlock);
CGContextSaveGState(ctx);
};
diff --git a/Framework/IJSVG/IJSVG/Source/Layers/IJSVGRootLayer.m b/Framework/IJSVG/IJSVG/Source/Layers/IJSVGRootLayer.m
index 24c9e69..1d104b7 100644
--- a/Framework/IJSVG/IJSVG/Source/Layers/IJSVGRootLayer.m
+++ b/Framework/IJSVG/IJSVG/Source/Layers/IJSVGRootLayer.m
@@ -15,7 +15,7 @@
if(self.viewBox != nil) {
CGRect viewBox = [self.viewBox computeValue:CGSizeZero];
__weak IJSVGRootLayer* weakSelf = self;
- IJSVGViewBoxDrawingBlock drawingBlock = ^(CGRect computedRect, CGFloat scale[]) {
+ IJSVGViewBoxDrawingBlock drawingBlock = ^(CGFloat scale[]) {
CGContextSaveGState(ctx);
// we have to make sure we set the backing scale factor once
// we know how scale this will be drawn at
@@ -29,8 +29,8 @@
};
IJSVGContextDrawViewBox(ctx, viewBox, self.boundingBoxBounds,
- self.viewBoxAlignment, self.viewBoxMeetOrSlice,
- drawingBlock);
+ self.viewBoxAlignment,
+ self.viewBoxMeetOrSlice, drawingBlock);
return;
}
[super performRenderInContext:ctx];
diff --git a/Framework/IJSVG/IJSVG/Source/Utils/IJSVGViewBox.h b/Framework/IJSVG/IJSVG/Source/Utils/IJSVGViewBox.h
index 8901a4c..4c78b25 100644
--- a/Framework/IJSVG/IJSVG/Source/Utils/IJSVGViewBox.h
+++ b/Framework/IJSVG/IJSVG/Source/Utils/IJSVGViewBox.h
@@ -29,31 +29,33 @@ typedef NS_ENUM(NSInteger, IJSVGViewBoxMeetOrSlice) {
IJSVGViewBoxMeetOrSliceSlice,
};
-typedef CGRect (*IJSVGViewBoxComputeRectFunction)(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale);
+typedef CGAffineTransform (*IJSVGViewBoxComputeTransformFunction)(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice);
@interface IJSVGViewBox : NSObject
-typedef void (^IJSVGViewBoxDrawingBlock)(CGRect computedRect, CGFloat scale[]);
+typedef void (^IJSVGViewBoxDrawingBlock)(CGFloat scale[]);
+ (IJSVGViewBoxAlignment)alignmentForString:(NSString*)string
meetOrSlice:(IJSVGViewBoxMeetOrSlice*)meetOrSlice;
+ (IJSVGViewBoxAlignment)alignmentForString:(NSString*)string;
+ (IJSVGViewBoxMeetOrSlice)meetOrSliceForString:(NSString*)string;
-CGRect IJSVGViewBoxComputeRect(CGRect viewBox, CGRect drawingRect, IJSVGViewBoxAlignment alignment,
- IJSVGViewBoxMeetOrSlice meetOrSlice, CGFloat* scale);
+CGAffineTransform IJSVGViewBoxComputeTransform(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxAlignment alignment,
+ IJSVGViewBoxMeetOrSlice meetOrSlice);
-void IJSVGContextDrawViewBox(CGContextRef ctx, CGRect viewBox, CGRect boundingBox,
- IJSVGViewBoxAlignment alignment, IJSVGViewBoxMeetOrSlice meetOrSlice,
- IJSVGViewBoxDrawingBlock block);
+CGAffineTransform IJSVGContextDrawViewBox(CGContextRef ctx, CGRect viewBox,
+ CGRect boundingBox,
+ IJSVGViewBoxAlignment alignment,
+ IJSVGViewBoxMeetOrSlice meetOrSlice,
+ IJSVGViewBoxDrawingBlock block);
-+ (void)drawViewBox:(CGRect)viewBox
- inRect:(CGRect)drawingRect
- alignment:(IJSVGViewBoxAlignment)alignment
- meetOrSlice:(IJSVGViewBoxMeetOrSlice)meetOrSlice
- inContext:(CGContextRef)ctx
- drawingBlock:(IJSVGViewBoxDrawingBlock)block;
++ (CGAffineTransform)drawViewBox:(CGRect)viewBox
+ inRect:(CGRect)drawingRect
+ alignment:(IJSVGViewBoxAlignment)alignment
+ meetOrSlice:(IJSVGViewBoxMeetOrSlice)meetOrSlice
+ inContext:(CGContextRef)ctx
+ drawingBlock:(IJSVGViewBoxDrawingBlock)block;
@end
diff --git a/Framework/IJSVG/IJSVG/Source/Utils/IJSVGViewBox.m b/Framework/IJSVG/IJSVG/Source/Utils/IJSVGViewBox.m
index e574b12..e1bf559 100644
--- a/Framework/IJSVG/IJSVG/Source/Utils/IJSVGViewBox.m
+++ b/Framework/IJSVG/IJSVG/Source/Utils/IJSVGViewBox.m
@@ -85,46 +85,35 @@
return IJSVGViewBoxAlignmentUnknown;
}
-CGRect IJSVGViewBoxComputeRectXMidYMid(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMidYMid(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
// translate it
- CGAffineTransform translate = CGAffineTransformMakeTranslation(drawingRect.size.width / 2.f - (viewBox.size.width * ratio) / 2.f,
- drawingRect.size.height / 2.f - (viewBox.size.height * ratio) / 2.f);
+ CGFloat originX = drawingRect.size.width / 2.f - (viewBox.size.width * ratio) / 2.f;
+ CGFloat originY = drawingRect.size.height / 2.f - (viewBox.size.height * ratio) / 2.f;
+ originX += -(viewBox.origin.x * ratio);
+ originY += -(viewBox.origin.y * ratio);
+
+ CGAffineTransform translate = CGAffineTransformMakeTranslation(originX, originY);
transform = CGAffineTransformConcat(transform, translate);
- translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
- -(viewBox.origin.y * ratio));
- transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectXMinYMid(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMinYMid(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
@@ -136,22 +125,16 @@ CGRect IJSVGViewBoxComputeRectXMinYMid(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
-(viewBox.origin.y * ratio));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectXMaxYMid(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMaxYMid(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
@@ -163,22 +146,16 @@ CGRect IJSVGViewBoxComputeRectXMaxYMid(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
-(viewBox.origin.y * ratio));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectXMidYMin(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMidYMin(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
@@ -190,22 +167,16 @@ CGRect IJSVGViewBoxComputeRectXMidYMin(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
-(viewBox.origin.y * ratio));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectXMinYMin(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMinYMin(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
@@ -216,22 +187,16 @@ CGRect IJSVGViewBoxComputeRectXMinYMin(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
-(viewBox.origin.y * ratio));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectXMidYMax(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMidYMax(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
@@ -243,22 +208,16 @@ CGRect IJSVGViewBoxComputeRectXMidYMax(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
-(viewBox.origin.y * ratio));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectXMaxYMin(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMaxYMin(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
@@ -270,22 +229,16 @@ CGRect IJSVGViewBoxComputeRectXMaxYMin(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
-(viewBox.origin.y * ratio));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectXMinYMax(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMinYMax(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
@@ -297,22 +250,16 @@ CGRect IJSVGViewBoxComputeRectXMinYMax(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
-(viewBox.origin.y * ratio));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectXMaxYMax(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectXMaxYMax(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
CGFloat ratio = meetOrSlice == IJSVGViewBoxMeetOrSliceMeet ? MIN(width, height) : MAX(width, height);
- if(scale != NULL) {
- scale[0] = ratio;
- scale[1] = ratio;
- }
-
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(ratio, ratio));
@@ -324,21 +271,15 @@ CGRect IJSVGViewBoxComputeRectXMaxYMax(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * ratio),
-(viewBox.origin.y * ratio));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGViewBoxComputeRectNone(CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeRectNone(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
CGFloat width = drawingRect.size.width / viewBox.size.width;
CGFloat height = drawingRect.size.height / viewBox.size.height;
-
- if(scale != NULL) {
- scale[0] = width;
- scale[1] = height;
- }
-
+
// scale the viewBox into the drawingRect
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(width, height));
@@ -350,104 +291,98 @@ CGRect IJSVGViewBoxComputeRectNone(CGRect viewBox, CGRect drawingRect,
translate = CGAffineTransformMakeTranslation(-(viewBox.origin.x * width),
-(viewBox.origin.y * height));
transform = CGAffineTransformConcat(transform, translate);
- return CGRectApplyAffineTransform(drawingRect, transform);
+ return transform;
}
-CGRect IJSVGContextViewBoxConcatNone(CGContextRef ctx, CGRect viewBox,
- CGRect drawingRect, IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
+CGAffineTransform IJSVGContextViewBoxConcat(CGContextRef ctx, IJSVGViewBoxComputeTransformFunction function,
+ CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
- CGFloat ratioX = 1.f;
- CGFloat ratioY = 1.f;
- CGRect rect = IJSVGViewBoxComputeRectNone(viewBox, drawingRect, meetOrSlice, scale);
- CGContextTranslateCTM(ctx, rect.origin.x, rect.origin.y);
- CGContextScaleCTM(ctx, ratioX, ratioY);
- return rect;
+ // if both are equal, nothing will happen, it will be mapped 1:1
+ if(CGRectEqualToRect(viewBox, drawingRect) == YES) {
+ return CGAffineTransformIdentity;
+ }
+ CGAffineTransform transform;
+ transform = function(viewBox, drawingRect, meetOrSlice);
+ CGContextConcatCTM(ctx, transform);
+ return transform;
}
-CGRect IJSVGContextViewBoxConcat(CGContextRef ctx, IJSVGViewBoxComputeRectFunction function,
- CGRect viewBox, CGRect drawingRect,
- IJSVGViewBoxMeetOrSlice meetOrSlice,
- CGFloat* scale)
-{
- CGRect rect = function(viewBox, drawingRect, meetOrSlice, scale);
- CGContextTranslateCTM(ctx, rect.origin.x, rect.origin.y);
- CGContextScaleCTM(ctx, scale[0], scale[1]);
- return rect;
+CGAffineTransform IJSVGContextDrawViewBox(CGContextRef ctx, CGRect viewBox,
+ CGRect boundingBox,
+ IJSVGViewBoxAlignment alignment,
+ IJSVGViewBoxMeetOrSlice meetOrSlice,
+ IJSVGViewBoxDrawingBlock block) {
+ return [IJSVGViewBox drawViewBox:viewBox
+ inRect:boundingBox
+ alignment:alignment
+ meetOrSlice:meetOrSlice
+ inContext:ctx
+ drawingBlock:block];
}
-void IJSVGContextDrawViewBox(CGContextRef ctx, CGRect viewBox, CGRect boundingBox,
- IJSVGViewBoxAlignment alignment, IJSVGViewBoxMeetOrSlice meetOrSlice,
- IJSVGViewBoxDrawingBlock block) {
- [IJSVGViewBox drawViewBox:viewBox
- inRect:boundingBox
- alignment:alignment
- meetOrSlice:meetOrSlice
- inContext:ctx
- drawingBlock:block];
-}
-
-CGRect IJSVGViewBoxComputeRect(CGRect viewBox, CGRect drawingRect, IJSVGViewBoxAlignment alignment,
- IJSVGViewBoxMeetOrSlice meetOrSlice, CGFloat* scale)
+CGAffineTransform IJSVGViewBoxComputeTransform(CGRect viewBox, CGRect drawingRect,
+ IJSVGViewBoxAlignment alignment,
+ IJSVGViewBoxMeetOrSlice meetOrSlice)
{
switch(alignment) {
default:
case IJSVGViewBoxAlignmentUnknown:
case IJSVGViewBoxAlignmentXMidYMid: {
return IJSVGViewBoxComputeRectXMidYMid(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentNone: {
return IJSVGViewBoxComputeRectNone(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentXMaxYMax: {
return IJSVGViewBoxComputeRectXMaxYMax(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentXMaxYMid: {
return IJSVGViewBoxComputeRectXMaxYMid(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentXMaxYMin: {
return IJSVGViewBoxComputeRectXMaxYMin(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentXMidYMax: {
return IJSVGViewBoxComputeRectXMidYMax(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentXMidYMin: {
return IJSVGViewBoxComputeRectXMidYMin(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentXMinYMax: {
return IJSVGViewBoxComputeRectXMinYMin(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentXMinYMid: {
return IJSVGViewBoxComputeRectXMinYMid(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
case IJSVGViewBoxAlignmentXMinYMin: {
return IJSVGViewBoxComputeRectXMinYMin(viewBox, drawingRect,
- meetOrSlice, scale);
+ meetOrSlice);
}
}
- return CGRectNull;
+ return CGAffineTransformIdentity;
}
-+ (void)drawViewBox:(CGRect)viewBox
- inRect:(CGRect)drawingRect
- alignment:(IJSVGViewBoxAlignment)alignment
- meetOrSlice:(IJSVGViewBoxMeetOrSlice)meetOrSlice
- inContext:(CGContextRef)ctx
- drawingBlock:(IJSVGViewBoxDrawingBlock)block
++ (CGAffineTransform)drawViewBox:(CGRect)viewBox
+ inRect:(CGRect)drawingRect
+ alignment:(IJSVGViewBoxAlignment)alignment
+ meetOrSlice:(IJSVGViewBoxMeetOrSlice)meetOrSlice
+ inContext:(CGContextRef)ctx
+ drawingBlock:(IJSVGViewBoxDrawingBlock)block
{
// this is equal to none, dont do anything fancy
if(CGRectIsNull(viewBox) == YES ||
CGRectEqualToRect(viewBox, CGRectZero) == YES) {
- return;
+ return CGAffineTransformIdentity;
}
CGContextSaveGState(ctx);
@@ -460,73 +395,69 @@ CGRect IJSVGViewBoxComputeRect(CGRect viewBox, CGRect drawingRect, IJSVGViewBoxA
scale[0] = 1.f;
scale[1] = 1.f;
- CGRect computedRect = CGRectNull;
+ CGAffineTransform transform = CGAffineTransformIdentity;
switch(alignment) {
case IJSVGViewBoxAlignmentNone: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectNone,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectNone,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentUnknown:
case IJSVGViewBoxAlignmentXMidYMid: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMidYMid,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMidYMid,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentXMinYMid: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMinYMid,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMinYMid,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentXMaxYMid: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMaxYMid,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMaxYMid,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentXMidYMin: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMidYMin,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMidYMin,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentXMidYMax: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMidYMax,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMidYMax,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentXMinYMin: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMinYMin,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMinYMin,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentXMaxYMin: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMaxYMin,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMaxYMin,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentXMinYMax: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMinYMax,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMinYMax,
+ viewBox, drawingRect, meetOrSlice);
break;
}
case IJSVGViewBoxAlignmentXMaxYMax: {
- computedRect = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMaxYMax,
- viewBox, drawingRect, meetOrSlice,
- scale);
+ transform = IJSVGContextViewBoxConcat(ctx, &IJSVGViewBoxComputeRectXMaxYMax,
+ viewBox, drawingRect, meetOrSlice);
break;
}
}
- block(computedRect, scale);
+ // grab the scale from the transform
+ scale[0] = transform.a;
+ scale[1] = transform.d;
+
+ // call the draw block and memory clean / restore context
+ block(scale);
free(scale);
CGContextRestoreGState(ctx);
+ return transform;
}
@end
diff --git a/IJSVGExample/IJSVGExample/Bayer_matrix.svg b/IJSVGExample/IJSVGExample/Bayer_matrix.svg
new file mode 100644
index 0000000..267165f
--- /dev/null
+++ b/IJSVGExample/IJSVGExample/Bayer_matrix.svg
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/IJSVGExample/IJSVGExample/aspect-ratio.svg b/IJSVGExample/IJSVGExample/aspect-ratio.svg
new file mode 100644
index 0000000..59a9770
--- /dev/null
+++ b/IJSVGExample/IJSVGExample/aspect-ratio.svg
@@ -0,0 +1,84 @@
+
\ No newline at end of file
diff --git a/IJSVGExample/IJSVGExample/couchdb.svg b/IJSVGExample/IJSVGExample/couchdb.svg
new file mode 100644
index 0000000..1b1c8b1
--- /dev/null
+++ b/IJSVGExample/IJSVGExample/couchdb.svg
@@ -0,0 +1,5 @@
+
+
+
+
+