From 603a31d0c509c7ce3c2709dcb5377a78e6ce4815 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Wed, 14 Jun 2017 11:41:18 -0400 Subject: Add blend to GraphicsData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CL [1] added the ability to set the blend mode for a page object. This CL adds the corresponding component to GraphicsData since the blend mode is part of ExtGSState. In addition, a test using the SetBlendMode method is added. [1] https://pdfium-review.googlesource.com/c/5953/ Bug: pdfium:720 Change-Id: I49120284345185c200a45cc3b37ec59f0658e2dc Reviewed-on: https://pdfium-review.googlesource.com/6510 Commit-Queue: Nicolás Peña Reviewed-by: dsinclair --- fpdfsdk/fpdfedit_embeddertest.cpp | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index 40081e6d75..1146a8c546 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -556,6 +556,61 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { FPDF_ClosePage(page); } +TEST_F(FPDFEditEmbeddertest, GraphicsData) { + // New page + std::unique_ptr page( + FPDFPage_New(CreateNewDocument(), 0, 612, 792)); + + // Create a rect with nontrivial graphics + FPDF_PAGEOBJECT rect1 = FPDFPageObj_CreateNewRect(10, 10, 100, 100); + FPDFPageObj_SetBlendMode(rect1, "Color"); + FPDFPage_InsertObject(page.get(), rect1); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + + // Check that the ExtGState was created + CPDF_Page* the_page = CPDFPageFromFPDFPage(page.get()); + CPDF_Dictionary* graphics_dict = + the_page->m_pResources->GetDictFor("ExtGState"); + ASSERT_TRUE(graphics_dict); + EXPECT_EQ(1, static_cast(graphics_dict->GetCount())); + + // Add a text object causing no change to the graphics dictionary + FPDF_PAGEOBJECT text1 = FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); + // Only alpha, the last component, matters for the graphics dictionary. And + // the default value is 255. + EXPECT_TRUE(FPDFText_SetFillColor(text1, 100, 100, 100, 255)); + FPDFPage_InsertObject(page.get(), text1); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + EXPECT_EQ(1, static_cast(graphics_dict->GetCount())); + + // Add a text object increasing the size of the graphics dictionary + FPDF_PAGEOBJECT text2 = + FPDFPageObj_NewTextObj(document(), "Times-Roman", 12.0f); + FPDFPage_InsertObject(page.get(), text2); + FPDFPageObj_SetBlendMode(text2, "Darken"); + EXPECT_TRUE(FPDFText_SetFillColor(text2, 0, 0, 255, 150)); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + EXPECT_EQ(2, static_cast(graphics_dict->GetCount())); + + // Add a path that should reuse graphics + // TODO(npm): This causes a crash on Windows. + /*FPDF_PAGEOBJECT path = FPDFPageObj_CreateNewPath(400, 100); + FPDFPageObj_SetBlendMode(path, "Darken"); + EXPECT_TRUE(FPDFPath_SetFillColor(path, 200, 200, 100, 150)); + FPDFPage_InsertObject(page.get(), path); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + EXPECT_EQ(2, static_cast(graphics_dict->GetCount()));*/ + + // Add a rect increasing the size of the graphics dictionary + FPDF_PAGEOBJECT rect2 = FPDFPageObj_CreateNewRect(10, 10, 100, 100); + FPDFPageObj_SetBlendMode(rect2, "Darken"); + EXPECT_TRUE(FPDFPath_SetFillColor(rect2, 0, 0, 255, 150)); + EXPECT_TRUE(FPDFPath_SetStrokeColor(rect2, 0, 0, 0, 200)); + FPDFPage_InsertObject(page.get(), rect2); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + EXPECT_EQ(3, static_cast(graphics_dict->GetCount())); +} + TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { // Start with a blank page FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); -- cgit v1.2.3