summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-07-11 21:19:22 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-11 21:19:22 +0000
commitb4bcf69210719810ca563b9f8c0179719e80d212 (patch)
tree1a809ee9a2c7b20db29e33918b6eecfa0aae8a2b /fpdfsdk
parent10a7ddb596f0089ba12d0db29b5752a61919a208 (diff)
downloadpdfium-b4bcf69210719810ca563b9f8c0179719e80d212.tar.xz
Write marked content operators when generating a stream.
The marked content operators are BMC, BDC and EMC. In the case of BDC, it is preceded by a direct dict or a property name. Bug: pdfium:1118 Change-Id: I3ee736ff7be3e7d7dde55ef581af3444a325e887 Reviewed-on: https://pdfium-review.googlesource.com/37470 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp85
1 files changed, 83 insertions, 2 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index e169c46b6d..52cc9fed86 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -694,6 +694,68 @@ TEST_F(FPDFEditEmbeddertest, RemoveMarkedObjectsPrime) {
UnloadPage(page);
}
+TEST_F(FPDFEditEmbeddertest, MaintainMarkedObjects) {
+ // Load document with some text.
+ EXPECT_TRUE(OpenDocument("text_in_page_marked.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // Iterate over all objects, counting the number of times each content mark
+ // name appears.
+ CheckMarkCounts(page, 1, 19, 8, 4, 9, 1);
+
+ // Remove first page object.
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ FPDFPageObj_Destroy(page_object);
+
+ CheckMarkCounts(page, 2, 18, 8, 3, 9, 1);
+
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+
+ UnloadPage(page);
+
+ OpenSavedDocument();
+ FPDF_PAGE saved_page = LoadSavedPage(0);
+
+ CheckMarkCounts(saved_page, 2, 18, 8, 3, 9, 1);
+
+ CloseSavedPage(saved_page);
+ CloseSavedDocument();
+}
+
+TEST_F(FPDFEditEmbeddertest, MaintainIndirectMarkedObjects) {
+ // Load document with some text.
+ EXPECT_TRUE(OpenDocument("text_in_page_marked_indirect.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // Iterate over all objects, counting the number of times each content mark
+ // name appears.
+ CheckMarkCounts(page, 1, 19, 8, 4, 9, 1);
+
+ // Remove first page object.
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, 0);
+ EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ FPDFPageObj_Destroy(page_object);
+
+ CheckMarkCounts(page, 2, 18, 8, 3, 9, 1);
+
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+
+ UnloadPage(page);
+
+ OpenSavedDocument();
+ FPDF_PAGE saved_page = LoadSavedPage(0);
+
+ CheckMarkCounts(saved_page, 2, 18, 8, 3, 9, 1);
+
+ CloseSavedPage(saved_page);
+ CloseSavedDocument();
+}
+
TEST_F(FPDFEditEmbeddertest, RemoveExistingPageObject) {
// Load document with some text.
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
@@ -2160,10 +2222,29 @@ TEST_F(FPDFEditEmbeddertest, AddMarkedText) {
CompareBitmap(page_bitmap.get(), 612, 792, md5);
}
+ // Now save the result.
+ EXPECT_EQ(1, FPDFPage_CountObjects(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+
FPDF_ClosePage(page);
- // TODO(pdfium:1118): Save, then re-open the file and check the changes were
- // kept in the saved .pdf.
+ // Re-open the file and check the changes were kept in the saved .pdf.
+ OpenSavedDocument();
+ FPDF_PAGE saved_page = LoadSavedPage(0);
+ EXPECT_EQ(1, FPDFPage_CountObjects(saved_page));
+
+ text_object = FPDFPage_GetObject(saved_page, 0);
+ EXPECT_TRUE(text_object);
+ EXPECT_EQ(1, FPDFPageObj_CountMarks(text_object));
+ mark = FPDFPageObj_GetMark(text_object, 0);
+ EXPECT_TRUE(mark);
+ EXPECT_GT(FPDFPageObjMark_GetName(mark, buffer, 256), 0u);
+ name = GetPlatformWString(reinterpret_cast<unsigned short*>(buffer));
+ EXPECT_EQ(L"TestMarkName", name);
+
+ CloseSavedPage(saved_page);
+ CloseSavedDocument();
}
TEST_F(FPDFEditEmbeddertest, ExtractImageBitmap) {