| OLD | NEW | 
|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 
| 6 | 6 | 
| 7 #include "pageint.h" | 7 #include "pageint.h" | 
| 8 | 8 | 
| 9 #include "core/include/fpdfapi/fpdf_page.h" | 9 #include "core/include/fpdfapi/fpdf_page.h" | 
| 10 | 10 | 
| 11 namespace { | 11 namespace { | 
| 12 | 12 | 
| 13 const int kSingleCoordinatePair = 1; | 13 const int kSingleCoordinatePair = 1; | 
| 14 const int kTensorCoordinatePairs = 16; | 14 const int kTensorCoordinatePairs = 16; | 
| 15 const int kCoonsCoordinatePairs = 12; | 15 const int kCoonsCoordinatePairs = 12; | 
| 16 | 16 | 
| 17 const int kSingleColorPerPatch = 1; | 17 const int kSingleColorPerPatch = 1; | 
| 18 const int kQuadColorsPerPatch = 4; | 18 const int kQuadColorsPerPatch = 4; | 
| 19 | 19 | 
| 20 ShadingType ToShadingType(int type) { | 20 ShadingType ToShadingType(int type) { | 
| 21   return (type > static_cast<int>(kInvalidShading) && | 21   return (type > static_cast<int>(kInvalidShading) && | 
| 22           type < static_cast<int>(kMaxShading)) | 22           type < static_cast<int>(kMaxShading)) | 
| 23              ? static_cast<ShadingType>(type) | 23              ? static_cast<ShadingType>(type) | 
| 24              : kInvalidShading; | 24              : kInvalidShading; | 
| 25 } | 25 } | 
| 26 | 26 | 
| 27 }  // namespace | 27 }  // namespace | 
| 28 | 28 | 
| 29 CPDF_Pattern::CPDF_Pattern(const CFX_Matrix* pParentMatrix) | 29 CPDF_Pattern::CPDF_Pattern(PatternType type, | 
| 30     : m_pPatternObj(NULL), | 30                            CPDF_Document* pDoc, | 
| 31       m_PatternType(PATTERN_TILING), | 31                            CPDF_Object* pObj, | 
| 32       m_pDocument(NULL), | 32                            const CFX_Matrix* pParentMatrix) | 
|  | 33     : m_PatternType(type), | 
|  | 34       m_pDocument(pDoc), | 
|  | 35       m_pPatternObj(pObj), | 
| 33       m_bForceClear(FALSE) { | 36       m_bForceClear(FALSE) { | 
| 34   if (pParentMatrix) { | 37   if (pParentMatrix) | 
| 35     m_ParentMatrix = *pParentMatrix; | 38     m_ParentMatrix = *pParentMatrix; | 
| 36   } |  | 
| 37 } | 39 } | 
| 38 CPDF_Pattern::~CPDF_Pattern() {} | 40 CPDF_Pattern::~CPDF_Pattern() {} | 
| 39 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, | 41 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, | 
| 40                                        CPDF_Object* pPatternObj, | 42                                        CPDF_Object* pPatternObj, | 
| 41                                        const CFX_Matrix* parentMatrix) | 43                                        const CFX_Matrix* parentMatrix) | 
| 42     : CPDF_Pattern(parentMatrix) { | 44     : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { | 
| 43   m_PatternType = PATTERN_TILING; |  | 
| 44   m_pPatternObj = pPatternObj; |  | 
| 45   m_pDocument = pDoc; |  | 
| 46   CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 45   CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 
| 47   ASSERT(pDict); |  | 
| 48   m_Pattern2Form = pDict->GetMatrix("Matrix"); | 46   m_Pattern2Form = pDict->GetMatrix("Matrix"); | 
| 49   m_bColored = pDict->GetInteger("PaintType") == 1; | 47   m_bColored = pDict->GetInteger("PaintType") == 1; | 
| 50   if (parentMatrix) { | 48   if (parentMatrix) { | 
| 51     m_Pattern2Form.Concat(*parentMatrix); | 49     m_Pattern2Form.Concat(*parentMatrix); | 
| 52   } | 50   } | 
| 53   m_pForm = NULL; | 51   m_pForm = NULL; | 
| 54 } | 52 } | 
| 55 CPDF_TilingPattern::~CPDF_TilingPattern() { | 53 CPDF_TilingPattern::~CPDF_TilingPattern() { | 
| 56   delete m_pForm; | 54   delete m_pForm; | 
| 57   m_pForm = NULL; | 55   m_pForm = NULL; | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 74 | 72 | 
| 75   m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); | 73   m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); | 
| 76   m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); | 74   m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); | 
| 77   m_BBox = pDict->GetRect("BBox"); | 75   m_BBox = pDict->GetRect("BBox"); | 
| 78   return TRUE; | 76   return TRUE; | 
| 79 } | 77 } | 
| 80 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, | 78 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, | 
| 81                                          CPDF_Object* pPatternObj, | 79                                          CPDF_Object* pPatternObj, | 
| 82                                          FX_BOOL bShading, | 80                                          FX_BOOL bShading, | 
| 83                                          const CFX_Matrix* parentMatrix) | 81                                          const CFX_Matrix* parentMatrix) | 
| 84     : CPDF_Pattern(parentMatrix) { | 82     : CPDF_Pattern(SHADING, | 
| 85   m_PatternType = PATTERN_SHADING; | 83                    pDoc, | 
| 86   m_pPatternObj = bShading ? NULL : pPatternObj; | 84                    bShading ? nullptr : pPatternObj, | 
| 87   m_pDocument = pDoc; | 85                    parentMatrix), | 
| 88   m_bShadingObj = bShading; | 86       m_ShadingType(kInvalidShading), | 
|  | 87       m_bShadingObj(bShading), | 
|  | 88       m_pShadingObj(pPatternObj), | 
|  | 89       m_pCS(nullptr), | 
|  | 90       m_pCountedCS(nullptr), | 
|  | 91       m_nFuncs(0) { | 
| 89   if (!bShading) { | 92   if (!bShading) { | 
| 90     CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 93     CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 
| 91     ASSERT(pDict); |  | 
| 92     m_Pattern2Form = pDict->GetMatrix("Matrix"); | 94     m_Pattern2Form = pDict->GetMatrix("Matrix"); | 
| 93     m_pShadingObj = pDict->GetElementValue("Shading"); | 95     m_pShadingObj = pDict->GetElementValue("Shading"); | 
| 94     if (parentMatrix) { | 96     if (parentMatrix) | 
| 95       m_Pattern2Form.Concat(*parentMatrix); | 97       m_Pattern2Form.Concat(*parentMatrix); | 
| 96     } |  | 
| 97   } else { |  | 
| 98     m_pShadingObj = pPatternObj; |  | 
| 99   } | 98   } | 
| 100   m_ShadingType = kInvalidShading; | 99   for (int i = 0; i < FX_ArraySize(m_pFunctions); ++i) | 
| 101   m_pCS = NULL; | 100     m_pFunctions[i] = nullptr; | 
| 102   m_nFuncs = 0; |  | 
| 103   for (int i = 0; i < 4; i++) { |  | 
| 104     m_pFunctions[i] = NULL; |  | 
| 105   } |  | 
| 106   m_pCountedCS = NULL; |  | 
| 107 } | 101 } | 
|  | 102 | 
| 108 CPDF_ShadingPattern::~CPDF_ShadingPattern() { | 103 CPDF_ShadingPattern::~CPDF_ShadingPattern() { | 
| 109   Clear(); | 104   for (int i = 0; i < m_nFuncs; ++i) | 
| 110 } |  | 
| 111 void CPDF_ShadingPattern::Clear() { |  | 
| 112   for (int i = 0; i < m_nFuncs; i++) { |  | 
| 113     delete m_pFunctions[i]; | 105     delete m_pFunctions[i]; | 
| 114     m_pFunctions[i] = NULL; | 106 | 
| 115   } |  | 
| 116   CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; | 107   CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; | 
| 117   if (pCS && m_pDocument) { | 108   if (pCS && m_pDocument) | 
| 118     m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); | 109     m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); | 
| 119   } |  | 
| 120   m_ShadingType = kInvalidShading; |  | 
| 121   m_pCS = NULL; |  | 
| 122   m_pCountedCS = NULL; |  | 
| 123   m_nFuncs = 0; |  | 
| 124 } | 110 } | 
| 125 | 111 | 
| 126 FX_BOOL CPDF_ShadingPattern::Load() { | 112 FX_BOOL CPDF_ShadingPattern::Load() { | 
| 127   if (m_ShadingType != kInvalidShading) | 113   if (m_ShadingType != kInvalidShading) | 
| 128     return TRUE; | 114     return TRUE; | 
| 129 | 115 | 
| 130   CPDF_Dictionary* pShadingDict = | 116   CPDF_Dictionary* pShadingDict = | 
| 131       m_pShadingObj ? m_pShadingObj->GetDict() : NULL; | 117       m_pShadingObj ? m_pShadingObj->GetDict() : NULL; | 
| 132   if (!pShadingDict) { | 118   if (!pShadingDict) { | 
| 133     return FALSE; | 119     return FALSE; | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 161   } | 147   } | 
| 162 | 148 | 
| 163   m_ShadingType = ToShadingType(pShadingDict->GetInteger("ShadingType")); | 149   m_ShadingType = ToShadingType(pShadingDict->GetInteger("ShadingType")); | 
| 164 | 150 | 
| 165   // We expect to have a stream if our shading type is a mesh. | 151   // We expect to have a stream if our shading type is a mesh. | 
| 166   if (IsMeshShading() && !ToStream(m_pShadingObj)) | 152   if (IsMeshShading() && !ToStream(m_pShadingObj)) | 
| 167     return FALSE; | 153     return FALSE; | 
| 168 | 154 | 
| 169   return TRUE; | 155   return TRUE; | 
| 170 } | 156 } | 
| 171 FX_BOOL CPDF_ShadingPattern::Reload() { |  | 
| 172   Clear(); |  | 
| 173   return Load(); |  | 
| 174 } |  | 
| 175 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, | 157 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, | 
| 176                               CPDF_Function** pFuncs, | 158                               CPDF_Function** pFuncs, | 
| 177                               int nFuncs, | 159                               int nFuncs, | 
| 178                               CPDF_ColorSpace* pCS) { | 160                               CPDF_ColorSpace* pCS) { | 
| 179   m_Stream.LoadAllData(pShadingStream); | 161   m_Stream.LoadAllData(pShadingStream); | 
| 180   m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); | 162   m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); | 
| 181   m_pFuncs = pFuncs; | 163   m_pFuncs = pFuncs; | 
| 182   m_nFuncs = nFuncs; | 164   m_nFuncs = nFuncs; | 
| 183   m_pCS = pCS; | 165   m_pCS = pCS; | 
| 184   CPDF_Dictionary* pDict = pShadingStream->GetDict(); | 166   CPDF_Dictionary* pDict = pShadingStream->GetDict(); | 
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 324       } | 306       } | 
| 325     } | 307     } | 
| 326     stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * | 308     stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * | 
| 327                                 color_count); | 309                                 color_count); | 
| 328     if (bGouraud) | 310     if (bGouraud) | 
| 329       stream.m_BitStream.ByteAlign(); | 311       stream.m_BitStream.ByteAlign(); | 
| 330   } | 312   } | 
| 331   rect.Transform(pMatrix); | 313   rect.Transform(pMatrix); | 
| 332   return rect; | 314   return rect; | 
| 333 } | 315 } | 
| OLD | NEW | 
|---|