【发布时间】:2017-05-10 09:26:12
【问题描述】:
目标是在 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);
}
}
}
layer的大小是(612.000000, 792.000000),但是s.frame的大小是(3.110400, 1.107000)。如何从填充为黄色的矩形中获取真实框架?
【问题讨论】:
-
frame的整个概念是没有意义的,除非转换是身份。文档对此非常清楚。 -
那么就没有办法了吗?对吗?
-
我不知道“这样做”是什么意思。我不知道你认为你想做什么;你甚至没有解释
s是什么!但是您的问题是关于frame,而frame是一个纯粹构造的概念,在转换下没有意义。
标签: ios pdf quartz-graphics cgcontext quartz-2d