summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-09-15 07:49:03 +0200
committerChromium commit bot <commit-bot@chromium.org>2017-09-15 06:03:35 +0000
commit12abfd04a42a1166f7d1496beb63515bc47ec360 (patch)
tree573057f4cf24780bdf17d2ac113e48eec0897780 /fpdfsdk
parent69fe7110e6af83ca82d71275a70ae4983daddd6f (diff)
downloadpdfium-12abfd04a42a1166f7d1496beb63515bc47ec360.tar.xz
Add public method FPDFPath_CountPoint to get # of points of a path object.
It was already possible to get the fill color, this exposes the number of points. Naming attempts to be consistent with existing FPDFPage_CountObject(). Change-Id: I79e8dd9f0c077de84ce9017a01d239e48e58174a Reviewed-on: https://pdfium-review.googlesource.com/13592 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp21
-rw-r--r--fpdfsdk/fpdfeditpath.cpp7
-rw-r--r--fpdfsdk/fpdfview_c_api_test.c1
3 files changed, 29 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);