summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdftext/cpdf_textpage.cpp14
-rw-r--r--core/fpdftext/cpdf_textpage.h6
-rw-r--r--fpdfsdk/fpdftext.cpp18
-rw-r--r--fpdfsdk/fpdftext_embeddertest.cpp6
-rw-r--r--public/fpdf_text.h24
5 files changed, 32 insertions, 36 deletions
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 98eacf3c14..b448a59b33 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -471,18 +471,12 @@ int CPDF_TextPage::CountRects(int start, int nCount) {
return pdfium::CollectionSize<int>(m_SelRects);
}
-void CPDF_TextPage::GetRect(int rectIndex,
- float& left,
- float& top,
- float& right,
- float& bottom) const {
+bool CPDF_TextPage::GetRect(int rectIndex, CFX_FloatRect* pRect) const {
if (!m_bIsParsed || !pdfium::IndexInBounds(m_SelRects, rectIndex))
- return;
+ return false;
- left = m_SelRects[rectIndex].left;
- top = m_SelRects[rectIndex].top;
- right = m_SelRects[rectIndex].right;
- bottom = m_SelRects[rectIndex].bottom;
+ *pRect = m_SelRects[rectIndex];
+ return true;
}
CPDF_TextPage::TextOrientation CPDF_TextPage::FindTextlineFlowOrientation()
diff --git a/core/fpdftext/cpdf_textpage.h b/core/fpdftext/cpdf_textpage.h
index cd30ace3ad..51d066071e 100644
--- a/core/fpdftext/cpdf_textpage.h
+++ b/core/fpdftext/cpdf_textpage.h
@@ -111,11 +111,7 @@ class CPDF_TextPage {
WideString GetAllPageText() const { return GetPageText(0, CountChars()); }
int CountRects(int start, int nCount);
- void GetRect(int rectIndex,
- float& left,
- float& top,
- float& right,
- float& bottom) const;
+ bool GetRect(int rectIndex, CFX_FloatRect* pRect) const;
static bool IsRectIntersect(const CFX_FloatRect& rect1,
const CFX_FloatRect& rect2);
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index 85dc6e475e..bc86c1c099 100644
--- a/fpdfsdk/fpdftext.cpp
+++ b/fpdfsdk/fpdftext.cpp
@@ -205,22 +205,24 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_CountRects(FPDF_TEXTPAGE text_page,
return textpage->CountRects(start, count);
}
-FPDF_EXPORT void FPDF_CALLCONV FPDFText_GetRect(FPDF_TEXTPAGE text_page,
- int rect_index,
- double* left,
- double* top,
- double* right,
- double* bottom) {
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetRect(FPDF_TEXTPAGE text_page,
+ int rect_index,
+ double* left,
+ double* top,
+ double* right,
+ double* bottom) {
if (!text_page)
- return;
+ return false;
CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page);
CFX_FloatRect rect;
- textpage->GetRect(rect_index, rect.left, rect.top, rect.right, rect.bottom);
+ bool result = textpage->GetRect(rect_index, &rect);
+
*left = rect.left;
*top = rect.top;
*right = rect.right;
*bottom = rect.bottom;
+ return result;
}
FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page,
diff --git a/fpdfsdk/fpdftext_embeddertest.cpp b/fpdfsdk/fpdftext_embeddertest.cpp
index 6885eb0f75..a9637be5df 100644
--- a/fpdfsdk/fpdftext_embeddertest.cpp
+++ b/fpdfsdk/fpdftext_embeddertest.cpp
@@ -115,7 +115,7 @@ TEST_F(FPDFTextEmbeddertest, Text) {
right = 0.0;
bottom = 0.0;
top = 0.0;
- FPDFText_GetRect(textpage, 1, &left, &top, &right, &bottom);
+ EXPECT_TRUE(FPDFText_GetRect(textpage, 1, &left, &top, &right, &bottom));
EXPECT_NEAR(20.847, left, 0.001);
EXPECT_NEAR(135.167, right, 0.001);
EXPECT_NEAR(96.655, bottom, 0.001);
@@ -126,7 +126,7 @@ TEST_F(FPDFTextEmbeddertest, Text) {
right = -1.0;
bottom = -1.0;
top = -1.0;
- FPDFText_GetRect(textpage, -1, &left, &top, &right, &bottom);
+ EXPECT_FALSE(FPDFText_GetRect(textpage, -1, &left, &top, &right, &bottom));
EXPECT_EQ(0.0, left);
EXPECT_EQ(0.0, right);
EXPECT_EQ(0.0, bottom);
@@ -136,7 +136,7 @@ TEST_F(FPDFTextEmbeddertest, Text) {
right = -2.0;
bottom = -2.0;
top = -2.0;
- FPDFText_GetRect(textpage, 2, &left, &top, &right, &bottom);
+ EXPECT_FALSE(FPDFText_GetRect(textpage, 2, &left, &top, &right, &bottom));
EXPECT_EQ(0.0, left);
EXPECT_EQ(0.0, right);
EXPECT_EQ(0.0, bottom);
diff --git a/public/fpdf_text.h b/public/fpdf_text.h
index bad66ad085..90ccaf76ae 100644
--- a/public/fpdf_text.h
+++ b/public/fpdf_text.h
@@ -219,14 +219,18 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_CountRects(FPDF_TEXTPAGE text_page,
// bottom - Pointer to a double value receiving the rectangle
// bottom boundary.
// Return Value:
-// None.
+// On success, return TRUE and fill in |left|, |top|, |right|, and
+// |bottom|. If |link_page| is invalid then return FALSE, and the out
+// parameters remain unmodified. If |link_page| is valid but
+// |link_index| is out of bounds, then return FALSE and set the out
+// parameters to 0.
//
-FPDF_EXPORT void FPDF_CALLCONV FPDFText_GetRect(FPDF_TEXTPAGE text_page,
- int rect_index,
- double* left,
- double* top,
- double* right,
- double* bottom);
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetRect(FPDF_TEXTPAGE text_page,
+ int rect_index,
+ double* left,
+ double* top,
+ double* right,
+ double* bottom);
// Function: FPDFText_GetBoundedText
// Extract unicode text within a rectangular boundary on the page.
@@ -423,9 +427,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountRects(FPDF_PAGELINK link_page,
// bottom boundary.
// Return Value:
// 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.
+// |bottom|. If |link_page| is invalid or if |link_index| does not
+// correspond to a valid link, then return FALSE, and the out
+// parameters remain unmodified.
//
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetRect(FPDF_PAGELINK link_page,
int link_index,