목표는 검색된 문자열을 식별하기 위해 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에서 실제 프레임을 어떻게 얻을 수 있습니까?
전체 개념은 의미가 없습니다. 문서 도구는 이에 대해 아주 분명합니다. – matt
그렇게 할 방법이 없습니까? 권리? –
"그게"무슨 뜻인지 모르겠다. 나는 네가 네가 뭘 하려는지 생각하지 않는다. 당신은's'이 무엇인지 설명조차하지 못했습니다! 하지만 당신의 _question_은'frame'에 관한 것이고,'frame'은 변환 과정에서 의미가없는 순수한 개념입니다. – matt