From 6eb7939300d1bc7c31afd5086c1b93d4a7628481 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Tue, 12 Jun 2018 20:27:35 +0000 Subject: Fill m_ContentStream field in CPDF_PageObject. From the comment of CPDF_PageObject::GetContentStream(): """ Get what content stream the object was parsed from in its page. This number is the index of the content stream in the "Contents" array, or 0 if there is a single content stream. If the object is newly created, -1 is returned. If the object is spread among more than one content stream, this is the index of the last one. """ Bug: pdfium:1051 Change-Id: I9f7804af4f263dda0422e9542e025e3320ff7c31 Reviewed-on: https://pdfium-review.googlesource.com/34250 Commit-Queue: Henrique Nakashima Reviewed-by: dsinclair --- fpdfsdk/fpdf_edit_embeddertest.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index dc61c0d974..3d2e090a36 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -9,6 +9,7 @@ #include "core/fpdfapi/font/cpdf_font.h" #include "core/fpdfapi/page/cpdf_page.h" +#include "core/fpdfapi/page/cpdf_pageobject.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_number.h" @@ -655,6 +656,34 @@ TEST_F(FPDFEditEmbeddertest, DISABLED_RemoveExistingPageObject) { CloseSavedDocument(); } +// TODO(pdfium:1051): Extend this test to remove some elements and verify +// saving works. +TEST_F(FPDFEditEmbeddertest, GetContentStream) { + // Load document with some text split across streams. + EXPECT_TRUE(OpenDocument("split_streams.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Content stream 0: page objects 0-14. + // Content stream 1: page objects 15-17. + // Content stream 2: page object 18. + ASSERT_EQ(19, FPDFPage_CountObjects(page)); + for (int i = 0; i < 19; i++) { + FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i); + ASSERT_TRUE(page_object); + CPDF_PageObject* cpdf_page_object = + CPDFPageObjectFromFPDFPageObject(page_object); + if (i < 15) + EXPECT_EQ(0, cpdf_page_object->GetContentStream()) << i; + else if (i < 18) + EXPECT_EQ(1, cpdf_page_object->GetContentStream()) << i; + else + EXPECT_EQ(2, cpdf_page_object->GetContentStream()) << i; + } + + UnloadPage(page); +} + TEST_F(FPDFEditEmbeddertest, InsertPageObjectAndSave) { // Load document with some text. EXPECT_TRUE(OpenDocument("hello_world.pdf")); -- cgit v1.2.3