如何'annot'CGPDFDictionary'Rect'转换为目标c Rect [英] How does an 'annot' CGPDFDictionary 'Rect' translate to objective c Rect

查看:115
本文介绍了如何'annot'CGPDFDictionary'Rect'转换为目标c Rect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将'annot'CGPDFDictionary'Rect'转换为目标c Rect:

How does an 'annot' CGPDFDictionary 'Rect' translate to objective c Rect:

推荐答案

Adob​​es 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.

矩形通常是由它们的左下角和
指定的
,可接受
来指定任何两个对角相对的
角。处理PDF
的应用程序应准备在需要
特定角点的情况下规范化这种
矩形。
通常,数组采用
格式[llx lly urx ury],指定
左下角x,左下角y,
右上角x和右上角y
矩形的坐标,在
的顺序。
矩形的另外两个角被假定为具有
坐标(llx,ury)和(urx,lly)。

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翻译不是原生的,如图所示这里,应该是这样:

So, this means that that the rect translation is not native as shown here and should be like this:

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

查看代码Bellow(原始代码由 BrainFeeder )查看coords数组的上下文:

See the code Bellow (original code by BrainFeeder) to see the context of the coords array:

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]);

这篇关于如何'annot'CGPDFDictionary'Rect'转换为目标c Rect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆