目的は、検索された文字列を識別するためにpdfページの実際のフレームを取得することです。コアの方法は次である:層のアフィン変換後に実際のフレームを取得する
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
CGContextSetFillColorWithColor(ctx, [[UIColor whiteColor] CGColor]);
CGContextFillRect(ctx, layer.bounds);
// Flip the coordinate system
CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
// Transform coordinate system to match PDF
NSInteger rotationAngle = CGPDFPageGetRotationAngle(pdfPage);
CGAffineTransform transform = CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, layer.bounds, -rotationAngle, YES);
CGContextConcatCTM(ctx, transform);
CGContextDrawPDFPage(ctx, pdfPage);
if (self.keyword)
{
CGContextSetFillColorWithColor(ctx, [[UIColor yellowColor] CGColor]);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
for (Selection *s in self.selections)
{
NSLog(@"layer.bounds = %f, %f, %f, %f", layer.bounds.origin.x, layer.bounds.origin.y, layer.bounds.size.width, layer.bounds.size.height);
CGContextSaveGState(ctx);
CGContextConcatCTM(ctx, s.transform);
NSLog(@"s.frame = %f, %f, %f, %f", s.frame.origin.x, s.frame.origin.y, s.frame.size.width, s.frame.size.height);
CGContextFillRect(ctx, s.frame);
CGContextRestoreGState(ctx);
}
}
}
サイズ(612.000000、792.000000)であるが、s.frameのサイズは(3.110400、1.107000)です。どのようにして黄色で塗られたrectから実際のフレームを得ることができますか?
変換がアイデンティティでない限り、「フレーム」という概念は無意味です。ドキュメントについては、これについてはかなり明確です。 – matt
そうする方法はありませんか?右? –
"それは何を意味するのか"は分かりません。私はあなたが何をしようとしていると思いますか分かりません。あなたは 's'が何であるかを説明していません!しかし、あなたの_question_は 'frame'についてのものであり、' frame'は純粋に構築された概念であり、変換のもとでは意味がありません。 – matt