summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfdoc.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-03-22 18:39:05 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-22 18:39:05 +0000
commitaaed698534284ca45a986ae7344246cffbc6faa9 (patch)
tree196ef8371b5b63ef8cccd3869424e25690f823d6 /fpdfsdk/fpdfdoc.cpp
parentf9f0e511c4a8a4b7f29624012ddcc00fb7cc8ba9 (diff)
downloadpdfium-aaed698534284ca45a986ae7344246cffbc6faa9.tar.xz
Consolidate QuadPoints reading code in fpdfsdk.chromium/3380chromium/3379
Also fix nits in QuadPoints code in cpdf_annot.cpp. Change-Id: I7852b673d3dca906e6d250cb3cfa305f8ea7e742 Reviewed-on: https://pdfium-review.googlesource.com/28893 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfdoc.cpp')
-rw-r--r--fpdfsdk/fpdfdoc.cpp60
1 files changed, 32 insertions, 28 deletions
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,