Reputation: 2543
I'm new to the CGAffine world. Anyone know why my transformation doesn't work/take ?
I have a valid PDFContext created with UIGraphicsBeginPDFContextToData and the following current matrix:
CGAffineTransform curMat = CGContextGetCTM(context);
NSLog (@"current context matrix: %f %f %f %f %f %f", curMat.a, curMat.b, curMat.c, curMat.d, curMat.tx, curMat.ty);
NSLog values:
current matrix: 1.000000 0.000000 -0.000000 -1.000000 0.000000 792.000000
I create the transformation matrix with:
CGAffineTransform xform = CGAffineTransformMake(a, b, c, d, tx, ty);
NSLog values:
transform matrix: 0.062500 0.000000 0.000000 0.062500 0.000000 0.000000
I get the my rect from:
CGRect pdfBounds = UIGraphicsGetPDFContextBounds();
NSLog values:
pdfBounds: 0.000000 0.000000 612.000000 792.000000
I apply the transformation matrix with:
CGRectApplyAffineTransform (pdfBounds, xform);
Then I re-check the current matrix value with:
CGAffineTransform curMat2 = CGContextGetCTM(context);
NSLog (@"current context matrix after transformation: %f %f %f %f %f %f", curMat2.a, curMat2.b, curMat2.c, curMat2.d, curMat2.tx, curMat2.ty)
and the NSLog values are the same as at the beginning.
current context matrix after transformation: 1.000000 0.000000 -0.000000 -1.000000 0.000000 792.000000
What am I missing ? Why is the transformation not happening/taking ? Thank you.
Upvotes: 2
Views: 1022
Reputation: 57179
You are ignoring the result of the applied transformation and you are also not applying any transformation to the context.
Step 7 should be:
CGContextConcatCTM(context, xform);
Upvotes: 1