Upload
masayuki-nii
View
329
Download
7
Embed Size (px)
Citation preview
CoreGraphicsによるPDF表示
UIViewを継承したクラスのdrawRect:メソッドに以下のようなPDFページの描画を行えばよい
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL ( (CFURLRef)sampleURL );CGPDFPageRef pageRef = CGPDFDocumentGetPage ( document, self.page );CGRect pageRect = CGPDFPageGetBoxRect( pageRef, kCGPDFMediaBox );NSInteger angle = CGPDFPageGetRotationAngle( pageRef ); : :CGContextDrawPDFPage ( context, pageRef );
32011年5月27日金曜日
座標変換(アフィン変換)
CGContextConcatCTM ( context, CGPDFPageGetDrawingTransform ( pageRef, kCGPDFMediaBox, pageRect, 0, true ));CGContextConcatCTM ( context, CGAffineTransformMakeTranslation( 0, pageRect.size.height) );CGContextConcatCTM ( context, CGAffineTransformMakeScale( 1.0, -1.0 ) );
42011年5月27日金曜日
座標変換と回転角度
Y軸が上下逆さまなので、実際には角度は負の数と解釈される• 90度→ -90度 = 270度• 270度→ - 270度 = 90度• 180度→ -180度 = 180度どうすればいいか?• あらかじめ、180度回転させればいいのでは!• 90度→ 180 - 90 = 90• 270度→ 180 -270 = -90• 180度→ 180 -180 = 0 :この場合はそのままがいいと思われる
72011年5月27日金曜日
90/270度の場合の追加変換
if ( angle == 90 || angle == 270 ) { CGContextConcatCTM( context, CGAffineTransformMakeRotation(M_PI) ); CGContextConcatCTM( context, CGAffineTransformMakeTranslation( -pageRect.size.width, -pageRect.size.height) );}
82011年5月27日金曜日