From 50bd8fa8a9505487c1109e2645ef785ad73b1cbc Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 10 Jan 2018 17:33:06 +0000 Subject: Change FPDFLink_GetRect() to return a boolean. BUG=pdfium:858 Change-Id: Ib8effb64a1622feb2837f536b36b9e46847a2210 Reviewed-on: https://pdfium-review.googlesource.com/22631 Reviewed-by: dsinclair Commit-Queue: Lei Zhang --- fpdfsdk/fpdftext.cpp | 19 ++++++++++--------- fpdfsdk/fpdftext_embeddertest.cpp | 6 +++--- public/fpdf_text.h | 20 +++++++++++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp index 9392981df1..85dc6e475e 100644 --- a/fpdfsdk/fpdftext.cpp +++ b/fpdfsdk/fpdftext.cpp @@ -362,25 +362,26 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountRects(FPDF_PAGELINK link_page, return pdfium::CollectionSize(pageLink->GetRects(link_index)); } -FPDF_EXPORT void FPDF_CALLCONV FPDFLink_GetRect(FPDF_PAGELINK link_page, - int link_index, - int rect_index, - double* left, - double* top, - double* right, - double* bottom) { +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetRect(FPDF_PAGELINK link_page, + int link_index, + int rect_index, + double* left, + double* top, + double* right, + double* bottom) { if (!link_page || link_index < 0 || rect_index < 0) - return; + return false; CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); std::vector rectArray = pageLink->GetRects(link_index); if (rect_index >= pdfium::CollectionSize(rectArray)) - return; + return false; *left = rectArray[rect_index].left; *right = rectArray[rect_index].right; *top = rectArray[rect_index].top; *bottom = rectArray[rect_index].bottom; + return true; } FPDF_EXPORT void FPDF_CALLCONV FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) { diff --git a/fpdfsdk/fpdftext_embeddertest.cpp b/fpdfsdk/fpdftext_embeddertest.cpp index 60654057b9..6885eb0f75 100644 --- a/fpdfsdk/fpdftext_embeddertest.cpp +++ b/fpdfsdk/fpdftext_embeddertest.cpp @@ -365,7 +365,7 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) { double right = 0.0; double top = 0.0; double bottom = 0.0; - FPDFLink_GetRect(pagelink, 0, 0, &left, &top, &right, &bottom); + EXPECT_TRUE(FPDFLink_GetRect(pagelink, 0, 0, &left, &top, &right, &bottom)); EXPECT_NEAR(50.791, left, 0.001); EXPECT_NEAR(187.963, right, 0.001); EXPECT_NEAR(97.624, bottom, 0.001); @@ -376,7 +376,7 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) { right = -1.0; top = -1.0; bottom = -1.0; - FPDFLink_GetRect(pagelink, 0, 1, &left, &top, &right, &bottom); + EXPECT_FALSE(FPDFLink_GetRect(pagelink, 0, 1, &left, &top, &right, &bottom)); EXPECT_EQ(-1.0, left); EXPECT_EQ(-1.0, right); EXPECT_EQ(-1.0, bottom); @@ -387,7 +387,7 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) { right = -2.0; top = -2.0; bottom = -2.0; - FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom); + EXPECT_FALSE(FPDFLink_GetRect(pagelink, -1, 0, &left, &top, &right, &bottom)); EXPECT_EQ(-2.0, left); EXPECT_EQ(-2.0, right); EXPECT_EQ(-2.0, bottom); diff --git a/public/fpdf_text.h b/public/fpdf_text.h index 4a76a7fcd0..bad66ad085 100644 --- a/public/fpdf_text.h +++ b/public/fpdf_text.h @@ -422,16 +422,18 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountRects(FPDF_PAGELINK link_page, // bottom - Pointer to a double value receiving the rectangle // bottom boundary. // Return Value: -// None. If |link_index| does not correspond to a valid link, then -// |left|, |top|, |right|, and |bottom| remain unmodified. +// On success, return TRUE and fill in |left|, |top|, |right|, and +// |bottom|. If |link_index| does not correspond to a valid link, then +// return FALSE, and |left|, |top|, |right|, and |bottom| remain +// unmodified. // -FPDF_EXPORT void FPDF_CALLCONV FPDFLink_GetRect(FPDF_PAGELINK link_page, - int link_index, - int rect_index, - double* left, - double* top, - double* right, - double* bottom); +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetRect(FPDF_PAGELINK link_page, + int link_index, + int rect_index, + double* left, + double* top, + double* right, + double* bottom); // Function: FPDFLink_CloseWebLinks // Release resources used by weblink feature. -- cgit v1.2.3