From 06bbdef296b483e6f666156b198319019d3c6373 Mon Sep 17 00:00:00 2001 From: wileyrya Date: Fri, 26 May 2017 15:20:23 -0500 Subject: Add public API for setting the blend mode on a page object. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=pdfium:720 R=npm@chromium.org Change-Id: I2a43b34da6946265ca06502b9ff19ad352fd18cb Reviewed-on: https://pdfium-review.googlesource.com/5953 Commit-Queue: Nicolás Peña Reviewed-by: Nicolás Peña --- core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 19 +++++++++++-- core/fpdfapi/page/cpdf_generalstate.cpp | 37 +++++++++++++++++++++++++ core/fpdfapi/page/cpdf_generalstate.h | 1 + fpdfsdk/fpdfeditpage.cpp | 9 ++++++ public/fpdf_edit.h | 11 ++++++++ 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index e9ea064810..2cf10bd7cb 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -225,8 +225,12 @@ void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, GraphicsData graphD; graphD.fillAlpha = pPageObj->m_GeneralState.GetFillAlpha(); graphD.strokeAlpha = pPageObj->m_GeneralState.GetStrokeAlpha(); - if (graphD.fillAlpha == 1.0f && graphD.strokeAlpha == 1.0f) + int blend_type = pPageObj->m_GeneralState.GetBlendType(); + if (graphD.fillAlpha == 1.0f && graphD.strokeAlpha == 1.0f && + (blend_type == FXDIB_BLEND_UNSUPPORTED || + blend_type == FXDIB_BLEND_NORMAL)) { return; + } CFX_ByteString name; auto it = m_pPage->m_GraphicsMap.find(graphD); @@ -234,8 +238,17 @@ void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, name = it->second; } else { auto gsDict = pdfium::MakeUnique(); - gsDict->SetNewFor("ca", graphD.fillAlpha); - gsDict->SetNewFor("CA", graphD.strokeAlpha); + if (graphD.fillAlpha != 1.0f) + gsDict->SetNewFor("ca", graphD.fillAlpha); + + if (graphD.strokeAlpha != 1.0f) + gsDict->SetNewFor("CA", graphD.strokeAlpha); + + if (blend_type != FXDIB_BLEND_UNSUPPORTED && + blend_type != FXDIB_BLEND_NORMAL) { + gsDict->SetNewFor("BM", + pPageObj->m_GeneralState.GetBlendMode()); + } CPDF_Object* pDict = m_pDocument->AddIndirectObject(std::move(gsDict)); uint32_t dwObjNum = pDict->GetObjNum(); name = RealizeResource(dwObjNum, "ExtGState"); diff --git a/core/fpdfapi/page/cpdf_generalstate.cpp b/core/fpdfapi/page/cpdf_generalstate.cpp index e07a3ca13d..540707447e 100644 --- a/core/fpdfapi/page/cpdf_generalstate.cpp +++ b/core/fpdfapi/page/cpdf_generalstate.cpp @@ -78,6 +78,43 @@ CPDF_GeneralState::~CPDF_GeneralState() {} void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); } +CFX_ByteString CPDF_GeneralState::GetBlendMode() const { + switch (GetBlendType()) { + case FXDIB_BLEND_NORMAL: + return CFX_ByteString("Normal"); + case FXDIB_BLEND_MULTIPLY: + return CFX_ByteString("Multiply"); + case FXDIB_BLEND_SCREEN: + return CFX_ByteString("Screen"); + case FXDIB_BLEND_OVERLAY: + return CFX_ByteString("Overlay"); + case FXDIB_BLEND_DARKEN: + return CFX_ByteString("Darken"); + case FXDIB_BLEND_LIGHTEN: + return CFX_ByteString("Lighten"); + case FXDIB_BLEND_COLORDODGE: + return CFX_ByteString("ColorDodge"); + case FXDIB_BLEND_COLORBURN: + return CFX_ByteString("ColorBurn"); + case FXDIB_BLEND_HARDLIGHT: + return CFX_ByteString("HardLight"); + case FXDIB_BLEND_SOFTLIGHT: + return CFX_ByteString("SoftLight"); + case FXDIB_BLEND_DIFFERENCE: + return CFX_ByteString("Difference"); + case FXDIB_BLEND_EXCLUSION: + return CFX_ByteString("Exclusion"); + case FXDIB_BLEND_HUE: + return CFX_ByteString("Hue"); + case FXDIB_BLEND_SATURATION: + return CFX_ByteString("Saturation"); + case FXDIB_BLEND_COLOR: + return CFX_ByteString("Color"); + case FXDIB_BLEND_LUMINOSITY: + return CFX_ByteString("Luminosity"); + } + return CFX_ByteString("Normal"); +} int CPDF_GeneralState::GetBlendType() const { const StateData* pData = m_Ref.GetObject(); diff --git a/core/fpdfapi/page/cpdf_generalstate.h b/core/fpdfapi/page/cpdf_generalstate.h index 4ec08ca9c5..356841690b 100644 --- a/core/fpdfapi/page/cpdf_generalstate.h +++ b/core/fpdfapi/page/cpdf_generalstate.h @@ -27,6 +27,7 @@ class CPDF_GeneralState { void SetRenderIntent(const CFX_ByteString& ri); + CFX_ByteString GetBlendMode() const; int GetBlendType() const; void SetBlendType(int type); diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 37469ed23a..a474414435 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -264,6 +264,15 @@ DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, pPageObj->Transform(matrix); } +DLLEXPORT void STDCALL FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page_object, + FPDF_BYTESTRING blend_mode) { + CPDF_PageObject* pPageObj = static_cast(page_object); + if (!pPageObj) + return; + + pPageObj->m_GeneralState.SetBlendMode(blend_mode); +} + DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, double a, double b, diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h index 677bdb28d3..2014e6faf4 100644 --- a/public/fpdf_edit.h +++ b/public/fpdf_edit.h @@ -311,6 +311,17 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject, float* right, float* top); +// Set the blend mode of |pageObject|. +// +// pageObject - handle to a page object. +// blend_mode - string containing the blend mode. +// +// Blend mode can be one of following: Color, ColorBurn, ColorDodge, Darken, +// Difference, Exclusion, HardLight, Hue, Lighten, Luminosity, Multiply, Normal, +// Overlay, Saturation, Screen, SoftLight +DLLEXPORT void STDCALL FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page, + FPDF_BYTESTRING blend_mode); + // Set the stroke RGBA of a path. Range of values: 0 - 255. // // path - the handle to the path object. -- cgit v1.2.3