summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdftext.cpp18
-rw-r--r--fpdfsdk/fpdftext_embeddertest.cpp6
-rw-r--r--fpdfsdk/fpdfview_c_api_test.c1
-rw-r--r--public/fpdf_text.h21
4 files changed, 46 insertions, 0 deletions
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index 70acf54ec7..2ea06de5d8 100644
--- a/fpdfsdk/fpdftext.cpp
+++ b/fpdfsdk/fpdftext.cpp
@@ -123,6 +123,24 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page,
*top = charinfo.m_CharBox.top;
}
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFText_GetCharOrigin(FPDF_TEXTPAGE text_page,
+ int index,
+ double* x,
+ double* y) {
+ if (!text_page)
+ return false;
+ CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page);
+
+ if (index < 0 || index >= textpage->CountChars())
+ return false;
+ FPDF_CHAR_INFO charinfo;
+ textpage->GetCharInfo(index, &charinfo);
+ *x = charinfo.m_Origin.x;
+ *y = charinfo.m_Origin.y;
+ return true;
+}
+
// select
FPDF_EXPORT int FPDF_CALLCONV
FPDFText_GetCharIndexAtPos(FPDF_TEXTPAGE text_page,
diff --git a/fpdfsdk/fpdftext_embeddertest.cpp b/fpdfsdk/fpdftext_embeddertest.cpp
index 65f5734122..572368af15 100644
--- a/fpdfsdk/fpdftext_embeddertest.cpp
+++ b/fpdfsdk/fpdftext_embeddertest.cpp
@@ -71,6 +71,12 @@ TEST_F(FPDFTextEmbeddertest, Text) {
EXPECT_NEAR(49.844, bottom, 0.001);
EXPECT_NEAR(55.520, top, 0.001);
+ double x = 0.0;
+ double y = 0.0;
+ EXPECT_TRUE(FPDFText_GetCharOrigin(textpage, 4, &x, &y));
+ EXPECT_NEAR(40.664, x, 0.001);
+ EXPECT_NEAR(50.000, y, 0.001);
+
EXPECT_EQ(4, FPDFText_GetCharIndexAtPos(textpage, 42.0, 50.0, 1.0, 1.0));
EXPECT_EQ(-1, FPDFText_GetCharIndexAtPos(textpage, 0.0, 0.0, 1.0, 1.0));
EXPECT_EQ(-1, FPDFText_GetCharIndexAtPos(textpage, 199.0, 199.0, 1.0, 1.0));
diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c
index 8276eb64b7..88b7465744 100644
--- a/fpdfsdk/fpdfview_c_api_test.c
+++ b/fpdfsdk/fpdfview_c_api_test.c
@@ -254,6 +254,7 @@ int CheckPDFiumCApi() {
CHK(FPDFText_GetUnicode);
CHK(FPDFText_GetFontSize);
CHK(FPDFText_GetCharBox);
+ CHK(FPDFText_GetCharOrigin);
CHK(FPDFText_GetCharIndexAtPos);
CHK(FPDFText_GetText);
CHK(FPDFText_CountRects);
diff --git a/public/fpdf_text.h b/public/fpdf_text.h
index c069144026..4a76a7fcd0 100644
--- a/public/fpdf_text.h
+++ b/public/fpdf_text.h
@@ -113,6 +113,27 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page,
double* bottom,
double* top);
+// Function: FPDFText_GetCharOrigin
+// Get origin of a particular character.
+// Parameters:
+// text_page - Handle to a text page information structure.
+// Returned by FPDFText_LoadPage function.
+// index - Zero-based index of the character.
+// x - Pointer to a double number receiving x coordinate of
+// the character origin.
+// y - Pointer to a double number receiving y coordinate of
+// the character origin.
+// Return Value:
+// Whether the call succeeded. If false, x and y are unchanged.
+// Comments:
+// All positions are measured in PDF "user space".
+//
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFText_GetCharOrigin(FPDF_TEXTPAGE text_page,
+ int index,
+ double* x,
+ double* y);
+
// Function: FPDFText_GetCharIndexAtPos
// Get the index of a character at or nearby a certain position on the
// page.