gpt4 book ai didi

iphone - 'annot' CGPDFDictionary 'Rect' 如何转换为 objective-c Rect

转载 作者:行者123 更新时间:2023-12-01 18:03:18 25 4
gpt4 key购买 nike

'annot' CGPDFDictionary 'Rect' 如何转换为 objective-c Rect:

最佳答案

Adobes PDF Spec状态:

Rectangles are used to describe locations on a page and bounding boxes for a variety of objects. A rectangle shall be written as an array of four numbers giving the coordinates of a pair of diagonally opposite corners.

Although rectangles are conventionally specified by their lower-left and upper-right corners, it is acceptable to specify any two diagonally opposite corners. Applications that process PDF should be prepared to normalize such rectangles in situations where specific corners are required. Typically, the array takes the form [llx lly urx ury] specifying the lower-left x, lower-left y, upper-right x, and upper-right y coordinates of the rectangle, in that order. The other two corners of the rectangle are then assumed to have coordinates (llx, ury) and (urx, lly).



因此,这意味着 rect 翻译不是本地的,如图所示 here应该是这样的:
CGRect rect = CGRectMake(coords[0],coords[3],coords[2]-coords[0],coords[3]-coords[1]);

查看代码 Bellow(由 BrainFeeder 提供的原始代码)以查看 coords 数组的上下文:
CGPDFArrayRef rectArray;
if(CGPDFDictionaryGetArray(annotDict, "Rect", &rectArray)) {
//continue;

CGPDFReal coords[4];

for( int k = 0; k < arrayCount; ++k ) {

CGPDFObjectRef rectObj;
if(!CGPDFArrayGetObject(rectArray, k, &rectObj)) {
continue;
}

CGPDFReal coord;
if(!CGPDFObjectGetValue(rectObj, kCGPDFObjectTypeReal, &coord)) {
continue;
}

coords[k] = coord;
}

}

//blx,bly,trx,try>tlx,tly,w,h

CGRect rect = CGRectMake(coords[0],coords[3],coords[2]-coords[0],coords[3]-coords[1]);

关于iphone - 'annot' CGPDFDictionary 'Rect' 如何转换为 objective-c Rect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4255298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com