summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfedit_embeddertest.cpp
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-09-20 22:52:43 +0200
committerChromium commit bot <commit-bot@chromium.org>2017-09-20 21:04:08 +0000
commit36eed87d19e741be9909500c45dd12e50ff6a1ab (patch)
tree7311bbf0ba29245308ca79b34acb22086d6cbdd0 /fpdfsdk/fpdfedit_embeddertest.cpp
parent0c2e705f8d8dec68c1afc8344872fe8bee527c48 (diff)
downloadpdfium-36eed87d19e741be9909500c45dd12e50ff6a1ab.tar.xz
Add FPDFPath_GetPoint() APIchromium/3221
Combined with the previously added FPDFPath_CountPoint(), this allows getting the coordinates of all points of a path. Change-Id: Ic969723d4b01ee427498d38ce323c74147b87a9c Reviewed-on: https://pdfium-review.googlesource.com/14111 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfedit_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index ca2a457147..6826317ef2 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -259,6 +259,39 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) {
// Make sure the path has 5 points (1 FXPT_TYPE::MoveTo and 4
// FXPT_TYPE::LineTo).
ASSERT_EQ(5, FPDFPath_CountPoint(green_rect));
+ // Verify actual coordinates.
+ FPDF_PATHSEGMENT segment = FPDFPath_GetPathSegment(green_rect, 0);
+ float x;
+ float y;
+ EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y));
+ EXPECT_EQ(100, x);
+ EXPECT_EQ(100, y);
+ EXPECT_EQ(FPDF_SEGMENT_MOVETO, FPDFPathSegment_GetType(segment));
+ EXPECT_FALSE(FPDFPathSegment_GetClose(segment));
+ segment = FPDFPath_GetPathSegment(green_rect, 1);
+ EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y));
+ EXPECT_EQ(100, x);
+ EXPECT_EQ(140, y);
+ EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment));
+ EXPECT_FALSE(FPDFPathSegment_GetClose(segment));
+ segment = FPDFPath_GetPathSegment(green_rect, 2);
+ EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y));
+ EXPECT_EQ(140, x);
+ EXPECT_EQ(140, y);
+ EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment));
+ EXPECT_FALSE(FPDFPathSegment_GetClose(segment));
+ segment = FPDFPath_GetPathSegment(green_rect, 3);
+ EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y));
+ EXPECT_EQ(140, x);
+ EXPECT_EQ(100, y);
+ EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment));
+ EXPECT_FALSE(FPDFPathSegment_GetClose(segment));
+ segment = FPDFPath_GetPathSegment(green_rect, 4);
+ EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y));
+ EXPECT_EQ(100, x);
+ EXPECT_EQ(100, y);
+ EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment));
+ EXPECT_TRUE(FPDFPathSegment_GetClose(segment));
EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_WINDING, 0));
FPDFPage_InsertObject(page, green_rect);
@@ -277,6 +310,27 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) {
// Make sure the path has 3 points (1 FXPT_TYPE::MoveTo and 2
// FXPT_TYPE::LineTo).
ASSERT_EQ(3, FPDFPath_CountPoint(black_path));
+ // Verify actual coordinates.
+ segment = FPDFPath_GetPathSegment(black_path, 0);
+ EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y));
+ EXPECT_EQ(400, x);
+ EXPECT_EQ(100, y);
+ EXPECT_EQ(FPDF_SEGMENT_MOVETO, FPDFPathSegment_GetType(segment));
+ EXPECT_FALSE(FPDFPathSegment_GetClose(segment));
+ segment = FPDFPath_GetPathSegment(black_path, 1);
+ EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y));
+ EXPECT_EQ(400, x);
+ EXPECT_EQ(200, y);
+ EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment));
+ EXPECT_FALSE(FPDFPathSegment_GetClose(segment));
+ segment = FPDFPath_GetPathSegment(black_path, 2);
+ EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y));
+ EXPECT_EQ(300, x);
+ EXPECT_EQ(100, y);
+ EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment));
+ EXPECT_TRUE(FPDFPathSegment_GetClose(segment));
+ // Make sure out of bounds index access fails properly.
+ EXPECT_EQ(nullptr, FPDFPath_GetPathSegment(black_path, 3));
FPDFPage_InsertObject(page, black_path);
page_bitmap = RenderPage(page);
@@ -317,6 +371,21 @@ TEST_F(FPDFEditEmbeddertest, PathsPoints) {
// This should fail gracefully, even if path is NULL.
ASSERT_EQ(-1, FPDFPath_CountPoint(nullptr));
+ // FPDFPath_GetPathSegment() with a non-path.
+ ASSERT_EQ(nullptr, FPDFPath_GetPathSegment(img, 0));
+ // FPDFPath_GetPathSegment() with a NULL path.
+ ASSERT_EQ(nullptr, FPDFPath_GetPathSegment(nullptr, 0));
+ float x;
+ float y;
+ // FPDFPathSegment_GetPoint() with a NULL segment.
+ EXPECT_FALSE(FPDFPathSegment_GetPoint(nullptr, &x, &y));
+
+ // FPDFPathSegment_GetType() with a NULL segment.
+ ASSERT_EQ(FPDF_SEGMENT_UNKNOWN, FPDFPathSegment_GetType(nullptr));
+
+ // FPDFPathSegment_GetClose() with a NULL segment.
+ EXPECT_FALSE(FPDFPathSegment_GetClose(nullptr));
+
FPDFPageObj_Destroy(img);
}