目標是在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