summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfannot_embeddertest.cpp
diff options
context:
space:
mode:
authorJane Liu <janeliulwq@google.com>2017-06-01 18:56:09 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-06-01 23:17:03 +0000
commit4fd9a47465c0f2f17aa2a840d8452b2bee6bec33 (patch)
tree4dbd633596216ceddf817e693376a3626e28f112 /fpdfsdk/fpdfannot_embeddertest.cpp
parent8cb884102c17ef0530277126fd8da054d329d065 (diff)
downloadpdfium-4fd9a47465c0f2f17aa2a840d8452b2bee6bec33.tar.xz
Basic APIs and tests for extracting annotations
1. Added API for extracting annotation properties: * Added testing flag "--annot" that outputs the annotation properties into a .txt file. * Added two embedder tests covering all the API functions. Bug=pdfium:737 Change-Id: I95943a9b2b3d5d431bc8a74a31b27b4f4b521026 Reviewed-on: https://pdfium-review.googlesource.com/6092 Commit-Queue: Jane Liu <janeliulwq@google.com> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfannot_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfannot_embeddertest.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp
new file mode 100644
index 0000000000..27a76eecfa
--- /dev/null
+++ b/fpdfsdk/fpdfannot_embeddertest.cpp
@@ -0,0 +1,132 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "public/fpdf_annot.h"
+#include "public/fpdfview.h"
+#include "testing/embedder_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class FPDFAnnotEmbeddertest : public EmbedderTest {};
+
+TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) {
+ // Open a file with one annotation and load its first page.
+ ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
+ FPDF_PAGE page = FPDF_LoadPage(document(), 0);
+ ASSERT_TRUE(page);
+
+ // Check that there is a total of 1 annotation on its first page.
+ EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+
+ // Check that the annotation is of type "highlight".
+ FPDF_ANNOTATION annot;
+ ASSERT_TRUE(FPDFPage_GetAnnot(page, 0, &annot));
+ EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
+
+ // Check that the annotation color is yellow.
+ unsigned int R;
+ unsigned int G;
+ unsigned int B;
+ unsigned int A;
+ EXPECT_TRUE(
+ FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A));
+ EXPECT_EQ(255u, R);
+ EXPECT_EQ(255u, G);
+ EXPECT_EQ(0u, B);
+ EXPECT_EQ(255u, A);
+
+ // Check that the author is correct.
+ unsigned long len =
+ FPDFAnnot_GetText(annot, FPDFANNOT_TEXTTYPE_Author, nullptr, 0);
+ std::vector<char> buf(len);
+ EXPECT_EQ(28u, FPDFAnnot_GetText(annot, FPDFANNOT_TEXTTYPE_Author, buf.data(),
+ len));
+ EXPECT_STREQ(L"Jae Hyun Park",
+ GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
+ .c_str());
+
+ // Check that the content is correct.
+ len = FPDFAnnot_GetText(annot, FPDFANNOT_TEXTTYPE_Contents, nullptr, 0);
+ buf.clear();
+ buf.resize(len);
+ EXPECT_EQ(2690u, FPDFAnnot_GetText(annot, FPDFANNOT_TEXTTYPE_Contents,
+ buf.data(), len));
+ const wchar_t contents[] =
+ L"This is a note for that highlight annotation. Very long highlight "
+ "annotation. Long long long Long long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long longLong long longLong long longLong long longLong long "
+ "longLong long long. END";
+ EXPECT_STREQ(contents,
+ GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
+ .c_str());
+
+ // Check that the quadpoints are correct.
+ FS_QUADPOINTSF quadpoints;
+ ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints));
+ EXPECT_EQ(115.802643f, quadpoints.x1);
+ EXPECT_EQ(718.913940f, quadpoints.y1);
+ EXPECT_EQ(157.211182f, quadpoints.x4);
+ EXPECT_EQ(706.264465f, quadpoints.y4);
+
+ UnloadPage(page);
+}
+
+TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) {
+ // Open a file with three annotations and load its first page.
+ ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
+ FPDF_PAGE page = FPDF_LoadPage(document(), 0);
+ ASSERT_TRUE(page);
+
+ // Check that there is a total of 3 annotation on its first page.
+ EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
+
+ // Check that the third annotation of type "ink".
+ FPDF_ANNOTATION annot;
+ ASSERT_TRUE(FPDFPage_GetAnnot(page, 2, &annot));
+ EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot));
+
+ // Check that the annotation color is blue with opacity.
+ unsigned int R;
+ unsigned int G;
+ unsigned int B;
+ unsigned int A;
+ EXPECT_TRUE(
+ FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A));
+ EXPECT_EQ(0u, R);
+ EXPECT_EQ(0u, G);
+ EXPECT_EQ(255u, B);
+ EXPECT_EQ(76u, A);
+
+ // Check that there is no content.
+ EXPECT_EQ(2u,
+ FPDFAnnot_GetText(annot, FPDFANNOT_TEXTTYPE_Contents, nullptr, 0));
+
+ // Check that the rectange coordinates are correct.
+ // Note that upon rendering, the rectangle coordinates will be adjusted.
+ FS_RECTF rect;
+ ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
+ EXPECT_EQ(351.820404f, rect.left);
+ EXPECT_EQ(583.830688f, rect.bottom);
+ EXPECT_EQ(475.336090f, rect.right);
+ EXPECT_EQ(681.535034f, rect.top);
+
+ UnloadPage(page);
+}