diff options
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_allstates.cpp | 48 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_generalstate.cpp | 147 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_pageobject.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 11 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_generalstate.h | 71 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h | 10 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render.cpp | 94 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_image.cpp | 43 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 12 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_text.cpp | 13 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/render_int.h | 37 |
12 files changed, 327 insertions, 164 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp index acecafd01e..89c13215ae 100644 --- a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp @@ -50,7 +50,6 @@ void CPDF_AllStates::SetLineDash(CPDF_Array* pArray, void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser* pParser) { - CPDF_GeneralStateData* pGeneralState = m_GeneralState.GetPrivateCopy(); for (const auto& it : *pGS) { const CFX_ByteString& key_str = it.first; CPDF_Object* pElement = it.second; @@ -103,80 +102,77 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, continue; } case FXBSTR_ID('T', 'R', '2', 0): - pGeneralState->m_pTR = - (pObject && !pObject->IsName()) ? pObject : nullptr; + m_GeneralState.SetTR(pObject && !pObject->IsName() ? pObject : nullptr); break; case FXBSTR_ID('B', 'M', 0, 0): { CPDF_Array* pArray = pObject->AsArray(); CFX_ByteString mode = pArray ? pArray->GetStringAt(0) : pObject->GetString(); - pGeneralState->SetBlendMode(mode.AsStringC()); - if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) { + m_GeneralState.SetBlendMode(mode.AsStringC()); + if (m_GeneralState.GetBlendType() > FXDIB_BLEND_MULTIPLY) pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(TRUE); - } break; } case FXBSTR_ID('S', 'M', 'a', 's'): if (ToDictionary(pObject)) { - pGeneralState->m_pSoftMask = pObject; - FXSYS_memcpy(pGeneralState->m_SMaskMatrix, + m_GeneralState.SetSoftMask(pObject); + FXSYS_memcpy(m_GeneralState.GetMutableSMaskMatrix(), &pParser->GetCurStates()->m_CTM, sizeof(CFX_Matrix)); } else { - pGeneralState->m_pSoftMask = nullptr; + m_GeneralState.SetSoftMask(nullptr); } break; case FXBSTR_ID('C', 'A', 0, 0): - pGeneralState->m_StrokeAlpha = ClipFloat(pObject->GetNumber()); + m_GeneralState.SetStrokeAlpha(ClipFloat(pObject->GetNumber())); break; case FXBSTR_ID('c', 'a', 0, 0): - pGeneralState->m_FillAlpha = ClipFloat(pObject->GetNumber()); + m_GeneralState.SetFillAlpha(ClipFloat(pObject->GetNumber())); break; case FXBSTR_ID('O', 'P', 0, 0): - pGeneralState->m_StrokeOP = pObject->GetInteger(); - if (!pGS->KeyExist("op")) { - pGeneralState->m_FillOP = pObject->GetInteger(); - } + m_GeneralState.SetStrokeOP(!!pObject->GetInteger()); + if (!pGS->KeyExist("op")) + m_GeneralState.SetFillOP(!!pObject->GetInteger()); break; case FXBSTR_ID('o', 'p', 0, 0): - pGeneralState->m_FillOP = pObject->GetInteger(); + m_GeneralState.SetFillOP(!!pObject->GetInteger()); break; case FXBSTR_ID('O', 'P', 'M', 0): - pGeneralState->m_OPMode = pObject->GetInteger(); + m_GeneralState.SetOPMode(pObject->GetInteger()); break; case FXBSTR_ID('B', 'G', 0, 0): if (pGS->KeyExist("BG2")) { continue; } case FXBSTR_ID('B', 'G', '2', 0): - pGeneralState->m_pBG = pObject; + m_GeneralState.SetBG(pObject); break; case FXBSTR_ID('U', 'C', 'R', 0): if (pGS->KeyExist("UCR2")) { continue; } case FXBSTR_ID('U', 'C', 'R', '2'): - pGeneralState->m_pUCR = pObject; + m_GeneralState.SetUCR(pObject); break; case FXBSTR_ID('H', 'T', 0, 0): - pGeneralState->m_pHT = pObject; + m_GeneralState.SetHT(pObject); break; case FXBSTR_ID('F', 'L', 0, 0): - pGeneralState->m_Flatness = pObject->GetNumber(); + m_GeneralState.SetFlatness(pObject->GetNumber()); break; case FXBSTR_ID('S', 'M', 0, 0): - pGeneralState->m_Smoothness = pObject->GetNumber(); + m_GeneralState.SetSmoothness(pObject->GetNumber()); break; case FXBSTR_ID('S', 'A', 0, 0): - pGeneralState->m_StrokeAdjust = pObject->GetInteger(); + m_GeneralState.SetStrokeAdjust(!!pObject->GetInteger()); break; case FXBSTR_ID('A', 'I', 'S', 0): - pGeneralState->m_AlphaSource = pObject->GetInteger(); + m_GeneralState.SetAlphaSource(!!pObject->GetInteger()); break; case FXBSTR_ID('T', 'K', 0, 0): - pGeneralState->m_TextKnockout = pObject->GetInteger(); + m_GeneralState.SetTextKnockout(!!pObject->GetInteger()); break; } } - pGeneralState->m_Matrix = m_CTM; + m_GeneralState.SetMatrix(m_CTM); } diff --git a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp index 0f6cce6e29..e34801f534 100644 --- a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp @@ -24,6 +24,151 @@ int RI_StringToId(const CFX_ByteString& ri) { } // namespace +CPDF_GeneralState::CPDF_GeneralState() {} + +CPDF_GeneralState::CPDF_GeneralState(const CPDF_GeneralState& that) + : m_Ref(that.m_Ref) {} + +CPDF_GeneralState::~CPDF_GeneralState() {} + void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { - GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); + m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); +} + +int CPDF_GeneralState::GetBlendType() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL; +} + +void CPDF_GeneralState::SetBlendType(int type) { + m_Ref.GetPrivateCopy()->m_BlendType = type; +} + +FX_FLOAT CPDF_GeneralState::GetFillAlpha() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_FillAlpha : 1.0f; +} + +void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) { + m_Ref.GetPrivateCopy()->m_FillAlpha = alpha; +} + +FX_FLOAT CPDF_GeneralState::GetStrokeAlpha() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_StrokeAlpha : 1.0f; +} + +void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) { + m_Ref.GetPrivateCopy()->m_StrokeAlpha = alpha; +} + +CPDF_Object* CPDF_GeneralState::GetSoftMask() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_pSoftMask : nullptr; +} + +void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) { + m_Ref.GetPrivateCopy()->m_pSoftMask = pObject; +} + +CPDF_Object* CPDF_GeneralState::GetTR() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_pTR : nullptr; +} + +void CPDF_GeneralState::SetTR(CPDF_Object* pObject) { + m_Ref.GetPrivateCopy()->m_pTR = pObject; +} + +CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_pTransferFunc : nullptr; +} + +void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) { + m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc; +} + +void CPDF_GeneralState::SetBlendMode(const CFX_ByteStringC& mode) { + m_Ref.GetPrivateCopy()->SetBlendMode(mode); +} + +const FX_FLOAT* CPDF_GeneralState::GetSMaskMatrix() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData ? pData->m_SMaskMatrix : nullptr; +} + +FX_FLOAT* CPDF_GeneralState::GetMutableSMaskMatrix() { + return m_Ref.GetPrivateCopy()->m_SMaskMatrix; +} + +bool CPDF_GeneralState::GetFillOP() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData && pData->m_FillOP; +} + +void CPDF_GeneralState::SetFillOP(bool op) { + m_Ref.GetPrivateCopy()->m_FillOP = op; +} + +void CPDF_GeneralState::SetStrokeOP(bool op) { + m_Ref.GetPrivateCopy()->m_StrokeOP = op; +} + +bool CPDF_GeneralState::GetStrokeOP() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData && pData->m_StrokeOP; +} + +int CPDF_GeneralState::GetOPMode() const { + return m_Ref.GetObject()->m_OPMode; +} + +void CPDF_GeneralState::SetOPMode(int mode) { + m_Ref.GetPrivateCopy()->m_OPMode = mode; +} + +void CPDF_GeneralState::SetBG(CPDF_Object* pObject) { + m_Ref.GetPrivateCopy()->m_pBG = pObject; +} + +void CPDF_GeneralState::SetUCR(CPDF_Object* pObject) { + m_Ref.GetPrivateCopy()->m_pUCR = pObject; +} + +void CPDF_GeneralState::SetHT(CPDF_Object* pObject) { + m_Ref.GetPrivateCopy()->m_pHT = pObject; +} + +void CPDF_GeneralState::SetFlatness(FX_FLOAT flatness) { + m_Ref.GetPrivateCopy()->m_Flatness = flatness; +} + +void CPDF_GeneralState::SetSmoothness(FX_FLOAT smoothness) { + m_Ref.GetPrivateCopy()->m_Smoothness = smoothness; +} + +bool CPDF_GeneralState::GetStrokeAdjust() const { + const CPDF_GeneralStateData* pData = m_Ref.GetObject(); + return pData && pData->m_StrokeAdjust; +} + +void CPDF_GeneralState::SetStrokeAdjust(bool adjust) { + m_Ref.GetPrivateCopy()->m_StrokeAdjust = adjust; +} + +void CPDF_GeneralState::SetAlphaSource(bool source) { + m_Ref.GetPrivateCopy()->m_AlphaSource = source; +} + +void CPDF_GeneralState::SetTextKnockout(bool knockout) { + m_Ref.GetPrivateCopy()->m_TextKnockout = knockout; +} + +void CPDF_GeneralState::SetMatrix(const CFX_Matrix& matrix) { + m_Ref.GetPrivateCopy()->m_Matrix = matrix; +} + +CFX_Matrix* CPDF_GeneralState::GetMutableMatrix() { + return &m_Ref.GetPrivateCopy()->m_Matrix; } diff --git a/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp b/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp index 17014c4883..1ce83a85bc 100644 --- a/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp @@ -88,8 +88,7 @@ void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) { void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) { if (!m_GeneralState) return; - CPDF_GeneralStateData* pGS = m_GeneralState.GetPrivateCopy(); - pGS->m_Matrix.Concat(matrix); + m_GeneralState.GetMutableMatrix()->Concat(matrix); } FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 4712ea0725..cf77de15a4 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -865,7 +865,7 @@ void CPDF_StreamContentParser::Handle_ClosePath() { } void CPDF_StreamContentParser::Handle_SetFlat() { - m_pCurStates->m_GeneralState.GetPrivateCopy()->m_Flatness = GetNumber(0); + m_pCurStates->m_GeneralState.SetFlatness(GetNumber(0)); } void CPDF_StreamContentParser::Handle_BeginImageData() {} diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 92a9d6c92e..745a707902 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -711,12 +711,11 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm, TRUE); } if (pForm->m_Transparency & PDFTRANS_GROUP) { - CPDF_GeneralStateData* pData = - m_pParser->GetCurStates()->m_GeneralState.GetPrivateCopy(); - pData->m_BlendType = FXDIB_BLEND_NORMAL; - pData->m_StrokeAlpha = 1.0f; - pData->m_FillAlpha = 1.0f; - pData->m_pSoftMask = nullptr; + CPDF_GeneralState* pState = &m_pParser->GetCurStates()->m_GeneralState; + pState->SetBlendType(FXDIB_BLEND_NORMAL); + pState->SetStrokeAlpha(1.0f); + pState->SetFillAlpha(1.0f); + pState->SetSoftMask(nullptr); } m_nStreams = 0; m_pSingleStream.reset(new CPDF_StreamAcc); diff --git a/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h b/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h index dff8371119..b653d640d7 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h @@ -10,22 +10,67 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h" #include "core/fxcrt/include/fx_basic.h" -class CPDF_GeneralState : public CFX_CountRef<CPDF_GeneralStateData> { +class CPDF_GeneralState { public: + CPDF_GeneralState(); + CPDF_GeneralState(const CPDF_GeneralState& that); + ~CPDF_GeneralState(); + + void Emplace() { m_Ref.Emplace(); } + operator bool() const { return !!m_Ref; } + void SetRenderIntent(const CFX_ByteString& ri); - int GetBlendType() const { - const CPDF_GeneralStateData* pData = GetObject(); - return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL; - } - - int GetAlpha(FX_BOOL bStroke) const { - const CPDF_GeneralStateData* pData = GetObject(); - if (!pData) - return 255; - return FXSYS_round((bStroke ? pData->m_StrokeAlpha : pData->m_FillAlpha) * - 255); - } + int GetBlendType() const; + void SetBlendType(int type); + + FX_FLOAT GetFillAlpha() const; + void SetFillAlpha(FX_FLOAT alpha); + + FX_FLOAT GetStrokeAlpha() const; + void SetStrokeAlpha(FX_FLOAT alpha); + + CPDF_Object* GetSoftMask() const; + void SetSoftMask(CPDF_Object* pObject); + + CPDF_Object* GetTR() const; + void SetTR(CPDF_Object* pObject); + + CPDF_TransferFunc* GetTransferFunc() const; + void SetTransferFunc(CPDF_TransferFunc* pFunc); + + void SetBlendMode(const CFX_ByteStringC& mode); + + const FX_FLOAT* GetSMaskMatrix() const; + FX_FLOAT* GetMutableSMaskMatrix(); + + bool GetFillOP() const; + void SetFillOP(bool op); + + bool GetStrokeOP() const; + void SetStrokeOP(bool op); + + int GetOPMode() const; + void SetOPMode(int mode); + + void SetBG(CPDF_Object* pObject); + void SetUCR(CPDF_Object* pObject); + void SetHT(CPDF_Object* pObject); + + void SetFlatness(FX_FLOAT flatness); + void SetSmoothness(FX_FLOAT smoothness); + + bool GetStrokeAdjust() const; + void SetStrokeAdjust(bool adjust); + + void SetAlphaSource(bool source); + void SetTextKnockout(bool knockout); + + void SetMatrix(const CFX_Matrix& matrix); + CFX_Matrix* GetMutableMatrix(); + + private: + CFX_CountRef<CPDF_GeneralStateData> m_Ref; }; #endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATE_H_ diff --git a/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h index a4577a6cb0..e19bcc76ac 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h @@ -33,11 +33,11 @@ class CPDF_GeneralStateData { CPDF_TransferFunc* m_pTransferFunc; CFX_Matrix m_Matrix; int m_RenderIntent; - FX_BOOL m_StrokeAdjust; - FX_BOOL m_AlphaSource; - FX_BOOL m_TextKnockout; - FX_BOOL m_StrokeOP; - FX_BOOL m_FillOP; + bool m_StrokeAdjust; + bool m_AlphaSource; + bool m_TextKnockout; + bool m_StrokeOP; + bool m_FillOP; int m_OPMode; CPDF_Object* m_pBG; CPDF_Object* m_pUCR; diff --git a/core/fpdfapi/fpdf_render/fpdf_render.cpp b/core/fpdfapi/fpdf_render/fpdf_render.cpp index 7df6b9a4b2..1ac5bfa04c 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render.cpp @@ -249,7 +249,7 @@ void CPDF_RenderStatus::RenderObjectList( #endif } -void CPDF_RenderStatus::RenderSingleObject(const CPDF_PageObject* pObj, +void CPDF_RenderStatus::RenderSingleObject(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device) { #if defined _SKIA_SUPPORT_ DebugVerifyDeviceIsPreMultiplied(); @@ -274,7 +274,7 @@ void CPDF_RenderStatus::RenderSingleObject(const CPDF_PageObject* pObj, #endif } -FX_BOOL CPDF_RenderStatus::ContinueSingleObject(const CPDF_PageObject* pObj, +FX_BOOL CPDF_RenderStatus::ContinueSingleObject(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, IFX_Pause* pPause) { if (m_pImageRenderer) { @@ -335,7 +335,7 @@ FX_BOOL CPDF_RenderStatus::GetObjectClippedRect(const CPDF_PageObject* pObj, return rect.IsEmpty(); } -void CPDF_RenderStatus::ProcessObjectNoClip(const CPDF_PageObject* pObj, +void CPDF_RenderStatus::ProcessObjectNoClip(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device) { #if defined _SKIA_SUPPORT_ DebugVerifyDeviceIsPreMultiplied(); @@ -365,7 +365,7 @@ void CPDF_RenderStatus::ProcessObjectNoClip(const CPDF_PageObject* pObj, #endif } -FX_BOOL CPDF_RenderStatus::DrawObjWithBlend(const CPDF_PageObject* pObj, +FX_BOOL CPDF_RenderStatus::DrawObjWithBlend(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device) { FX_BOOL bRet = FALSE; switch (pObj->GetType()) { @@ -388,7 +388,8 @@ void CPDF_RenderStatus::GetScaledMatrix(CFX_Matrix& matrix) const { matrix.a *= FXSYS_fabs(dCTM.a); matrix.d *= FXSYS_fabs(dCTM.d); } -void CPDF_RenderStatus::DrawObjWithBackground(const CPDF_PageObject* pObj, + +void CPDF_RenderStatus::DrawObjWithBackground(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device) { FX_RECT rect; if (GetObjectClippedRect(pObj, pObj2Device, FALSE, rect)) { @@ -462,7 +463,7 @@ FX_BOOL IsAvailableMatrix(const CFX_Matrix& matrix) { return TRUE; } -FX_BOOL CPDF_RenderStatus::ProcessPath(const CPDF_PathObject* pPathObj, +FX_BOOL CPDF_RenderStatus::ProcessPath(CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device) { int FillType = pPathObj->m_FillType; FX_BOOL bStroke = pPathObj->m_bStroke; @@ -485,9 +486,10 @@ FX_BOOL CPDF_RenderStatus::ProcessPath(const CPDF_PathObject* pPathObj, FillType |= FXFILL_NOPATHSMOOTH; if (bStroke) FillType |= FX_FILL_STROKE; - const CPDF_GeneralStateData* pGeneralData = - static_cast<const CPDF_PageObject*>(pPathObj)->m_GeneralState.GetObject(); - if (pGeneralData && pGeneralData->m_StrokeAdjust) + + 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; @@ -505,7 +507,8 @@ CPDF_TransferFunc* CPDF_RenderStatus::GetTransferFunc(CPDF_Object* pObj) const { CPDF_DocRenderData* pDocCache = m_pContext->GetDocument()->GetRenderData(); return pDocCache ? pDocCache->GetTransferFunc(pObj) : nullptr; } -FX_ARGB CPDF_RenderStatus::GetFillArgb(const CPDF_PageObject* pObj, + +FX_ARGB CPDF_RenderStatus::GetFillArgb(CPDF_PageObject* pObj, FX_BOOL bType3) const { const CPDF_ColorStateData* pColorData = pObj->m_ColorState.GetObject(); if (m_pType3Char && !bType3 && @@ -521,25 +524,20 @@ FX_ARGB CPDF_RenderStatus::GetFillArgb(const CPDF_PageObject* pObj, if (rgb == (uint32_t)-1) { return 0; } - const CPDF_GeneralStateData* pGeneralData = pObj->m_GeneralState.GetObject(); - int alpha; - if (pGeneralData) { - alpha = (int32_t)(pGeneralData->m_FillAlpha * 255); - if (pGeneralData->m_pTR) { - if (!pGeneralData->m_pTransferFunc) { - ((CPDF_GeneralStateData*)pGeneralData)->m_pTransferFunc = - GetTransferFunc(pGeneralData->m_pTR); - } - if (pGeneralData->m_pTransferFunc) { - rgb = pGeneralData->m_pTransferFunc->TranslateColor(rgb); - } + 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())); } - } else { - alpha = 255; + if (pObj->m_GeneralState.GetTransferFunc()) + rgb = pObj->m_GeneralState.GetTransferFunc()->TranslateColor(rgb); } return m_Options.TranslateColor(ArgbEncode(alpha, rgb)); } -FX_ARGB CPDF_RenderStatus::GetStrokeArgb(const CPDF_PageObject* pObj) const { + +FX_ARGB CPDF_RenderStatus::GetStrokeArgb(CPDF_PageObject* pObj) const { const CPDF_ColorStateData* pColorData = pObj->m_ColorState.GetObject(); if (m_pType3Char && (!m_pType3Char->m_bColored || (m_pType3Char->m_bColored && @@ -553,21 +551,15 @@ FX_ARGB CPDF_RenderStatus::GetStrokeArgb(const CPDF_PageObject* pObj) const { if (rgb == (uint32_t)-1) { return 0; } - const CPDF_GeneralStateData* pGeneralData = pObj->m_GeneralState.GetObject(); - int alpha; - if (pGeneralData) { - alpha = (int32_t)(pGeneralData->m_StrokeAlpha * 255); - if (pGeneralData->m_pTR) { - if (!pGeneralData->m_pTransferFunc) { - ((CPDF_GeneralStateData*)pGeneralData)->m_pTransferFunc = - GetTransferFunc(pGeneralData->m_pTR); - } - if (pGeneralData->m_pTransferFunc) { - rgb = pGeneralData->m_pTransferFunc->TranslateColor(rgb); - } + 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())); } - } else { - alpha = 255; + if (pObj->m_GeneralState.GetTransferFunc()) + rgb = pObj->m_GeneralState.GetTransferFunc()->TranslateColor(rgb); } return m_Options.TranslateColor(ArgbEncode(alpha, rgb)); } @@ -675,20 +667,17 @@ FX_BOOL CPDF_RenderStatus::SelectClipPath(const CPDF_PathObject* pPathObj, return m_pDevice->SetClip_PathFill(pPathObj->m_Path.GetObject(), &path_matrix, fill_mode); } -FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, +FX_BOOL CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj, const CFX_Matrix* pObj2Device) { #if defined _SKIA_SUPPORT_ DebugVerifyDeviceIsPreMultiplied(); #endif - const CPDF_GeneralStateData* pGeneralState = - pPageObj->m_GeneralState.GetObject(); - int blend_type = - pGeneralState ? pGeneralState->m_BlendType : FXDIB_BLEND_NORMAL; - if (blend_type == FXDIB_BLEND_UNSUPPORTED) { + int blend_type = pPageObj->m_GeneralState.GetBlendType(); + if (blend_type == FXDIB_BLEND_UNSUPPORTED) return TRUE; - } + CPDF_Dictionary* pSMaskDict = - pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : nullptr; + ToDictionary(pPageObj->m_GeneralState.GetSoftMask()); if (pSMaskDict) { if (pPageObj->IsImage() && pPageObj->AsImage()->GetImage()->GetDict()->KeyExist("SMask")) { @@ -701,11 +690,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, FX_BOOL bGroupTransparent = FALSE; if (pPageObj->IsForm()) { const CPDF_FormObject* pFormObj = pPageObj->AsForm(); - const CPDF_GeneralStateData* pStateData = - pFormObj->m_GeneralState.GetObject(); - if (pStateData) { - group_alpha = pStateData->m_FillAlpha; - } + group_alpha = pFormObj->m_GeneralState.GetFillAlpha(); Transparency = pFormObj->m_pForm->m_Transparency; bGroupTransparent = !!(Transparency & PDFTRANS_ISOLATED); if (pFormObj->m_pForm->m_pFormDict) { @@ -717,7 +702,8 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, m_pDevice->GetDeviceClass() == FXDC_DISPLAY && !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP)); if ((m_Options.m_Flags & RENDER_OVERPRINT) && pPageObj->IsImage() && - pGeneralState && pGeneralState->m_FillOP && pGeneralState->m_StrokeOP) { + pPageObj->m_GeneralState.GetFillOP() && + pPageObj->m_GeneralState.GetStrokeOP()) { CPDF_Document* pDocument = nullptr; CPDF_Page* pPage = nullptr; if (m_pContext->GetPageCache()) { @@ -819,7 +805,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, m_bStopped = bitmap_render.m_bStopped; if (pSMaskDict) { CFX_Matrix smask_matrix; - FXSYS_memcpy(&smask_matrix, pGeneralState->m_SMaskMatrix, + FXSYS_memcpy(&smask_matrix, pPageObj->m_GeneralState.GetSMaskMatrix(), sizeof smask_matrix); smask_matrix.Concat(*pObj2Device); std::unique_ptr<CFX_DIBSource> pSMaskSource( diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp index 295ac4f7d7..e7e9682322 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -33,7 +33,7 @@ #include "core/fxge/skia/fx_skia_device.h" #endif -FX_BOOL CPDF_RenderStatus::ProcessImage(const CPDF_ImageObject* pImageObj, +FX_BOOL CPDF_RenderStatus::ProcessImage(CPDF_ImageObject* pImageObj, const CFX_Matrix* pObj2Device) { CPDF_ImageRenderer render; if (render.Start(this, pImageObj, pObj2Device, m_bStdCS, m_curBlend)) { @@ -388,30 +388,27 @@ FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() { } FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { - if (!m_Loader.m_pBitmap) { + if (!m_Loader.m_pBitmap) return FALSE; - } - m_BitmapAlpha = 255; - const CPDF_GeneralStateData* pGeneralState = - m_pImageObject->m_GeneralState.GetObject(); - if (pGeneralState) { - m_BitmapAlpha = FXSYS_round(pGeneralState->m_FillAlpha * 255); - } + + m_BitmapAlpha = + FXSYS_round(255 * m_pImageObject->m_GeneralState.GetFillAlpha()); m_pDIBSource = m_Loader.m_pBitmap; if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_ALPHA && !m_Loader.m_pMask) { return StartBitmapAlpha(); } - if (pGeneralState && pGeneralState->m_pTR) { - if (!pGeneralState->m_pTransferFunc) { - ((CPDF_GeneralStateData*)pGeneralState)->m_pTransferFunc = - m_pRenderStatus->GetTransferFunc(pGeneralState->m_pTR); + if (m_pImageObject->m_GeneralState.GetTR()) { + if (!m_pImageObject->m_GeneralState.GetTransferFunc()) { + m_pImageObject->m_GeneralState.SetTransferFunc( + m_pRenderStatus->GetTransferFunc( + m_pImageObject->m_GeneralState.GetTR())); } - if (pGeneralState->m_pTransferFunc && - !pGeneralState->m_pTransferFunc->m_bIdentity) { + if (m_pImageObject->m_GeneralState.GetTransferFunc() && + !m_pImageObject->m_GeneralState.GetTransferFunc()->m_bIdentity) { m_pDIBSource = m_Loader.m_pBitmap = - pGeneralState->m_pTransferFunc->TranslateImage(m_Loader.m_pBitmap, - !m_Loader.m_bCached); + m_pImageObject->m_GeneralState.GetTransferFunc()->TranslateImage( + m_Loader.m_pBitmap, !m_Loader.m_bCached); if (m_Loader.m_bCached && m_Loader.m_pMask) { m_Loader.m_pMask = m_Loader.m_pMask->Clone(); } @@ -474,10 +471,12 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { if (m_bPatternColor) { return DrawPatternImage(m_pObj2Device); } - if (m_BitmapAlpha == 255 && pGeneralState && pGeneralState->m_FillOP && - pGeneralState->m_OPMode == 0 && - pGeneralState->m_BlendType == FXDIB_BLEND_NORMAL && - pGeneralState->m_StrokeAlpha == 1 && pGeneralState->m_FillAlpha == 1) { + if (m_BitmapAlpha == 255 && m_pImageObject->m_GeneralState && + m_pImageObject->m_GeneralState.GetFillOP() && + m_pImageObject->m_GeneralState.GetOPMode() == 0 && + m_pImageObject->m_GeneralState.GetBlendType() == FXDIB_BLEND_NORMAL && + m_pImageObject->m_GeneralState.GetStrokeAlpha() == 1.0f && + m_pImageObject->m_GeneralState.GetFillAlpha() == 1.0f) { CPDF_Document* pDocument = nullptr; CPDF_Page* pPage = nullptr; if (m_pRenderStatus->m_pContext->GetPageCache()) { @@ -505,7 +504,7 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { } FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus, - const CPDF_PageObject* pObj, + CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, FX_BOOL bStdCS, int blendType) { diff --git a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index fc06c0be57..090060d2c0 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -961,7 +961,9 @@ void CPDF_RenderStatus::DrawShadingPattern(CPDF_ShadingPattern* pattern, CFX_Matrix matrix = *pattern->pattern_to_form(); matrix.Concat(*pObj2Device); GetScaledMatrix(matrix); - int alpha = pPageObj->m_GeneralState.GetAlpha(bStroke); + int alpha = + FXSYS_round(255 * (bStroke ? pPageObj->m_GeneralState.GetStrokeAlpha() + : pPageObj->m_GeneralState.GetFillAlpha())); DrawShading(pattern, &matrix, rect, alpha, m_Options.m_ColorMode == RENDER_COLOR_ALPHA); m_pDevice->RestoreState(false); @@ -978,12 +980,12 @@ void CPDF_RenderStatus::ProcessShading(const CPDF_ShadingObject* pShadingObj, CFX_Matrix matrix = pShadingObj->m_Matrix; matrix.Concat(*pObj2Device); DrawShading(pShadingObj->m_pShading, &matrix, rect, - pShadingObj->m_GeneralState.GetAlpha(FALSE), + FXSYS_round(255 * pShadingObj->m_GeneralState.GetFillAlpha()), m_Options.m_ColorMode == RENDER_COLOR_ALPHA); } void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, - const CPDF_PageObject* pPageObj, + CPDF_PageObject* pPageObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke) { if (!pPattern->Load()) { @@ -1167,7 +1169,7 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, m_pDevice->RestoreState(false); } -void CPDF_RenderStatus::DrawPathWithPattern(const CPDF_PathObject* pPathObj, +void CPDF_RenderStatus::DrawPathWithPattern(CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, const CPDF_Color* pColor, FX_BOOL bStroke) { @@ -1181,7 +1183,7 @@ void CPDF_RenderStatus::DrawPathWithPattern(const CPDF_PathObject* pPathObj, DrawShadingPattern(pShadingPattern, pPathObj, pObj2Device, bStroke); } -void CPDF_RenderStatus::ProcessPathPattern(const CPDF_PathObject* pPathObj, +void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, int& filltype, FX_BOOL& bStroke) { diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp index ed254c17be..74997027ca 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -32,7 +32,7 @@ #include "core/fxge/include/cfx_pathdata.h" #include "core/fxge/include/cfx_renderdevice.h" -FX_BOOL CPDF_RenderStatus::ProcessText(const CPDF_TextObject* textobj, +FX_BOOL CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj, const CFX_Matrix* pObj2Device, CFX_PathData* pClippingPath) { if (textobj->m_nChars == 0) @@ -128,15 +128,10 @@ FX_BOOL CPDF_RenderStatus::ProcessText(const CPDF_TextObject* textobj, flag |= FX_FILL_STROKE; flag |= FX_STROKE_TEXT_MODE; } - const CPDF_GeneralStateData* pGeneralData = - static_cast<const CPDF_PageObject*>(textobj) - ->m_GeneralState.GetObject(); - if (pGeneralData && pGeneralData->m_StrokeAdjust) { + if (textobj->m_GeneralState.GetStrokeAdjust()) flag |= FX_STROKE_ADJUST; - } - if (m_Options.m_Flags & RENDER_NOTEXTSMOOTH) { + if (m_Options.m_Flags & RENDER_NOTEXTSMOOTH) flag |= FXFILL_NOPATHSMOOTH; - } return CPDF_TextRenderer::DrawTextPath( m_pDevice, textobj->m_nChars, textobj->m_pCharCodes, textobj->m_pCharPos, pFont, font_size, &text_matrix, pDeviceMatrix, @@ -178,7 +173,7 @@ class CPDF_RefType3Cache { }; // TODO(npm): Font fallback for type 3 fonts? (Completely separate code!!) -FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj, +FX_BOOL CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, const CFX_Matrix* pObj2Device) { CPDF_Type3Font* pType3Font = textobj->m_TextState.GetFont()->AsType3Font(); for (int i = 0; i < m_Type3FontCache.GetSize(); ++i) { diff --git a/core/fpdfapi/fpdf_render/render_int.h b/core/fpdfapi/fpdf_render/render_int.h index 893784bc8f..672e5923df 100644 --- a/core/fpdfapi/fpdf_render/render_int.h +++ b/core/fpdfapi/fpdf_render/render_int.h @@ -110,9 +110,8 @@ class CPDF_RenderStatus { FX_BOOL bLoadMask = FALSE); void RenderObjectList(const CPDF_PageObjectHolder* pObjectHolder, const CFX_Matrix* pObj2Device); - void RenderSingleObject(const CPDF_PageObject* pObj, - const CFX_Matrix* pObj2Device); - FX_BOOL ContinueSingleObject(const CPDF_PageObject* pObj, + void RenderSingleObject(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device); + FX_BOOL ContinueSingleObject(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, IFX_Pause* pPause); CPDF_RenderContext* GetContext() { return m_pContext; } @@ -132,26 +131,25 @@ class CPDF_RenderStatus { void ProcessClipPath(CPDF_ClipPath ClipPath, const CFX_Matrix* pObj2Device); void DrawClipPath(CPDF_ClipPath ClipPath, const CFX_Matrix* pObj2Device); - FX_BOOL ProcessTransparency(const CPDF_PageObject* PageObj, + FX_BOOL ProcessTransparency(CPDF_PageObject* PageObj, const CFX_Matrix* pObj2Device); - void ProcessObjectNoClip(const CPDF_PageObject* PageObj, + void ProcessObjectNoClip(CPDF_PageObject* PageObj, const CFX_Matrix* pObj2Device); - void DrawObjWithBackground(const CPDF_PageObject* pObj, + void DrawObjWithBackground(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device); - FX_BOOL DrawObjWithBlend(const CPDF_PageObject* pObj, + FX_BOOL DrawObjWithBlend(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device); - FX_BOOL ProcessPath(const CPDF_PathObject* pPathObj, - const CFX_Matrix* pObj2Device); - void ProcessPathPattern(const CPDF_PathObject* pPathObj, + FX_BOOL ProcessPath(CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device); + void ProcessPathPattern(CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, int& filltype, FX_BOOL& bStroke); - void DrawPathWithPattern(const CPDF_PathObject* pPathObj, + void DrawPathWithPattern(CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, const CPDF_Color* pColor, FX_BOOL bStroke); void DrawTilingPattern(CPDF_TilingPattern* pPattern, - const CPDF_PageObject* pPageObj, + CPDF_PageObject* pPageObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke); void DrawShadingPattern(CPDF_ShadingPattern* pPattern, @@ -161,7 +159,7 @@ class CPDF_RenderStatus { FX_BOOL SelectClipPath(const CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke); - FX_BOOL ProcessImage(const CPDF_ImageObject* pImageObj, + FX_BOOL ProcessImage(CPDF_ImageObject* pImageObj, const CFX_Matrix* pObj2Device); FX_BOOL OutputBitmapAlpha(CPDF_ImageObject* pImageObj, const CFX_Matrix* pImage2Device); @@ -187,9 +185,9 @@ class CPDF_RenderStatus { FX_RECT& clip_rect, int alpha, FX_BOOL bAlphaMode); - FX_BOOL ProcessType3Text(const CPDF_TextObject* textobj, + FX_BOOL ProcessType3Text(CPDF_TextObject* textobj, const CFX_Matrix* pObj2Device); - FX_BOOL ProcessText(const CPDF_TextObject* textobj, + FX_BOOL ProcessText(CPDF_TextObject* textobj, const CFX_Matrix* pObj2Device, CFX_PathData* pClippingPath); void DrawTextPathWithPattern(const CPDF_TextObject* textobj, @@ -214,9 +212,8 @@ class CPDF_RenderStatus { static CPDF_GraphicStates* CloneObjStates(const CPDF_GraphicStates* pPathObj, FX_BOOL bStroke); CPDF_TransferFunc* GetTransferFunc(CPDF_Object* pObject) const; - FX_ARGB GetFillArgb(const CPDF_PageObject* pObj, - FX_BOOL bType3 = FALSE) const; - FX_ARGB GetStrokeArgb(const CPDF_PageObject* pObj) const; + FX_ARGB GetFillArgb(CPDF_PageObject* pObj, FX_BOOL bType3 = FALSE) const; + FX_ARGB GetStrokeArgb(CPDF_PageObject* pObj) const; FX_BOOL GetObjectClippedRect(const CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, FX_BOOL bLogical, @@ -311,7 +308,7 @@ class CPDF_ImageRenderer { ~CPDF_ImageRenderer(); FX_BOOL Start(CPDF_RenderStatus* pStatus, - const CPDF_PageObject* pObj, + CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, FX_BOOL bStdCS, int blendType = FXDIB_BLEND_NORMAL); @@ -337,7 +334,7 @@ class CPDF_ImageRenderer { FX_BOOL DrawPatternImage(const CFX_Matrix* pObj2Device); CPDF_RenderStatus* m_pRenderStatus; - const CPDF_ImageObject* m_pImageObject; + CPDF_ImageObject* m_pImageObject; int m_Status; const CFX_Matrix* m_pObj2Device; CFX_Matrix m_ImageMatrix; |