diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdfannot.cpp | 21 | ||||
-rw-r--r-- | fpdfsdk/fpdfdoc.cpp | 60 | ||||
-rw-r--r-- | fpdfsdk/fsdk_define.h | 6 |
3 files changed, 41 insertions, 46 deletions
diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp index d2a15ce8c0..b5dccaade1 100644 --- a/fpdfsdk/fpdfannot.cpp +++ b/fpdfsdk/fpdfannot.cpp @@ -627,24 +627,9 @@ FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot, if (!annot || !quad_points || !FPDFAnnot_HasAttachmentPoints(annot)) return false; - CPDF_Dictionary* pAnnotDict = - CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); - if (!pAnnotDict) - return false; - - CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints"); - if (!pArray) - return false; - - quad_points->x1 = pArray->GetNumberAt(0); - quad_points->y1 = pArray->GetNumberAt(1); - quad_points->x2 = pArray->GetNumberAt(2); - quad_points->y2 = pArray->GetNumberAt(3); - quad_points->x3 = pArray->GetNumberAt(4); - quad_points->y3 = pArray->GetNumberAt(5); - quad_points->x4 = pArray->GetNumberAt(6); - quad_points->y4 = pArray->GetNumberAt(7); - return true; + return GetQuadPointsFromDictionary( + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(), 0, + quad_points); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetRect(FPDF_ANNOTATION annot, diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp index befdc4d7a3..774dc28e8c 100644 --- a/fpdfsdk/fpdfdoc.cpp +++ b/fpdfsdk/fpdfdoc.cpp @@ -78,6 +78,31 @@ CPDF_Dictionary* CPDFDictionaryFromFPDFLink(FPDF_LINK link) { return ToDictionary(static_cast<CPDF_Object*>(link)); } +const CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict) { + return dict ? dict->GetArrayFor("QuadPoints") : nullptr; +} + +bool GetQuadPointsFromDictionary(CPDF_Dictionary* dict, + size_t quad_index, + FS_QUADPOINTSF* quad_points) { + ASSERT(quad_points); + + const CPDF_Array* pArray = GetQuadPointsArrayFromDictionary(dict); + if (!pArray || quad_index >= pArray->GetCount() / 8) + return false; + + quad_index *= 8; + quad_points->x1 = pArray->GetNumberAt(quad_index); + quad_points->y1 = pArray->GetNumberAt(quad_index + 1); + quad_points->x2 = pArray->GetNumberAt(quad_index + 2); + quad_points->y2 = pArray->GetNumberAt(quad_index + 3); + quad_points->x3 = pArray->GetNumberAt(quad_index + 4); + quad_points->y3 = pArray->GetNumberAt(quad_index + 5); + quad_points->x4 = pArray->GetNumberAt(quad_index + 6); + quad_points->y4 = pArray->GetNumberAt(quad_index + 7); + return true; +} + FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); @@ -379,41 +404,20 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK link_annot, } FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountQuadPoints(FPDF_LINK link_annot) { - if (!link_annot) - return 0; - CPDF_Dictionary* pAnnotDict = CPDFDictionaryFromFPDFLink(link_annot); - CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints"); - if (!pArray) - return 0; - return static_cast<int>(pArray->GetCount() / 8); + const CPDF_Array* pArray = + GetQuadPointsArrayFromDictionary(CPDFDictionaryFromFPDFLink(link_annot)); + return pArray ? static_cast<int>(pArray->GetCount() / 8) : 0; } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetQuadPoints(FPDF_LINK link_annot, int quad_index, FS_QUADPOINTSF* quad_points) { - if (!link_annot || !quad_points) + if (!quad_points || quad_index < 0) return false; - CPDF_Dictionary* pAnnotDict = CPDFDictionaryFromFPDFLink(link_annot); - CPDF_Array* pArray = pAnnotDict->GetArrayFor("QuadPoints"); - if (!pArray) - return false; - - if (quad_index < 0 || - static_cast<size_t>(quad_index) >= pArray->GetCount() / 8 || - (static_cast<size_t>(quad_index * 8 + 7) >= pArray->GetCount())) { - return false; - } - - quad_points->x1 = pArray->GetNumberAt(quad_index * 8); - quad_points->y1 = pArray->GetNumberAt(quad_index * 8 + 1); - quad_points->x2 = pArray->GetNumberAt(quad_index * 8 + 2); - quad_points->y2 = pArray->GetNumberAt(quad_index * 8 + 3); - quad_points->x3 = pArray->GetNumberAt(quad_index * 8 + 4); - quad_points->y3 = pArray->GetNumberAt(quad_index * 8 + 5); - quad_points->x4 = pArray->GetNumberAt(quad_index * 8 + 6); - quad_points->y4 = pArray->GetNumberAt(quad_index * 8 + 7); - return true; + return GetQuadPointsFromDictionary(CPDFDictionaryFromFPDFLink(link_annot), + static_cast<size_t>(quad_index), + quad_points); } FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetMetaText(FPDF_DOCUMENT document, diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h index d503ba5e1d..acd8437169 100644 --- a/fpdfsdk/fsdk_define.h +++ b/fpdfsdk/fsdk_define.h @@ -10,6 +10,7 @@ #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/fx_dib.h" +#include "public/fpdf_doc.h" #include "public/fpdfview.h" #ifdef PDF_ENABLE_XFA @@ -83,6 +84,11 @@ CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark); CPDF_Dictionary* CPDFDictionaryFromFPDFLink(FPDF_LINK link); +const CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict); +bool GetQuadPointsFromDictionary(CPDF_Dictionary* dict, + size_t quad_index, + FS_QUADPOINTSF* quad_points); + CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect); void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect); |