Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add PDFPageGetDrawingTransform function (modeled after CGPDFPageGetDr…

…awingTransform, does upscaling)
  • Loading branch information...
commit c0d9bf3f6294ac7b53fc3c1bf440c05d051801e3 1 parent 633deaf
@0xced authored
Showing with 34 additions and 18 deletions.
  1. +30 −0 CGPDFAdditions.c
  2. +2 −0  CGPDFAdditions.h
  3. +2 −18 PDFRasterize.m
View
30 CGPDFAdditions.c
@@ -21,3 +21,33 @@ int PDFPageGetRotation(CGPDFPageRef page)
else
return (4 + ((rotationAngle / 90) % 4)) % 4;
}
+
+CGAffineTransform PDFPageGetDrawingTransform(CGPDFPageRef page, CGPDFBox box, float scale)
+{
+ CGRect boxRect = CGPDFPageGetBoxRect(page, box);
+ int rotation = PDFPageGetRotation(page);
+
+ CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale);
+
+ transform = CGAffineTransformRotate(transform, -(rotation * M_PI_2));
+
+ switch (rotation)
+ {
+ case 1:
+ transform = CGAffineTransformTranslate(transform, -CGRectGetWidth(boxRect), 0);
+ break;
+ case 2:
+ transform = CGAffineTransformTranslate(transform, -CGRectGetWidth(boxRect), 0);
+ transform = CGAffineTransformTranslate(transform, 0, -CGRectGetHeight(boxRect));
+ break;
+ case 3:
+ transform = CGAffineTransformTranslate(transform, 0, -CGRectGetHeight(boxRect));
+ break;
+ default:
+ break;
+ }
+
+ transform = CGAffineTransformTranslate(transform, -boxRect.origin.x, -boxRect.origin.y);
+
+ return transform;
+}
View
2  CGPDFAdditions.h
@@ -21,3 +21,5 @@
*/
int PDFPageGetRotation(CGPDFPageRef page);
+
+CGAffineTransform PDFPageGetDrawingTransform(CGPDFPageRef page, CGPDFBox box, float scale);
View
20 PDFRasterize.m
@@ -284,24 +284,8 @@ - (BOOL) rasterizePage:(CGPDFPageRef)page toURL:(NSURL *)outputURL
}
// CGPDFPageGetDrawingTransform unfortunately does not upscale, see http://lists.apple.com/archives/quartz-dev/2005/Mar/msg00112.html
- CGContextScaleCTM(context, scale, scale);
- CGContextRotateCTM(context, -(rotation * M_PI_2));
- switch (rotation)
- {
- case 1:
- CGContextTranslateCTM(context, -CGRectGetWidth(boxRect), 0);
- break;
- case 2:
- CGContextTranslateCTM(context, -CGRectGetWidth(boxRect), 0);
- CGContextTranslateCTM(context, 0, -CGRectGetHeight(boxRect));
- break;
- case 3:
- CGContextTranslateCTM(context, 0, -CGRectGetHeight(boxRect));
- break;
- default:
- break;
- }
- CGContextTranslateCTM(context, -boxRect.origin.x, -boxRect.origin.y);
+ CGAffineTransform drawingTransform = PDFPageGetDrawingTransform(page, kCGPDFCropBox, scale);
+ CGContextConcatCTM(context, drawingTransform);
CGContextDrawPDFPage(context, page);
Please sign in to comment.
Something went wrong with that request. Please try again.