diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2018-07-13 19:47:22 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-13 19:47:22 +0000 |
commit | fed4adb003db228ac7fbc0510a21c25b50ae0cab (patch) | |
tree | f9a73333d86d5abb1cf890e320f0800a2dd875c9 /fpdfsdk/fpdf_edit_embeddertest.cpp | |
parent | a34067721d6630975c356a621a12753bbdab1cdb (diff) | |
download | pdfium-fed4adb003db228ac7fbc0510a21c25b50ae0cab.tar.xz |
Create API to remove a content mark from a page object.
- FPDFPageObj_RemoveMark()
Bug: pdfium:1037
Change-Id: I7ff320261d64e3ead45375ccc72301e7c64dd6e3
Reviewed-on: https://pdfium-review.googlesource.com/37710
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_edit_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdf_edit_embeddertest.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index ba790de654..9a03a4d5c8 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -692,6 +692,55 @@ TEST_F(FPDFEditEmbeddertest, RemoveMarkedObjectsPrime) { UnloadPage(page); } +TEST_F(FPDFEditEmbeddertest, RemoveMarks) { + // Load document with some text. + EXPECT_TRUE(OpenDocument("text_in_page_marked.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + constexpr int kExpectedObjectCount = 19; + CheckMarkCounts(page, 1, kExpectedObjectCount, 8, 4, 9, 1); + + // Remove all "Prime" content marks. + for (int i = 0; i < kExpectedObjectCount; ++i) { + FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i); + + int mark_count = FPDFPageObj_CountMarks(page_object); + for (int j = mark_count - 1; j >= 0; --j) { + FPDF_PAGEOBJECTMARK mark = FPDFPageObj_GetMark(page_object, j); + + char buffer[256]; + ASSERT_GT(FPDFPageObjMark_GetName(mark, buffer, sizeof(buffer)), 0u); + std::wstring name = + GetPlatformWString(reinterpret_cast<unsigned short*>(buffer)); + if (name == L"Prime") { + // Remove mark. + EXPECT_TRUE(FPDFPageObj_RemoveMark(page_object, mark)); + + // Verify there is now one fewer mark in the page object. + EXPECT_EQ(mark_count - 1, FPDFPageObj_CountMarks(page_object)); + } + } + } + + // Verify there are 0 "Prime" content marks now. + CheckMarkCounts(page, 1, kExpectedObjectCount, 0, 4, 9, 1); + + // Save the file. + EXPECT_TRUE(FPDFPage_GenerateContent(page)); + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + UnloadPage(page); + + // Re-open the file and check the prime marks are not there anymore. + OpenSavedDocument(); + FPDF_PAGE saved_page = LoadSavedPage(0); + + CheckMarkCounts(saved_page, 1, kExpectedObjectCount, 0, 4, 9, 1); + + CloseSavedPage(saved_page); + CloseSavedDocument(); +} + TEST_F(FPDFEditEmbeddertest, MaintainMarkedObjects) { // Load document with some text. EXPECT_TRUE(OpenDocument("text_in_page_marked.pdf")); |