summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdftext.cpp22
-rw-r--r--fpdfsdk/fpdftext_embeddertest.cpp18
-rw-r--r--public/fpdf_text.h16
3 files changed, 38 insertions, 18 deletions
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index bc86c1c099..68bf4f83d7 100644
--- a/fpdfsdk/fpdftext.cpp
+++ b/fpdfsdk/fpdftext.cpp
@@ -105,24 +105,26 @@ FPDF_EXPORT double FPDF_CALLCONV FPDFText_GetFontSize(FPDF_TEXTPAGE text_page,
return charinfo.m_FontSize;
}
-FPDF_EXPORT void FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page,
- int index,
- double* left,
- double* right,
- double* bottom,
- double* top) {
- if (!text_page)
- return;
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page,
+ int index,
+ double* left,
+ double* right,
+ double* bottom,
+ double* top) {
+ if (!text_page || index < 0)
+ return false;
+
CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page);
+ if (index >= textpage->CountChars())
+ return false;
- if (index < 0 || index >= textpage->CountChars())
- return;
FPDF_CHAR_INFO charinfo;
textpage->GetCharInfo(index, &charinfo);
*left = charinfo.m_CharBox.left;
*right = charinfo.m_CharBox.right;
*bottom = charinfo.m_CharBox.bottom;
*top = charinfo.m_CharBox.top;
+ return true;
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
diff --git a/fpdfsdk/fpdftext_embeddertest.cpp b/fpdfsdk/fpdftext_embeddertest.cpp
index a9637be5df..86d32a711a 100644
--- a/fpdfsdk/fpdftext_embeddertest.cpp
+++ b/fpdfsdk/fpdftext_embeddertest.cpp
@@ -87,7 +87,23 @@ TEST_F(FPDFTextEmbeddertest, Text) {
double right = 0.0;
double bottom = 0.0;
double top = 0.0;
- FPDFText_GetCharBox(textpage, 4, &left, &right, &bottom, &top);
+ EXPECT_FALSE(FPDFText_GetCharBox(nullptr, 4, &left, &right, &bottom, &top));
+ EXPECT_DOUBLE_EQ(0.0, left);
+ EXPECT_DOUBLE_EQ(0.0, right);
+ EXPECT_DOUBLE_EQ(0.0, bottom);
+ EXPECT_DOUBLE_EQ(0.0, top);
+ EXPECT_FALSE(FPDFText_GetCharBox(textpage, -1, &left, &right, &bottom, &top));
+ EXPECT_DOUBLE_EQ(0.0, left);
+ EXPECT_DOUBLE_EQ(0.0, right);
+ EXPECT_DOUBLE_EQ(0.0, bottom);
+ EXPECT_DOUBLE_EQ(0.0, top);
+ EXPECT_FALSE(FPDFText_GetCharBox(textpage, 55, &left, &right, &bottom, &top));
+ EXPECT_DOUBLE_EQ(0.0, left);
+ EXPECT_DOUBLE_EQ(0.0, right);
+ EXPECT_DOUBLE_EQ(0.0, bottom);
+ EXPECT_DOUBLE_EQ(0.0, top);
+
+ EXPECT_TRUE(FPDFText_GetCharBox(textpage, 4, &left, &right, &bottom, &top));
EXPECT_NEAR(41.071, left, 0.001);
EXPECT_NEAR(46.243, right, 0.001);
EXPECT_NEAR(49.844, bottom, 0.001);
diff --git a/public/fpdf_text.h b/public/fpdf_text.h
index 90ccaf76ae..043dc169c9 100644
--- a/public/fpdf_text.h
+++ b/public/fpdf_text.h
@@ -102,16 +102,18 @@ FPDF_EXPORT double FPDF_CALLCONV FPDFText_GetFontSize(FPDF_TEXTPAGE text_page,
// top - Pointer to a double number receiving top position of
// the character box.
// Return Value:
-// None.
+// On success, return TRUE and fill in |left|, |right|, |bottom|, and
+// |top|. If |text_page| is invalid, or if |index| is out of bounds,
+// then return FALSE, and the out parameters remain unmodified.
// Comments:
// All positions are measured in PDF "user space".
//
-FPDF_EXPORT void FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page,
- int index,
- double* left,
- double* right,
- double* bottom,
- double* top);
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page,
+ int index,
+ double* left,
+ double* right,
+ double* bottom,
+ double* top);
// Function: FPDFText_GetCharOrigin
// Get origin of a particular character.