summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp21
-rw-r--r--fpdfsdk/fpdfeditpath.cpp7
-rw-r--r--fpdfsdk/fpdfview_c_api_test.c1
-rw-r--r--public/fpdf_edit.h10
4 files changed, 39 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index 71933fea43..faf6d97adf 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -256,6 +256,10 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) {
EXPECT_EQ(0U, B);
EXPECT_EQ(128U, A);
+ // Make sure the path has 5 points (1 FXPT_TYPE::MoveTo and 4
+ // FXPT_TYPE::LineTo).
+ ASSERT_EQ(5, FPDFPath_CountPoint(green_rect));
+
EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_WINDING, 0));
FPDFPage_InsertObject(page, green_rect);
page_bitmap = RenderPage(page);
@@ -269,6 +273,11 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) {
EXPECT_TRUE(FPDFPath_LineTo(black_path, 400, 200));
EXPECT_TRUE(FPDFPath_LineTo(black_path, 300, 100));
EXPECT_TRUE(FPDFPath_Close(black_path));
+
+ // Make sure the path has 3 points (1 FXPT_TYPE::MoveTo and 2
+ // FXPT_TYPE::LineTo).
+ ASSERT_EQ(3, FPDFPath_CountPoint(black_path));
+
FPDFPage_InsertObject(page, black_path);
page_bitmap = RenderPage(page);
CompareBitmap(page_bitmap, 612, 792, "eadc8020a14dfcf091da2688733d8806");
@@ -299,6 +308,18 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) {
TestAndCloseSaved(612, 792, last_md5);
}
+TEST_F(FPDFEditEmbeddertest, PathsPoints) {
+ CreateNewDocument();
+ FPDF_PAGEOBJECT img = FPDFPageObj_NewImageObj(document_);
+ // This should fail gracefully, even if img is not a path.
+ ASSERT_EQ(-1, FPDFPath_CountPoint(img));
+
+ // This should fail gracefully, even if path is NULL.
+ ASSERT_EQ(-1, FPDFPath_CountPoint(nullptr));
+
+ FPDFPageObj_Destroy(img);
+}
+
TEST_F(FPDFEditEmbeddertest, PathOnTopOfText) {
// Load document with some text
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
index 2b33dee934..164ab7015f 100644
--- a/fpdfsdk/fpdfeditpath.cpp
+++ b/fpdfsdk/fpdfeditpath.cpp
@@ -118,6 +118,13 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetFillColor(FPDF_PAGEOBJECT path,
return true;
}
+FPDF_EXPORT int FPDF_CALLCONV FPDFPath_CountPoint(FPDF_PAGEOBJECT path) {
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj)
+ return -1;
+ return pdfium::CollectionSize<int>(pPathObj->m_Path.GetPoints());
+}
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path,
float x,
float y) {
diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c
index 6f84f353aa..415543dbe2 100644
--- a/fpdfsdk/fpdfview_c_api_test.c
+++ b/fpdfsdk/fpdfview_c_api_test.c
@@ -148,6 +148,7 @@ int CheckPDFiumCApi() {
CHK(FPDFPath_SetStrokeWidth);
CHK(FPDFPath_SetFillColor);
CHK(FPDFPath_GetFillColor);
+ CHK(FPDFPath_CountPoint);
CHK(FPDFPath_MoveTo);
CHK(FPDFPath_LineTo);
CHK(FPDFPath_BezierTo);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index 22582674ea..9ee11cb5ec 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -552,6 +552,16 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetFillColor(FPDF_PAGEOBJECT path,
unsigned int* B,
unsigned int* A);
+// Get number of point objects inside |path|.
+//
+// path - handle to a path.
+//
+// A point object is a command, created by e.g. FPDFPath_MoveTo() or
+// FPDFPath_LineTo().
+//
+// Returns the number of objects in |path| or -1 on failure.
+FPDF_EXPORT int FPDF_CALLCONV FPDFPath_CountPoint(FPDF_PAGEOBJECT path);
+
// Move a path's current point.
//
// path - the handle to the path object.