I override the drawRect: method in a custom UIView, and I am doing some custom drawing. Everything went well until I had to draw a PDF resource (more precisely, a vector glyph) into context. First I extract the PDF from the file:
NSURL *pdfURL = [NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"CardKit.bundle/A.pdf"]];
CGPDFDocumentRef pdfDoc = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDoc, 1);
Then I create a window with the same dimensions as the downloaded PDF:
CGRect box = CGPDFPageGetBoxRect(pdfPage, kCGPDFArtBox);
Then I save my graphic state so that I don't blame anything:
CGContextSaveGState(context);
And then I do a CTM scale + translation, theoretically flipping the whole context:
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0.0, rect.size.height);
Then I scale the PDF so that it fits the view correctly:
CGContextScaleCTM(context, rect.size.width/box.size.width, rect.size.height/box.size.height);
And finally, I draw a PDF and restore the state of the graphics:
CGContextDrawPDFPage(context, pdfPage);
CGContextRestoreGState(context);
The problem is that nothing is visible. All this code should theoretically draw a PDF glyphate in the view, right?
+ , , : .
?