目标是在pdf页面中获取真实帧以识别搜索到的字符串,我使用PDFKitten lib突出显示搜索到的文本并试图弄清楚如何获取突出显示文本的帧。芯的方法是下一个:仿射变换后获取真实帧
- (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黄色填充?
frame'的'整体概念是没有意义的,除非变换是身份。 Docs对此很清楚。 – matt
那么有没有办法做到这一点?对? –
我不知道“那样做”是什么意思。我不知道你想做什么,你甚至没有解释过什么!但是你的_question_是关于'frame'的,而'frame'是一个纯粹构造的概念,在变换下是没有意义的。 – matt