summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_annot_embeddertest.cpp
diff options
context:
space:
mode:
authorRalf Sippl <ralf.sippl@gmail.com>2018-04-12 21:20:26 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 21:20:26 +0000
commit1638179e85863b5045fcea2282fd3e0622aeac13 (patch)
treee21cc4c409ed04ccb4496f17c4edcc0d8f586cdc /fpdfsdk/fpdf_annot_embeddertest.cpp
parentc9f4f0dbcaaf9e86ef2b64c844b094bd2f6b1a92 (diff)
downloadpdfium-1638179e85863b5045fcea2282fd3e0622aeac13.tar.xz
Add index parameter to quadpoints getter and setter.
This is needed for working with multiline text markup annotations. Based on https://pdfium-review.googlesource.com/12012. Bug: pdfium:1045 Change-Id: Ifb105996b8b950bb2d5fceaf754b4f571155aef4 Reviewed-on: https://pdfium-review.googlesource.com/29150 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_annot_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdf_annot_embeddertest.cpp99
1 files changed, 92 insertions, 7 deletions
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index b97193db46..9d5c5548b6 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -134,7 +134,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) {
// Check that the quadpoints are correct.
FS_QUADPOINTSF quadpoints;
- ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
+ ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
EXPECT_EQ(115.802643f, quadpoints.x1);
EXPECT_EQ(718.913940f, quadpoints.y1);
EXPECT_EQ(157.211182f, quadpoints.x4);
@@ -303,7 +303,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
std::unique_ptr<void, FPDFAnnotationDeleter> annot(
FPDFPage_GetAnnot(page, 0));
ASSERT_TRUE(annot);
- ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
+ ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
EXPECT_EQ(115.802643f, quadpoints.x1);
EXPECT_EQ(718.913940f, quadpoints.y1);
EXPECT_EQ(157.211182f, quadpoints.x4);
@@ -317,7 +317,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
ASSERT_TRUE(annot);
quadpoints.x1 = 140.802643f;
quadpoints.x3 = 140.802643f;
- ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), &quadpoints));
+ ASSERT_TRUE(FPDFAnnot_AppendAttachmentPoints(annot.get(), &quadpoints));
}
// Save the document, closing the page and document.
@@ -343,7 +343,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot.get()));
FS_QUADPOINTSF new_quadpoints;
ASSERT_TRUE(
- FPDFAnnot_GetAttachmentPoints(new_annot.get(), &new_quadpoints));
+ FPDFAnnot_GetAttachmentPoints(new_annot.get(), 0, &new_quadpoints));
EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f);
EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f);
EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f);
@@ -354,6 +354,91 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
CloseSavedDocument();
}
+TEST_F(FPDFAnnotEmbeddertest, GetAndSetQuadPoints) {
+ // Open a file with four annotations and load its first page.
+ ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+ EXPECT_EQ(4, FPDFPage_GetAnnotCount(page));
+
+ // Retrieve the highlight annotation.
+ FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
+ ASSERT_TRUE(annot);
+ ASSERT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
+
+ FS_QUADPOINTSF quadpoints;
+ ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 0, &quadpoints));
+
+ {
+ // Verify the current one set of quadpoints.
+ ASSERT_EQ(1u, FPDFAnnot_CountAttachmentPoints(annot));
+
+ EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
+ EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
+ EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
+ EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
+ }
+
+ {
+ // Update the quadpoints.
+ FS_QUADPOINTSF new_quadpoints = quadpoints;
+ new_quadpoints.y1 -= 20.f;
+ new_quadpoints.y2 -= 20.f;
+ new_quadpoints.y3 -= 20.f;
+ new_quadpoints.y4 -= 20.f;
+ ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, 0, &new_quadpoints));
+
+ // Verify added quadpoint set
+ ASSERT_EQ(1u, FPDFAnnot_CountAttachmentPoints(annot));
+ ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 0, &quadpoints));
+ EXPECT_NEAR(new_quadpoints.x1, quadpoints.x1, 0.001f);
+ EXPECT_NEAR(new_quadpoints.y1, quadpoints.y1, 0.001f);
+ EXPECT_NEAR(new_quadpoints.x4, quadpoints.x4, 0.001f);
+ EXPECT_NEAR(new_quadpoints.y4, quadpoints.y4, 0.001f);
+ }
+
+ {
+ // Append a new set of quadpoints.
+ FS_QUADPOINTSF new_quadpoints = quadpoints;
+ new_quadpoints.y1 += 20.f;
+ new_quadpoints.y2 += 20.f;
+ new_quadpoints.y3 += 20.f;
+ new_quadpoints.y4 += 20.f;
+ ASSERT_TRUE(FPDFAnnot_AppendAttachmentPoints(annot, &new_quadpoints));
+
+ // Verify added quadpoint set
+ ASSERT_EQ(2u, FPDFAnnot_CountAttachmentPoints(annot));
+ ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 1, &quadpoints));
+ EXPECT_NEAR(new_quadpoints.x1, quadpoints.x1, 0.001f);
+ EXPECT_NEAR(new_quadpoints.y1, quadpoints.y1, 0.001f);
+ EXPECT_NEAR(new_quadpoints.x4, quadpoints.x4, 0.001f);
+ EXPECT_NEAR(new_quadpoints.y4, quadpoints.y4, 0.001f);
+ }
+
+ {
+ // Setting and getting quadpoints at out-of-bound index should fail
+ EXPECT_FALSE(FPDFAnnot_SetAttachmentPoints(annot, 300000, &quadpoints));
+ EXPECT_FALSE(FPDFAnnot_GetAttachmentPoints(annot, 300000, &quadpoints));
+ }
+
+ FPDFPage_CloseAnnot(annot);
+
+ // Retrieve the square annotation
+ FPDF_ANNOTATION squareAnnot = FPDFPage_GetAnnot(page, 2);
+
+ {
+ // Check that attempting to set its quadpoints would fail
+ ASSERT_TRUE(squareAnnot);
+ EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(squareAnnot));
+ EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(squareAnnot));
+ EXPECT_FALSE(FPDFAnnot_SetAttachmentPoints(squareAnnot, 0, &quadpoints));
+ }
+
+ FPDFPage_CloseAnnot(squareAnnot);
+
+ UnloadPage(page);
+}
+
TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
const char md5_original[] = "63af8432fab95a67cdebb7cd0e514941";
@@ -398,7 +483,7 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
// Verify its attachment points.
FS_QUADPOINTSF quadpoints;
- ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
+ ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
@@ -409,9 +494,9 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
quadpoints.x2 -= 50.f;
quadpoints.x3 -= 50.f;
quadpoints.x4 -= 50.f;
- ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), &quadpoints));
+ ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), 0, &quadpoints));
FS_QUADPOINTSF new_quadpoints;
- ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &new_quadpoints));
+ ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &new_quadpoints));
EXPECT_EQ(quadpoints.x1, new_quadpoints.x1);
EXPECT_EQ(quadpoints.y1, new_quadpoints.y1);
EXPECT_EQ(quadpoints.x4, new_quadpoints.x4);