diff options
author | Bo Xu <bo_xu@foxitsoftware.com> | 2014-09-09 18:39:30 -0700 |
---|---|---|
committer | Bo Xu <bo_xu@foxitsoftware.com> | 2014-09-09 18:39:30 -0700 |
commit | 9175beec2686231fe284e8c8095d04668817509b (patch) | |
tree | e8956fbb7dd070c405a4586ca54b69d6c2caf6ef | |
parent | 663af999d721f86e828a87354c380b76d146cedf (diff) | |
download | pdfium-9175beec2686231fe284e8c8095d04668817509b.tar.xz |
Change the forced clear order of CPDF_DocPageData::Clear, and remove m_pDocument in CPDF_Color
If not forced clear, the counter of CPDF_Pattern will take care the count of referenced instance.
When forced clear, clear color first to make sure pattern still exists when referencing it.
BUG=411154
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/554913003
-rw-r--r-- | core/include/fpdfapi/fpdf_resource.h | 3 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 19 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 22 |
3 files changed, 20 insertions, 24 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h index 92c4872537..a7a644435e 100644 --- a/core/include/fpdfapi/fpdf_resource.h +++ b/core/include/fpdfapi/fpdf_resource.h @@ -680,7 +680,7 @@ class CPDF_Color : public CFX_Object { public: - CPDF_Color() :m_pCS(NULL), m_pBuffer(NULL), m_pDocument(NULL) + CPDF_Color() :m_pCS(NULL), m_pBuffer(NULL) { } @@ -722,7 +722,6 @@ protected: void ReleaseBuffer(); void ReleaseColorSpace(); FX_FLOAT* m_pBuffer; - CPDF_Document* m_pDocument; }; #define PATTERN_TILING 1 #define PATTERN_SHADING 2 diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index db384a7d8f..c522dcdc84 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -1292,8 +1292,8 @@ void CPDF_Color::ReleaseBuffer() if (m_pCS->GetFamily() == PDFCS_PATTERN) { PatternValue* pvalue = (PatternValue*)m_pBuffer; CPDF_Pattern* pPattern = pvalue->m_pPattern; - if (pPattern && m_pDocument) { - CPDF_DocPageData *pPageData = m_pDocument->GetPageData(); + if (pPattern && pPattern->m_pDocument) { + CPDF_DocPageData *pPageData = pPattern->m_pDocument->GetPageData(); if (pPageData && !pPageData->IsForceClear()) { pPageData->ReleasePattern(pPattern->m_pPatternObj); } @@ -1304,10 +1304,9 @@ void CPDF_Color::ReleaseBuffer() } void CPDF_Color::ReleaseColorSpace() { - if (m_pDocument && m_pCS && m_pCS->GetArray()) { - m_pDocument->GetPageData()->ReleaseColorSpace(m_pCS->GetArray()); + if (m_pCS && m_pCS->m_pDocument && m_pCS->GetArray()) { + m_pCS->m_pDocument->GetPageData()->ReleaseColorSpace(m_pCS->GetArray()); m_pCS = NULL; - m_pDocument = NULL; } } void CPDF_Color::SetColorSpace(CPDF_ColorSpace* pCS) @@ -1318,13 +1317,11 @@ void CPDF_Color::SetColorSpace(CPDF_ColorSpace* pCS) } ReleaseColorSpace(); m_pCS = pCS; - m_pDocument = pCS->m_pDocument; return; } ReleaseBuffer(); ReleaseColorSpace(); m_pCS = pCS; - m_pDocument = pCS->m_pDocument; if (m_pCS) { m_pBuffer = pCS->CreateBuf(); pCS->GetDefaultColor(m_pBuffer); @@ -1352,8 +1349,8 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) m_pBuffer = m_pCS->CreateBuf(); } PatternValue* pvalue = (PatternValue*)m_pBuffer; - if (pvalue->m_pPattern && m_pDocument) { - CPDF_DocPageData *pDocPageData = m_pDocument->GetPageData(); + if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) { + CPDF_DocPageData *pDocPageData = pvalue->m_pPattern->m_pDocument->GetPageData(); if (pDocPageData && !pDocPageData->IsForceClear()) { pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj); } @@ -1382,8 +1379,8 @@ void CPDF_Color::Copy(const CPDF_Color* pSrc) FXSYS_memcpy32(m_pBuffer, pSrc->m_pBuffer, m_pCS->GetBufSize()); if (m_pCS->GetFamily() == PDFCS_PATTERN) { PatternValue* pvalue = (PatternValue*)m_pBuffer; - if (pvalue->m_pPattern && m_pDocument) { - pvalue->m_pPattern = m_pDocument->GetPageData()->GetPattern(pvalue->m_pPattern->m_pPatternObj, FALSE, &pvalue->m_pPattern->m_ParentMatrix); + if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) { + pvalue->m_pPattern = pvalue->m_pPattern->m_pDocument->GetPageData()->GetPattern(pvalue->m_pPattern->m_pPatternObj, FALSE, &pvalue->m_pPattern->m_ParentMatrix); } } } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index 16f0a9cfad..131edbe9b5 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -154,17 +154,6 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) FX_DWORD nCount; m_bForceClear = bForceRelease; - pos = m_PatternMap.GetStartPosition(); - while (pos) { - CPDF_Object* ptObj; - CPDF_CountedObject<CPDF_Pattern*>* ptData; - m_PatternMap.GetNextAssoc(pos, ptObj, ptData); - nCount = ptData->m_nCount; - if (bForceRelease || nCount < 2) { - delete ptData->m_Obj; - ptData->m_Obj = NULL; - } - } pos = m_FontMap.GetStartPosition(); while (pos) { CPDF_Dictionary* fontDict; @@ -233,6 +222,17 @@ void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) m_FontFileMap.RemoveKey(ftKey); } } + pos = m_PatternMap.GetStartPosition(); + while (pos) { + CPDF_Object* ptObj; + CPDF_CountedObject<CPDF_Pattern*>* ptData; + m_PatternMap.GetNextAssoc(pos, ptObj, ptData); + nCount = ptData->m_nCount; + if (bForceRelease || nCount < 2) { + delete ptData->m_Obj; + ptData->m_Obj = NULL; + } + } } CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnly) { |