summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render/fpdf_render.cpp
diff options
context:
space:
mode:
authornpm <npm@chromium.org>2016-11-17 13:50:44 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-17 13:50:44 -0800
commit483f3c485ac727cbf74c89e3912e5a4475d5f8f9 (patch)
tree546976bd96b8bad85bdad99a131a5ce425359ce9 /core/fpdfapi/render/fpdf_render.cpp
parentbcf4695095caa8ecc1b2df25992a7d06d58d80ac (diff)
downloadpdfium-483f3c485ac727cbf74c89e3912e5a4475d5f8f9.tar.xz
Move CPDF_RenderStatus from render_int
Moved CPDF_RenderStatus to its own class and removed unused methods. I only added some spaces and removed some {}s in cpdf_renderstatus.cpp. Will do cleanup of the file as a followup because it would be too hard to keep track of what's changed in this CL. Review-Url: https://codereview.chromium.org/2513693002
Diffstat (limited to 'core/fpdfapi/render/fpdf_render.cpp')
-rw-r--r--core/fpdfapi/render/fpdf_render.cpp770
1 files changed, 1 insertions, 769 deletions
diff --git a/core/fpdfapi/render/fpdf_render.cpp b/core/fpdfapi/render/fpdf_render.cpp
index ca9e059171..ba5d836e95 100644
--- a/core/fpdfapi/render/fpdf_render.cpp
+++ b/core/fpdfapi/render/fpdf_render.cpp
@@ -29,6 +29,7 @@
#include "core/fpdfapi/render/cpdf_pagerendercache.h"
#include "core/fpdfapi/render/cpdf_progressiverenderer.h"
#include "core/fpdfapi/render/cpdf_renderoptions.h"
+#include "core/fpdfapi/render/cpdf_renderstatus.h"
#include "core/fpdfapi/render/cpdf_textrenderer.h"
#include "core/fpdfapi/render/cpdf_type3cache.h"
#include "core/fpdfdoc/cpdf_occontext.h"
@@ -92,750 +93,6 @@ FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const {
return ArgbEncode(a, r, g, b);
}
-// static
-int CPDF_RenderStatus::s_CurrentRecursionDepth = 0;
-
-CPDF_RenderStatus::CPDF_RenderStatus()
- : m_pFormResource(nullptr),
- m_pPageResource(nullptr),
- m_pContext(nullptr),
- m_bStopped(false),
- m_pDevice(nullptr),
- m_pCurObj(nullptr),
- m_pStopObj(nullptr),
- m_HalftoneLimit(0),
- m_bPrint(false),
- m_Transparency(0),
- m_bDropObjects(false),
- m_bStdCS(false),
- m_GroupFamily(0),
- m_bLoadMask(false),
- m_pType3Char(nullptr),
- m_T3FillColor(0),
- m_curBlend(FXDIB_BLEND_NORMAL) {}
-
-CPDF_RenderStatus::~CPDF_RenderStatus() {}
-
-bool CPDF_RenderStatus::Initialize(CPDF_RenderContext* pContext,
- CFX_RenderDevice* pDevice,
- const CFX_Matrix* pDeviceMatrix,
- const CPDF_PageObject* pStopObj,
- const CPDF_RenderStatus* pParentState,
- const CPDF_GraphicStates* pInitialStates,
- const CPDF_RenderOptions* pOptions,
- int transparency,
- bool bDropObjects,
- CPDF_Dictionary* pFormResource,
- bool bStdCS,
- CPDF_Type3Char* pType3Char,
- FX_ARGB fill_color,
- uint32_t GroupFamily,
- bool bLoadMask) {
- m_pContext = pContext;
- m_pDevice = pDevice;
- m_bPrint = m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
- if (pDeviceMatrix) {
- m_DeviceMatrix = *pDeviceMatrix;
- }
- m_pStopObj = pStopObj;
- if (pOptions) {
- m_Options = *pOptions;
- }
- m_bDropObjects = bDropObjects;
- m_bStdCS = bStdCS;
- m_T3FillColor = fill_color;
- m_pType3Char = pType3Char;
- m_GroupFamily = GroupFamily;
- m_bLoadMask = bLoadMask;
- m_pFormResource = pFormResource;
- m_pPageResource = m_pContext->GetPageResources();
- if (pInitialStates && !m_pType3Char) {
- m_InitialStates.CopyStates(*pInitialStates);
- if (pParentState) {
- if (!m_InitialStates.m_ColorState.HasFillColor()) {
- m_InitialStates.m_ColorState.SetFillRGB(
- pParentState->m_InitialStates.m_ColorState.GetFillRGB());
- m_InitialStates.m_ColorState.GetMutableFillColor()->Copy(
- pParentState->m_InitialStates.m_ColorState.GetFillColor());
- }
- if (!m_InitialStates.m_ColorState.HasStrokeColor()) {
- m_InitialStates.m_ColorState.SetStrokeRGB(
- pParentState->m_InitialStates.m_ColorState.GetFillRGB());
- m_InitialStates.m_ColorState.GetMutableStrokeColor()->Copy(
- pParentState->m_InitialStates.m_ColorState.GetStrokeColor());
- }
- }
- } else {
- m_InitialStates.DefaultStates();
- }
- m_pImageRenderer.reset();
- m_Transparency = transparency;
- return true;
-}
-void CPDF_RenderStatus::RenderObjectList(
- const CPDF_PageObjectHolder* pObjectHolder,
- const CFX_Matrix* pObj2Device) {
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
- CFX_FloatRect clip_rect(m_pDevice->GetClipBox());
- CFX_Matrix device2object;
- device2object.SetReverse(*pObj2Device);
- device2object.TransformRect(clip_rect);
-
- for (const auto& pCurObj : *pObjectHolder->GetPageObjectList()) {
- if (pCurObj.get() == m_pStopObj) {
- m_bStopped = true;
- return;
- }
- if (!pCurObj)
- continue;
-
- if (pCurObj->m_Left > clip_rect.right ||
- pCurObj->m_Right < clip_rect.left ||
- pCurObj->m_Bottom > clip_rect.top ||
- pCurObj->m_Top < clip_rect.bottom) {
- continue;
- }
- RenderSingleObject(pCurObj.get(), pObj2Device);
- if (m_bStopped)
- return;
- }
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
-}
-
-void CPDF_RenderStatus::RenderSingleObject(CPDF_PageObject* pObj,
- const CFX_Matrix* pObj2Device) {
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
- CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth);
- if (++s_CurrentRecursionDepth > kRenderMaxRecursionDepth) {
- return;
- }
- m_pCurObj = pObj;
- if (m_Options.m_pOCContext && pObj->m_ContentMark) {
- if (!m_Options.m_pOCContext->CheckObjectVisible(pObj)) {
- return;
- }
- }
- ProcessClipPath(pObj->m_ClipPath, pObj2Device);
- if (ProcessTransparency(pObj, pObj2Device)) {
- return;
- }
- ProcessObjectNoClip(pObj, pObj2Device);
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
-}
-
-bool CPDF_RenderStatus::ContinueSingleObject(CPDF_PageObject* pObj,
- const CFX_Matrix* pObj2Device,
- IFX_Pause* pPause) {
- if (m_pImageRenderer) {
- if (m_pImageRenderer->Continue(pPause))
- return true;
-
- if (!m_pImageRenderer->m_Result)
- DrawObjWithBackground(pObj, pObj2Device);
- m_pImageRenderer.reset();
- return false;
- }
-
- m_pCurObj = pObj;
- if (m_Options.m_pOCContext && pObj->m_ContentMark &&
- !m_Options.m_pOCContext->CheckObjectVisible(pObj)) {
- return false;
- }
-
- ProcessClipPath(pObj->m_ClipPath, pObj2Device);
- if (ProcessTransparency(pObj, pObj2Device))
- return false;
-
- if (pObj->IsImage()) {
- m_pImageRenderer.reset(new CPDF_ImageRenderer);
- if (!m_pImageRenderer->Start(this, pObj, pObj2Device, false)) {
- if (!m_pImageRenderer->m_Result)
- DrawObjWithBackground(pObj, pObj2Device);
- m_pImageRenderer.reset();
- return false;
- }
- return ContinueSingleObject(pObj, pObj2Device, pPause);
- }
-
- ProcessObjectNoClip(pObj, pObj2Device);
- return false;
-}
-
-bool CPDF_RenderStatus::GetObjectClippedRect(const CPDF_PageObject* pObj,
- const CFX_Matrix* pObj2Device,
- bool bLogical,
- FX_RECT& rect) const {
- rect = pObj->GetBBox(pObj2Device);
- FX_RECT rtClip = m_pDevice->GetClipBox();
- if (!bLogical) {
- CFX_Matrix dCTM = m_pDevice->GetCTM();
- FX_FLOAT a = FXSYS_fabs(dCTM.a);
- FX_FLOAT d = FXSYS_fabs(dCTM.d);
- if (a != 1.0f || d != 1.0f) {
- rect.right = rect.left + (int32_t)FXSYS_ceil((FX_FLOAT)rect.Width() * a);
- rect.bottom = rect.top + (int32_t)FXSYS_ceil((FX_FLOAT)rect.Height() * d);
- rtClip.right =
- rtClip.left + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Width() * a);
- rtClip.bottom =
- rtClip.top + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Height() * d);
- }
- }
- rect.Intersect(rtClip);
- return rect.IsEmpty();
-}
-
-void CPDF_RenderStatus::ProcessObjectNoClip(CPDF_PageObject* pObj,
- const CFX_Matrix* pObj2Device) {
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
- bool bRet = false;
- switch (pObj->GetType()) {
- case CPDF_PageObject::TEXT:
- bRet = ProcessText(pObj->AsText(), pObj2Device, nullptr);
- break;
- case CPDF_PageObject::PATH:
- bRet = ProcessPath(pObj->AsPath(), pObj2Device);
- break;
- case CPDF_PageObject::IMAGE:
- bRet = ProcessImage(pObj->AsImage(), pObj2Device);
- break;
- case CPDF_PageObject::SHADING:
- ProcessShading(pObj->AsShading(), pObj2Device);
- return;
- case CPDF_PageObject::FORM:
- bRet = ProcessForm(pObj->AsForm(), pObj2Device);
- break;
- }
- if (!bRet)
- DrawObjWithBackground(pObj, pObj2Device);
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
-}
-
-bool CPDF_RenderStatus::DrawObjWithBlend(CPDF_PageObject* pObj,
- const CFX_Matrix* pObj2Device) {
- bool bRet = false;
- switch (pObj->GetType()) {
- case CPDF_PageObject::PATH:
- bRet = ProcessPath(pObj->AsPath(), pObj2Device);
- break;
- case CPDF_PageObject::IMAGE:
- bRet = ProcessImage(pObj->AsImage(), pObj2Device);
- break;
- case CPDF_PageObject::FORM:
- bRet = ProcessForm(pObj->AsForm(), pObj2Device);
- break;
- default:
- break;
- }
- return bRet;
-}
-void CPDF_RenderStatus::GetScaledMatrix(CFX_Matrix& matrix) const {
- CFX_Matrix dCTM = m_pDevice->GetCTM();
- matrix.a *= FXSYS_fabs(dCTM.a);
- matrix.d *= FXSYS_fabs(dCTM.d);
-}
-
-void CPDF_RenderStatus::DrawObjWithBackground(CPDF_PageObject* pObj,
- const CFX_Matrix* pObj2Device) {
- FX_RECT rect;
- if (GetObjectClippedRect(pObj, pObj2Device, false, rect)) {
- return;
- }
- int res = 300;
- if (pObj->IsImage() &&
- m_pDevice->GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) {
- res = 0;
- }
- CPDF_ScaledRenderBuffer buffer;
- if (!buffer.Initialize(m_pContext, m_pDevice, rect, pObj, &m_Options, res)) {
- return;
- }
- CFX_Matrix matrix = *pObj2Device;
- matrix.Concat(*buffer.GetMatrix());
- GetScaledMatrix(matrix);
- CPDF_Dictionary* pFormResource = nullptr;
- if (pObj->IsForm()) {
- const CPDF_FormObject* pFormObj = pObj->AsForm();
- if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) {
- pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources");
- }
- }
- CPDF_RenderStatus status;
- status.Initialize(m_pContext, buffer.GetDevice(), buffer.GetMatrix(), nullptr,
- nullptr, nullptr, &m_Options, m_Transparency,
- m_bDropObjects, pFormResource);
- status.RenderSingleObject(pObj, &matrix);
- buffer.OutputToDevice();
-}
-
-bool CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj,
- const CFX_Matrix* pObj2Device) {
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
- CPDF_Dictionary* pOC = pFormObj->m_pForm->m_pFormDict->GetDictFor("OC");
- if (pOC && m_Options.m_pOCContext &&
- !m_Options.m_pOCContext->CheckOCGVisible(pOC)) {
- return true;
- }
- CFX_Matrix matrix = pFormObj->m_FormMatrix;
- matrix.Concat(*pObj2Device);
- CPDF_Dictionary* pResources = nullptr;
- if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) {
- pResources = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources");
- }
- CPDF_RenderStatus status;
- status.Initialize(m_pContext, m_pDevice, nullptr, m_pStopObj, this, pFormObj,
- &m_Options, m_Transparency, m_bDropObjects, pResources,
- false);
- status.m_curBlend = m_curBlend;
- m_pDevice->SaveState();
- status.RenderObjectList(pFormObj->m_pForm.get(), &matrix);
- m_bStopped = status.m_bStopped;
- m_pDevice->RestoreState(false);
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
- return true;
-}
-
-bool IsAvailableMatrix(const CFX_Matrix& matrix) {
- if (matrix.a == 0 || matrix.d == 0) {
- return matrix.b != 0 && matrix.c != 0;
- }
- if (matrix.b == 0 || matrix.c == 0) {
- return matrix.a != 0 && matrix.d != 0;
- }
- return true;
-}
-
-bool CPDF_RenderStatus::ProcessPath(CPDF_PathObject* pPathObj,
- const CFX_Matrix* pObj2Device) {
- int FillType = pPathObj->m_FillType;
- bool bStroke = pPathObj->m_bStroke;
- ProcessPathPattern(pPathObj, pObj2Device, FillType, bStroke);
- if (FillType == 0 && !bStroke)
- return true;
-
- uint32_t fill_argb = FillType ? GetFillArgb(pPathObj) : 0;
- uint32_t stroke_argb = bStroke ? GetStrokeArgb(pPathObj) : 0;
- CFX_Matrix path_matrix = pPathObj->m_Matrix;
- path_matrix.Concat(*pObj2Device);
- if (!IsAvailableMatrix(path_matrix))
- return true;
-
- if (FillType && (m_Options.m_Flags & RENDER_RECT_AA))
- FillType |= FXFILL_RECT_AA;
- if (m_Options.m_Flags & RENDER_FILL_FULLCOVER)
- FillType |= FXFILL_FULLCOVER;
- if (m_Options.m_Flags & RENDER_NOPATHSMOOTH)
- FillType |= FXFILL_NOPATHSMOOTH;
- if (bStroke)
- FillType |= FX_FILL_STROKE;
-
- const CPDF_PageObject* pPageObj =
- static_cast<const CPDF_PageObject*>(pPathObj);
- if (pPageObj->m_GeneralState.GetStrokeAdjust())
- FillType |= FX_STROKE_ADJUST;
- if (m_pType3Char)
- FillType |= FX_FILL_TEXT_MODE;
-
- CFX_GraphState graphState = pPathObj->m_GraphState;
- if (m_Options.m_Flags & RENDER_THINLINE)
- graphState.SetLineWidth(0);
- return m_pDevice->DrawPathWithBlend(
- pPathObj->m_Path.GetObject(), &path_matrix, graphState.GetObject(),
- fill_argb, stroke_argb, FillType, m_curBlend);
-}
-
-CPDF_TransferFunc* CPDF_RenderStatus::GetTransferFunc(CPDF_Object* pObj) const {
- ASSERT(pObj);
- CPDF_DocRenderData* pDocCache = m_pContext->GetDocument()->GetRenderData();
- return pDocCache ? pDocCache->GetTransferFunc(pObj) : nullptr;
-}
-
-FX_ARGB CPDF_RenderStatus::GetFillArgb(CPDF_PageObject* pObj,
- bool bType3) const {
- const CPDF_ColorState* pColorState = &pObj->m_ColorState;
- if (m_pType3Char && !bType3 &&
- (!m_pType3Char->m_bColored ||
- (m_pType3Char->m_bColored &&
- (!*pColorState || pColorState->GetFillColor()->IsNull())))) {
- return m_T3FillColor;
- }
- if (!*pColorState || pColorState->GetFillColor()->IsNull())
- pColorState = &m_InitialStates.m_ColorState;
-
- FX_COLORREF rgb = pColorState->GetFillRGB();
- if (rgb == (uint32_t)-1)
- return 0;
-
- int32_t alpha =
- static_cast<int32_t>((pObj->m_GeneralState.GetFillAlpha() * 255));
- if (pObj->m_GeneralState.GetTR()) {
- if (!pObj->m_GeneralState.GetTransferFunc()) {
- pObj->m_GeneralState.SetTransferFunc(
- GetTransferFunc(pObj->m_GeneralState.GetTR()));
- }
- if (pObj->m_GeneralState.GetTransferFunc())
- rgb = pObj->m_GeneralState.GetTransferFunc()->TranslateColor(rgb);
- }
- return m_Options.TranslateColor(ArgbEncode(alpha, rgb));
-}
-
-FX_ARGB CPDF_RenderStatus::GetStrokeArgb(CPDF_PageObject* pObj) const {
- const CPDF_ColorState* pColorState = &pObj->m_ColorState;
- if (m_pType3Char &&
- (!m_pType3Char->m_bColored ||
- (m_pType3Char->m_bColored &&
- (!*pColorState || pColorState->GetStrokeColor()->IsNull())))) {
- return m_T3FillColor;
- }
- if (!*pColorState || pColorState->GetStrokeColor()->IsNull())
- pColorState = &m_InitialStates.m_ColorState;
-
- FX_COLORREF rgb = pColorState->GetStrokeRGB();
- if (rgb == (uint32_t)-1)
- return 0;
-
- int32_t alpha = static_cast<int32_t>(pObj->m_GeneralState.GetStrokeAlpha() *
- 255); // not rounded.
- if (pObj->m_GeneralState.GetTR()) {
- if (!pObj->m_GeneralState.GetTransferFunc()) {
- pObj->m_GeneralState.SetTransferFunc(
- GetTransferFunc(pObj->m_GeneralState.GetTR()));
- }
- if (pObj->m_GeneralState.GetTransferFunc())
- rgb = pObj->m_GeneralState.GetTransferFunc()->TranslateColor(rgb);
- }
- return m_Options.TranslateColor(ArgbEncode(alpha, rgb));
-}
-void CPDF_RenderStatus::ProcessClipPath(CPDF_ClipPath ClipPath,
- const CFX_Matrix* pObj2Device) {
- if (!ClipPath) {
- if (m_LastClipPath) {
- m_pDevice->RestoreState(true);
- m_LastClipPath.SetNull();
- }
- return;
- }
- if (m_LastClipPath == ClipPath)
- return;
-
- m_LastClipPath = ClipPath;
- m_pDevice->RestoreState(true);
- int nClipPath = ClipPath.GetPathCount();
- for (int i = 0; i < nClipPath; ++i) {
- const CFX_PathData* pPathData = ClipPath.GetPath(i).GetObject();
- if (!pPathData)
- continue;
-
- if (pPathData->GetPointCount() == 0) {
- CFX_PathData EmptyPath;
- EmptyPath.AppendRect(-1, -1, 0, 0);
- int fill_mode = FXFILL_WINDING;
- m_pDevice->SetClip_PathFill(&EmptyPath, nullptr, fill_mode);
- } else {
- int ClipType = ClipPath.GetClipType(i);
- m_pDevice->SetClip_PathFill(pPathData, pObj2Device, ClipType);
- }
- }
- int textcount = ClipPath.GetTextCount();
- if (textcount == 0)
- return;
-
- if (m_pDevice->GetDeviceClass() == FXDC_DISPLAY &&
- !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP)) {
- return;
- }
-
- std::unique_ptr<CFX_PathData> pTextClippingPath;
- for (int i = 0; i < textcount; ++i) {
- CPDF_TextObject* pText = ClipPath.GetText(i);
- if (pText) {
- if (!pTextClippingPath)
- pTextClippingPath.reset(new CFX_PathData);
- ProcessText(pText, pObj2Device, pTextClippingPath.get());
- continue;
- }
-
- if (!pTextClippingPath)
- continue;
-
- int fill_mode = FXFILL_WINDING;
- if (m_Options.m_Flags & RENDER_NOTEXTSMOOTH)
- fill_mode |= FXFILL_NOPATHSMOOTH;
- m_pDevice->SetClip_PathFill(pTextClippingPath.get(), nullptr, fill_mode);
- pTextClippingPath.reset();
- }
-}
-
-void CPDF_RenderStatus::DrawClipPath(CPDF_ClipPath ClipPath,
- const CFX_Matrix* pObj2Device) {
- if (!ClipPath)
- return;
-
- int fill_mode = 0;
- if (m_Options.m_Flags & RENDER_NOPATHSMOOTH) {
- fill_mode |= FXFILL_NOPATHSMOOTH;
- }
- int nClipPath = ClipPath.GetPathCount();
- int i;
- for (i = 0; i < nClipPath; i++) {
- const CFX_PathData* pPathData = ClipPath.GetPath(i).GetObject();
- if (!pPathData) {
- continue;
- }
- CFX_GraphStateData stroke_state;
- if (m_Options.m_Flags & RENDER_THINLINE) {
- stroke_state.m_LineWidth = 0;
- }
- m_pDevice->DrawPath(pPathData, pObj2Device, &stroke_state, 0, 0xffff0000,
- fill_mode);
- }
-}
-bool CPDF_RenderStatus::SelectClipPath(const CPDF_PathObject* pPathObj,
- const CFX_Matrix* pObj2Device,
- bool bStroke) {
- CFX_Matrix path_matrix = pPathObj->m_Matrix;
- path_matrix.Concat(*pObj2Device);
- if (bStroke) {
- CFX_GraphState graphState = pPathObj->m_GraphState;
- if (m_Options.m_Flags & RENDER_THINLINE)
- graphState.SetLineWidth(0);
- return m_pDevice->SetClip_PathStroke(pPathObj->m_Path.GetObject(),
- &path_matrix, graphState.GetObject());
- }
- int fill_mode = pPathObj->m_FillType;
- if (m_Options.m_Flags & RENDER_NOPATHSMOOTH) {
- fill_mode |= FXFILL_NOPATHSMOOTH;
- }
- return m_pDevice->SetClip_PathFill(pPathObj->m_Path.GetObject(), &path_matrix,
- fill_mode);
-}
-bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
- const CFX_Matrix* pObj2Device) {
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
- int blend_type = pPageObj->m_GeneralState.GetBlendType();
- if (blend_type == FXDIB_BLEND_UNSUPPORTED)
- return true;
-
- CPDF_Dictionary* pSMaskDict =
- ToDictionary(pPageObj->m_GeneralState.GetSoftMask());
- if (pSMaskDict) {
- if (pPageObj->IsImage() &&
- pPageObj->AsImage()->GetImage()->GetDict()->KeyExist("SMask")) {
- pSMaskDict = nullptr;
- }
- }
- CPDF_Dictionary* pFormResource = nullptr;
- FX_FLOAT group_alpha = 1.0f;
- int Transparency = m_Transparency;
- bool bGroupTransparent = false;
- if (pPageObj->IsForm()) {
- const CPDF_FormObject* pFormObj = pPageObj->AsForm();
- group_alpha = pFormObj->m_GeneralState.GetFillAlpha();
- Transparency = pFormObj->m_pForm->m_Transparency;
- bGroupTransparent = !!(Transparency & PDFTRANS_ISOLATED);
- if (pFormObj->m_pForm->m_pFormDict) {
- pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources");
- }
- }
- bool bTextClip =
- (pPageObj->m_ClipPath && pPageObj->m_ClipPath.GetTextCount() &&
- m_pDevice->GetDeviceClass() == FXDC_DISPLAY &&
- !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP));
- if ((m_Options.m_Flags & RENDER_OVERPRINT) && pPageObj->IsImage() &&
- pPageObj->m_GeneralState.GetFillOP() &&
- pPageObj->m_GeneralState.GetStrokeOP()) {
- CPDF_Document* pDocument = nullptr;
- CPDF_Page* pPage = nullptr;
- if (m_pContext->GetPageCache()) {
- pPage = m_pContext->GetPageCache()->GetPage();
- pDocument = pPage->m_pDocument;
- } else {
- pDocument = pPageObj->AsImage()->GetImage()->GetDocument();
- }
- CPDF_Dictionary* pPageResources = pPage ? pPage->m_pPageResources : nullptr;
- CPDF_Object* pCSObj = pPageObj->AsImage()
- ->GetImage()
- ->GetStream()
- ->GetDict()
- ->GetDirectObjectFor("ColorSpace");
- CPDF_ColorSpace* pColorSpace =
- pDocument->LoadColorSpace(pCSObj, pPageResources);
- if (pColorSpace) {
- int format = pColorSpace->GetFamily();
- if (format == PDFCS_DEVICECMYK || format == PDFCS_SEPARATION ||
- format == PDFCS_DEVICEN) {
- blend_type = FXDIB_BLEND_DARKEN;
- }
- pDocument->GetPageData()->ReleaseColorSpace(pCSObj);
- }
- }
- if (!pSMaskDict && group_alpha == 1.0f && blend_type == FXDIB_BLEND_NORMAL &&
- !bTextClip && !bGroupTransparent) {
- return false;
- }
- bool isolated = !!(Transparency & PDFTRANS_ISOLATED);
- if (m_bPrint) {
- bool bRet = false;
- int rendCaps = m_pDevice->GetRenderCaps();
- if (!((Transparency & PDFTRANS_ISOLATED) || pSMaskDict || bTextClip) &&
- (rendCaps & FXRC_BLEND_MODE)) {
- int oldBlend = m_curBlend;
- m_curBlend = blend_type;
- bRet = DrawObjWithBlend(pPageObj, pObj2Device);
- m_curBlend = oldBlend;
- }
- if (!bRet) {
- DrawObjWithBackground(pPageObj, pObj2Device);
- }
- return true;
- }
- FX_RECT rect = pPageObj->GetBBox(pObj2Device);
- rect.Intersect(m_pDevice->GetClipBox());
- if (rect.IsEmpty()) {
- return true;
- }
- CFX_Matrix deviceCTM = m_pDevice->GetCTM();
- FX_FLOAT scaleX = FXSYS_fabs(deviceCTM.a);
- FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d);
- int width = FXSYS_round((FX_FLOAT)rect.Width() * scaleX);
- int height = FXSYS_round((FX_FLOAT)rect.Height() * scaleY);
- CFX_FxgeDevice bitmap_device;
- std::unique_ptr<CFX_DIBitmap> oriDevice;
- if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
- oriDevice.reset(new CFX_DIBitmap);
- if (!m_pDevice->CreateCompatibleBitmap(oriDevice.get(), width, height))
- return true;
- m_pDevice->GetDIBits(oriDevice.get(), rect.left, rect.top);
- }
- if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice.get()))
- return true;
- CFX_DIBitmap* bitmap = bitmap_device.GetBitmap();
- bitmap->Clear(0);
- CFX_Matrix new_matrix = *pObj2Device;
- new_matrix.TranslateI(-rect.left, -rect.top);
- new_matrix.Scale(scaleX, scaleY);
- std::unique_ptr<CFX_DIBitmap> pTextMask;
- if (bTextClip) {
- pTextMask.reset(new CFX_DIBitmap);
- if (!pTextMask->Create(width, height, FXDIB_8bppMask))
- return true;
-
- pTextMask->Clear(0);
- CFX_FxgeDevice text_device;
- text_device.Attach(pTextMask.get(), false, nullptr, false);
- for (uint32_t i = 0; i < pPageObj->m_ClipPath.GetTextCount(); i++) {
- CPDF_TextObject* textobj = pPageObj->m_ClipPath.GetText(i);
- if (!textobj) {
- break;
- }
- CFX_Matrix text_matrix;
- textobj->GetTextMatrix(&text_matrix);
- CPDF_TextRenderer::DrawTextPath(
- &text_device, textobj->m_nChars, textobj->m_pCharCodes,
- textobj->m_pCharPos, textobj->m_TextState.GetFont(),
- textobj->m_TextState.GetFontSize(), &text_matrix, &new_matrix,
- textobj->m_GraphState.GetObject(), (FX_ARGB)-1, 0, nullptr, 0);
- }
- }
- CPDF_RenderStatus bitmap_render;
- bitmap_render.Initialize(m_pContext, &bitmap_device, nullptr, m_pStopObj,
- nullptr, nullptr, &m_Options, 0, m_bDropObjects,
- pFormResource, true);
- bitmap_render.ProcessObjectNoClip(pPageObj, &new_matrix);
- m_bStopped = bitmap_render.m_bStopped;
- if (pSMaskDict) {
- CFX_Matrix smask_matrix = *pPageObj->m_GeneralState.GetSMaskMatrix();
- smask_matrix.Concat(*pObj2Device);
- std::unique_ptr<CFX_DIBSource> pSMaskSource(
- LoadSMask(pSMaskDict, &rect, &smask_matrix));
- if (pSMaskSource)
- bitmap->MultiplyAlpha(pSMaskSource.get());
- }
- if (pTextMask) {
- bitmap->MultiplyAlpha(pTextMask.get());
- pTextMask.reset();
- }
- int32_t blitAlpha = 255;
- if (Transparency & PDFTRANS_GROUP && group_alpha != 1.0f) {
- blitAlpha = (int32_t)(group_alpha * 255);
-#ifndef _SKIA_SUPPORT_
- bitmap->MultiplyAlpha(blitAlpha);
- blitAlpha = 255;
-#endif
- }
- Transparency = m_Transparency;
- if (pPageObj->IsForm()) {
- Transparency |= PDFTRANS_GROUP;
- }
- CompositeDIBitmap(bitmap, rect.left, rect.top, 0, blitAlpha, blend_type,
- Transparency);
-#if defined _SKIA_SUPPORT_
- DebugVerifyDeviceIsPreMultiplied();
-#endif
- return true;
-}
-
-CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj,
- const FX_RECT& rect,
- int& left,
- int& top,
- bool bBackAlphaRequired) {
- FX_RECT bbox = rect;
- bbox.Intersect(m_pDevice->GetClipBox());
- left = bbox.left;
- top = bbox.top;
- CFX_Matrix deviceCTM = m_pDevice->GetCTM();
- FX_FLOAT scaleX = FXSYS_fabs(deviceCTM.a);
- FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d);
- int width = FXSYS_round(bbox.Width() * scaleX);
- int height = FXSYS_round(bbox.Height() * scaleY);
- std::unique_ptr<CFX_DIBitmap> pBackdrop(new CFX_DIBitmap);
- if (bBackAlphaRequired && !m_bDropObjects)
- pBackdrop->Create(width, height, FXDIB_Argb);
- else
- m_pDevice->CreateCompatibleBitmap(pBackdrop.get(), width, height);
-
- if (!pBackdrop->GetBuffer())
- return nullptr;
-
- bool bNeedDraw;
- if (pBackdrop->HasAlpha())
- bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT);
- else
- bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS);
-
- if (!bNeedDraw) {
- m_pDevice->GetDIBits(pBackdrop.get(), left, top);
- return pBackdrop.release();
- }
-
- CFX_Matrix FinalMatrix = m_DeviceMatrix;
- FinalMatrix.TranslateI(-left, -top);
- FinalMatrix.Scale(scaleX, scaleY);
- pBackdrop->Clear(pBackdrop->HasAlpha() ? 0 : 0xffffffff);
- CFX_FxgeDevice device;
- device.Attach(pBackdrop.get(), false, nullptr, false);
- m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix);
- return pBackdrop.release();
-}
-
void CPDF_RenderContext::GetBackground(CFX_DIBitmap* pBuffer,
const CPDF_PageObject* pObj,
const CPDF_RenderOptions* pOptions,
@@ -847,25 +104,6 @@ void CPDF_RenderContext::GetBackground(CFX_DIBitmap* pBuffer,
device.FillRect(&rect, 0xffffffff);
Render(&device, pObj, pOptions, pFinalMatrix);
}
-CPDF_GraphicStates* CPDF_RenderStatus::CloneObjStates(
- const CPDF_GraphicStates* pSrcStates,
- bool bStroke) {
- if (!pSrcStates)
- return nullptr;
-
- CPDF_GraphicStates* pStates = new CPDF_GraphicStates;
- pStates->CopyStates(*pSrcStates);
- const CPDF_Color* pObjColor = bStroke
- ? pSrcStates->m_ColorState.GetStrokeColor()
- : pSrcStates->m_ColorState.GetFillColor();
- if (!pObjColor->IsNull()) {
- pStates->m_ColorState.SetFillRGB(
- bStroke ? pSrcStates->m_ColorState.GetStrokeRGB()
- : pSrcStates->m_ColorState.GetFillRGB());
- pStates->m_ColorState.SetStrokeRGB(pStates->m_ColorState.GetFillRGB());
- }
- return pStates;
-}
CPDF_RenderContext::CPDF_RenderContext(CPDF_Page* pPage)
: m_pDocument(pPage->m_pDocument),
@@ -1162,9 +400,3 @@ void CPDF_ScaledRenderBuffer::OutputToDevice() {
m_Rect.top, m_Rect.Width(), m_Rect.Height());
}
}
-
-#if defined _SKIA_SUPPORT_
-void CPDF_RenderStatus::DebugVerifyDeviceIsPreMultiplied() const {
- m_pDevice->DebugVerifyBitmapIsPreMultiplied();
-}
-#endif