summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-03-27 16:26:44 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-27 16:26:44 +0000
commitc90adc58b97200d20b0532bde95b79dcba00637f (patch)
tree002895239afa554f84a0fb76e6cb85265fef19b3 /fpdfsdk
parentc526e38a47a7fc7d83cc87aaf521d14bb7b7304d (diff)
downloadpdfium-c90adc58b97200d20b0532bde95b79dcba00637f.tar.xz
Open FPDF_PAGEOBJECTMARK API.
Initially it contains: - FPDFPageObj_CountMarks - FPDFPageObj_GetMark - FPDFPageObjMark_GetName This allows reading the content marks from a page object. Bug: pdfium:1037 Change-Id: I3d7554b71f938778890fdb44088e0d45dd2718d9 Reviewed-on: https://pdfium-review.googlesource.com/28710 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp91
-rw-r--r--fpdfsdk/fpdfeditpage.cpp41
-rw-r--r--fpdfsdk/fpdfview.cpp6
-rw-r--r--fpdfsdk/fpdfview_c_api_test.c3
-rw-r--r--fpdfsdk/fsdk_define.h4
5 files changed, 141 insertions, 4 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index ec403c74b3..65e790cc32 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -387,7 +387,8 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
-// Show how the original file looks like.
+ // Show what the original file looks like.
+ {
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
const char kOriginalMD5[] = "b90475ca64d1348c3bf5e2b77ad9187a";
#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
@@ -395,7 +396,6 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
#else
const char kOriginalMD5[] = "2baa4c0e1758deba1b9c908e1fbd04ed";
#endif
- {
std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap =
RenderPageWithFlags(page, nullptr, 0);
CompareBitmap(page_bitmap.get(), 200, 200, kOriginalMD5);
@@ -407,7 +407,8 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
ASSERT_TRUE(page_object);
EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
-// Verify the "Hello, world!" text is gone.
+ // Verify the "Hello, world!" text is gone.
+ {
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
const char kRemovedMD5[] = "af760c4702467cb1492a57fb8215efaa";
#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
@@ -415,7 +416,6 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
#else
const char kRemovedMD5[] = "b76df015fe88009c3c342395df96abf1";
#endif
- {
std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap =
RenderPageWithFlags(page, nullptr, 0);
CompareBitmap(page_bitmap.get(), 200, 200, kRemovedMD5);
@@ -426,6 +426,89 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
FPDFPageObj_Destroy(page_object);
}
+TEST_F(FPDFEditEmbeddertest, RemoveMarkedObjectsPrime) {
+ // Load document with some text.
+ EXPECT_TRUE(OpenDocument("text_in_page_marked.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // Show what the original file looks like.
+ {
+#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
+ const char kOriginalMD5[] = "5a5eb63cb21cc15084fea1f14284b8df";
+#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
+ const char kOriginalMD5[] = "587c507a40f613f9c530b2ce2d58d655";
+#else
+ const char kOriginalMD5[] = "2edc6e70d54889aa0c0b7bdf3e168f86";
+#endif
+ std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap =
+ RenderPageWithFlags(page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 200, kOriginalMD5);
+ }
+
+ // Iterate over all objects, counting the number of times each content mark
+ // name appears.
+ int object_count = FPDFPage_CountObjects(page);
+ ASSERT_EQ(19, object_count);
+
+ unsigned long prime_count = 0;
+ unsigned long square_count = 0;
+ unsigned long greater_than_ten_count = 0;
+ std::vector<FPDF_PAGEOBJECT> primes;
+ for (int i = 0; i < object_count; ++i) {
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+
+ int mark_count = FPDFPageObj_CountMarks(page_object);
+ for (int j = 0; j < mark_count; ++j) {
+ FPDF_PAGEOBJECTMARK mark = FPDFPageObj_GetMark(page_object, j);
+
+ char buffer[256];
+ ASSERT_GT(FPDFPageObjMark_GetName(mark, buffer, 256), 0u);
+ std::wstring name =
+ GetPlatformWString(reinterpret_cast<unsigned short*>(buffer));
+ if (name == L"Prime") {
+ prime_count++;
+ primes.push_back(page_object);
+ } else if (name == L"Square") {
+ square_count++;
+ } else if (name == L"GreaterThanTen") {
+ greater_than_ten_count++;
+ } else {
+ FAIL();
+ }
+ }
+ }
+
+ // Expect certain number of tagged objects. The test file contains strings
+ // from 1 to 19.
+ EXPECT_EQ(8u, prime_count);
+ EXPECT_EQ(4u, square_count);
+ EXPECT_EQ(9u, greater_than_ten_count);
+
+ // Remove all objects marked with "Prime".
+ for (FPDF_PAGEOBJECT page_object : primes) {
+ EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ FPDFPageObj_Destroy(page_object);
+ }
+
+ EXPECT_EQ(11, FPDFPage_CountObjects(page));
+
+ {
+#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
+ const char kNonPrimesMD5[] = "57e76dc7375d896704f0fd6d6d1b9e65";
+#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
+ const char kNonPrimesMD5[] = "4d906b57fba36c70c600cf50d60f508c";
+#else
+ const char kNonPrimesMD5[] = "33d9c45bec41ead92a295e252f6b7922";
+#endif
+ std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap =
+ RenderPageWithFlags(page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 200, kNonPrimesMD5);
+ }
+
+ UnloadPage(page);
+}
+
TEST_F(FPDFEditEmbeddertest, AddAndRemovePaths) {
// Start with a blank page.
FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index 902aab4dd1..d0724d5359 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -222,6 +222,47 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPageObj_Destroy(FPDF_PAGEOBJECT page_obj) {
delete CPDFPageObjectFromFPDFPageObject(page_obj);
}
+FPDF_EXPORT int FPDF_CALLCONV
+FPDFPageObj_CountMarks(FPDF_PAGEOBJECT page_object) {
+ if (!page_object)
+ return -1;
+
+ const auto& mark =
+ CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMark;
+ return mark.HasRef() ? mark.CountItems() : 0;
+}
+
+FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV
+FPDFPageObj_GetMark(FPDF_PAGEOBJECT page_object, unsigned long index) {
+ if (!page_object)
+ return nullptr;
+
+ const auto& mark =
+ CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMark;
+ if (!mark.HasRef())
+ return nullptr;
+
+ if (index >= mark.CountItems())
+ return nullptr;
+
+ return static_cast<FPDF_PAGEOBJECTMARK>(&mark.GetItem(index));
+}
+
+FPDF_EXPORT unsigned long FPDF_CALLCONV
+FPDFPageObjMark_GetName(FPDF_PAGEOBJECTMARK mark,
+ void* buffer,
+ unsigned long buflen) {
+ if (!mark)
+ return 0;
+
+ const CPDF_ContentMarkItem* pMarkItem =
+ CPDFContentMarkItemFromFPDFPageObjectMark(mark);
+
+ return Utf16EncodeMaybeCopyAndReturnLength(
+ WideString::FromUTF8(pMarkItem->GetName().AsStringView()), buffer,
+ buflen);
+}
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
if (!pageObject)
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index e890aa0090..a9078102e3 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -12,6 +12,7 @@
#include "core/fpdfapi/cpdf_modulemgr.h"
#include "core/fpdfapi/cpdf_pagerendercontext.h"
+#include "core/fpdfapi/page/cpdf_contentmarkitem.h"
#include "core/fpdfapi/page/cpdf_image.h"
#include "core/fpdfapi/page/cpdf_imageobject.h"
#include "core/fpdfapi/page/cpdf_page.h"
@@ -345,6 +346,11 @@ CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
return static_cast<CPDF_PageObject*>(page_object);
}
+const CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark(
+ FPDF_PAGEOBJECTMARK mark) {
+ return static_cast<const CPDF_ContentMarkItem*>(mark);
+}
+
CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment) {
return static_cast<CPDF_Object*>(attachment);
}
diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c
index 201fd90669..a0bcc13ff3 100644
--- a/fpdfsdk/fpdfview_c_api_test.c
+++ b/fpdfsdk/fpdfview_c_api_test.c
@@ -144,6 +144,9 @@ int CheckPDFiumCApi() {
CHK(FPDFPageObj_Transform);
CHK(FPDFPage_TransformAnnots);
CHK(FPDFPageObj_NewImageObj);
+ CHK(FPDFPageObj_CountMarks);
+ CHK(FPDFPageObj_GetMark);
+ CHK(FPDFPageObjMark_GetName);
CHK(FPDFImageObj_LoadJpegFile);
CHK(FPDFImageObj_LoadJpegFileInline);
CHK(FPDFImageObj_SetMatrix);
diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h
index acd8437169..94497bb237 100644
--- a/fpdfsdk/fsdk_define.h
+++ b/fpdfsdk/fsdk_define.h
@@ -23,6 +23,7 @@
#endif
class CPDF_Annot;
+class CPDF_ContentMarkItem;
class CPDF_Page;
class CPDF_PageObject;
class CPDF_PageRenderContext;
@@ -70,6 +71,9 @@ CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
+const CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark(
+ FPDF_PAGEOBJECTMARK mark);
+
CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment);
ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string);