Change the forced clear order of CPDF_DocPageData::Clear, and remove m_pDocument...
authorBo Xu <bo_xu@foxitsoftware.com>
Wed, 10 Sep 2014 01:39:30 +0000 (18:39 -0700)
committerBo Xu <bo_xu@foxitsoftware.com>
Wed, 10 Sep 2014 01:39:30 +0000 (18:39 -0700)
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

core/include/fpdfapi/fpdf_resource.h
core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp

index 92c4872..a7a6444 100644 (file)
@@ -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
index db384a7..c522dcd 100644 (file)
@@ -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);
         }
     }
 }
index 16f0a9c..131edbe 100644 (file)
@@ -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)
 {