| Index: core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
 | 
| diff --git a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
 | 
| index e34801f534b721f2edcd16e149a80c1296d7fc5d..601cf0cebcfa2d9883824bb395b84edad47fe8f1 100644
 | 
| --- a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
 | 
| +++ b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
 | 
| @@ -6,6 +6,9 @@
 | 
|  
 | 
|  #include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h"
 | 
|  
 | 
| +#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
 | 
| +#include "core/fpdfapi/fpdf_render/render_int.h"
 | 
| +
 | 
|  namespace {
 | 
|  
 | 
|  int RI_StringToId(const CFX_ByteString& ri) {
 | 
| @@ -22,6 +25,45 @@ int RI_StringToId(const CFX_ByteString& ri) {
 | 
|    return 0;
 | 
|  }
 | 
|  
 | 
| +int GetBlendTypeInternal(const CFX_ByteString& mode) {
 | 
| +  switch (mode.GetID()) {
 | 
| +    case FXBSTR_ID('N', 'o', 'r', 'm'):
 | 
| +    case FXBSTR_ID('C', 'o', 'm', 'p'):
 | 
| +      return FXDIB_BLEND_NORMAL;
 | 
| +    case FXBSTR_ID('M', 'u', 'l', 't'):
 | 
| +      return FXDIB_BLEND_MULTIPLY;
 | 
| +    case FXBSTR_ID('S', 'c', 'r', 'e'):
 | 
| +      return FXDIB_BLEND_SCREEN;
 | 
| +    case FXBSTR_ID('O', 'v', 'e', 'r'):
 | 
| +      return FXDIB_BLEND_OVERLAY;
 | 
| +    case FXBSTR_ID('D', 'a', 'r', 'k'):
 | 
| +      return FXDIB_BLEND_DARKEN;
 | 
| +    case FXBSTR_ID('L', 'i', 'g', 'h'):
 | 
| +      return FXDIB_BLEND_LIGHTEN;
 | 
| +    case FXBSTR_ID('C', 'o', 'l', 'o'):
 | 
| +      if (mode.GetLength() == 10)
 | 
| +        return FXDIB_BLEND_COLORDODGE;
 | 
| +      if (mode.GetLength() == 9)
 | 
| +        return FXDIB_BLEND_COLORBURN;
 | 
| +      return FXDIB_BLEND_COLOR;
 | 
| +    case FXBSTR_ID('H', 'a', 'r', 'd'):
 | 
| +      return FXDIB_BLEND_HARDLIGHT;
 | 
| +    case FXBSTR_ID('S', 'o', 'f', 't'):
 | 
| +      return FXDIB_BLEND_SOFTLIGHT;
 | 
| +    case FXBSTR_ID('D', 'i', 'f', 'f'):
 | 
| +      return FXDIB_BLEND_DIFFERENCE;
 | 
| +    case FXBSTR_ID('E', 'x', 'c', 'l'):
 | 
| +      return FXDIB_BLEND_EXCLUSION;
 | 
| +    case FXBSTR_ID('H', 'u', 'e', 0):
 | 
| +      return FXDIB_BLEND_HUE;
 | 
| +    case FXBSTR_ID('S', 'a', 't', 'u'):
 | 
| +      return FXDIB_BLEND_SATURATION;
 | 
| +    case FXBSTR_ID('L', 'u', 'm', 'i'):
 | 
| +      return FXDIB_BLEND_LUMINOSITY;
 | 
| +  }
 | 
| +  return FXDIB_BLEND_NORMAL;
 | 
| +}
 | 
| +
 | 
|  }  // namespace
 | 
|  
 | 
|  CPDF_GeneralState::CPDF_GeneralState() {}
 | 
| @@ -36,7 +78,7 @@ void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) {
 | 
|  }
 | 
|  
 | 
|  int CPDF_GeneralState::GetBlendType() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData ? pData->m_BlendType : FXDIB_BLEND_NORMAL;
 | 
|  }
 | 
|  
 | 
| @@ -45,7 +87,7 @@ void CPDF_GeneralState::SetBlendType(int type) {
 | 
|  }
 | 
|  
 | 
|  FX_FLOAT CPDF_GeneralState::GetFillAlpha() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData ? pData->m_FillAlpha : 1.0f;
 | 
|  }
 | 
|  
 | 
| @@ -54,7 +96,7 @@ void CPDF_GeneralState::SetFillAlpha(FX_FLOAT alpha) {
 | 
|  }
 | 
|  
 | 
|  FX_FLOAT CPDF_GeneralState::GetStrokeAlpha() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData ? pData->m_StrokeAlpha : 1.0f;
 | 
|  }
 | 
|  
 | 
| @@ -63,7 +105,7 @@ void CPDF_GeneralState::SetStrokeAlpha(FX_FLOAT alpha) {
 | 
|  }
 | 
|  
 | 
|  CPDF_Object* CPDF_GeneralState::GetSoftMask() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData ? pData->m_pSoftMask : nullptr;
 | 
|  }
 | 
|  
 | 
| @@ -72,7 +114,7 @@ void CPDF_GeneralState::SetSoftMask(CPDF_Object* pObject) {
 | 
|  }
 | 
|  
 | 
|  CPDF_Object* CPDF_GeneralState::GetTR() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData ? pData->m_pTR : nullptr;
 | 
|  }
 | 
|  
 | 
| @@ -81,7 +123,7 @@ void CPDF_GeneralState::SetTR(CPDF_Object* pObject) {
 | 
|  }
 | 
|  
 | 
|  CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData ? pData->m_pTransferFunc : nullptr;
 | 
|  }
 | 
|  
 | 
| @@ -89,21 +131,23 @@ 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);
 | 
| +void CPDF_GeneralState::SetBlendMode(const CFX_ByteString& mode) {
 | 
| +  StateData* pData = m_Ref.GetPrivateCopy();
 | 
| +  pData->m_BlendMode = mode;
 | 
| +  pData->m_BlendType = GetBlendTypeInternal(mode);
 | 
|  }
 | 
|  
 | 
| -const FX_FLOAT* CPDF_GeneralState::GetSMaskMatrix() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| -  return pData ? pData->m_SMaskMatrix : nullptr;
 | 
| +const CFX_Matrix* CPDF_GeneralState::GetSMaskMatrix() const {
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
| +  return pData ? &pData->m_SMaskMatrix : nullptr;
 | 
|  }
 | 
|  
 | 
| -FX_FLOAT* CPDF_GeneralState::GetMutableSMaskMatrix() {
 | 
| -  return m_Ref.GetPrivateCopy()->m_SMaskMatrix;
 | 
| +void CPDF_GeneralState::SetSMaskMatrix(const CFX_Matrix& matrix) {
 | 
| +  m_Ref.GetPrivateCopy()->m_SMaskMatrix = matrix;
 | 
|  }
 | 
|  
 | 
|  bool CPDF_GeneralState::GetFillOP() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData && pData->m_FillOP;
 | 
|  }
 | 
|  
 | 
| @@ -116,7 +160,7 @@ void CPDF_GeneralState::SetStrokeOP(bool op) {
 | 
|  }
 | 
|  
 | 
|  bool CPDF_GeneralState::GetStrokeOP() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData && pData->m_StrokeOP;
 | 
|  }
 | 
|  
 | 
| @@ -149,7 +193,7 @@ void CPDF_GeneralState::SetSmoothness(FX_FLOAT smoothness) {
 | 
|  }
 | 
|  
 | 
|  bool CPDF_GeneralState::GetStrokeAdjust() const {
 | 
| -  const CPDF_GeneralStateData* pData = m_Ref.GetObject();
 | 
| +  const StateData* pData = m_Ref.GetObject();
 | 
|    return pData && pData->m_StrokeAdjust;
 | 
|  }
 | 
|  
 | 
| @@ -172,3 +216,66 @@ void CPDF_GeneralState::SetMatrix(const CFX_Matrix& matrix) {
 | 
|  CFX_Matrix* CPDF_GeneralState::GetMutableMatrix() {
 | 
|    return &m_Ref.GetPrivateCopy()->m_Matrix;
 | 
|  }
 | 
| +
 | 
| +CPDF_GeneralState::StateData::StateData()
 | 
| +    : m_BlendMode("Normal"),
 | 
| +      m_BlendType(0),
 | 
| +      m_pSoftMask(nullptr),
 | 
| +      m_StrokeAlpha(1.0),
 | 
| +      m_FillAlpha(1.0f),
 | 
| +      m_pTR(nullptr),
 | 
| +      m_pTransferFunc(nullptr),
 | 
| +      m_RenderIntent(0),
 | 
| +      m_StrokeAdjust(false),
 | 
| +      m_AlphaSource(false),
 | 
| +      m_TextKnockout(false),
 | 
| +      m_StrokeOP(false),
 | 
| +      m_FillOP(false),
 | 
| +      m_OPMode(0),
 | 
| +      m_pBG(nullptr),
 | 
| +      m_pUCR(nullptr),
 | 
| +      m_pHT(nullptr),
 | 
| +      m_Flatness(1.0f),
 | 
| +      m_Smoothness(0.0f) {
 | 
| +  m_SMaskMatrix.SetIdentity();
 | 
| +  m_Matrix.SetIdentity();
 | 
| +}
 | 
| +
 | 
| +CPDF_GeneralState::StateData::StateData(const StateData& that)
 | 
| +    : m_BlendMode(that.m_BlendMode),
 | 
| +      m_BlendType(that.m_BlendType),
 | 
| +      m_pSoftMask(that.m_pSoftMask),
 | 
| +      m_StrokeAlpha(that.m_StrokeAlpha),
 | 
| +      m_FillAlpha(that.m_FillAlpha),
 | 
| +      m_pTR(that.m_pTR),
 | 
| +      m_pTransferFunc(that.m_pTransferFunc),
 | 
| +      m_RenderIntent(that.m_RenderIntent),
 | 
| +      m_StrokeAdjust(that.m_StrokeAdjust),
 | 
| +      m_AlphaSource(that.m_AlphaSource),
 | 
| +      m_TextKnockout(that.m_TextKnockout),
 | 
| +      m_StrokeOP(that.m_StrokeOP),
 | 
| +      m_FillOP(that.m_FillOP),
 | 
| +      m_OPMode(that.m_OPMode),
 | 
| +      m_pBG(that.m_pBG),
 | 
| +      m_pUCR(that.m_pUCR),
 | 
| +      m_pHT(that.m_pHT),
 | 
| +      m_Flatness(that.m_Flatness),
 | 
| +      m_Smoothness(that.m_Smoothness) {
 | 
| +  m_Matrix = that.m_Matrix;
 | 
| +  m_SMaskMatrix = that.m_SMaskMatrix;
 | 
| +
 | 
| +  if (that.m_pTransferFunc && that.m_pTransferFunc->m_pPDFDoc) {
 | 
| +    CPDF_DocRenderData* pDocCache =
 | 
| +        that.m_pTransferFunc->m_pPDFDoc->GetRenderData();
 | 
| +    if (pDocCache)
 | 
| +      m_pTransferFunc = pDocCache->GetTransferFunc(m_pTR);
 | 
| +  }
 | 
| +}
 | 
| +
 | 
| +CPDF_GeneralState::StateData::~StateData() {
 | 
| +  if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) {
 | 
| +    CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData();
 | 
| +    if (pDocCache)
 | 
| +      pDocCache->ReleaseTransferFunc(m_pTR);
 | 
| +  }
 | 
| +}
 | 
| 
 |