1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "core/fpdfapi/page/cpdf_tilingpattern.h" 8 9 #include "core/fpdfapi/page/cpdf_form.h" 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" 11 #include "core/fpdfapi/parser/cpdf_object.h" 12 #include "core/fpdfapi/parser/cpdf_stream.h" 13 #include "third_party/base/ptr_util.h" 14 15 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, 16 CPDF_Object* pPatternObj, 17 const CFX_Matrix& parentMatrix) 18 : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { 19 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 20 m_Pattern2Form = pDict->GetMatrixFor("Matrix"); 21 m_bColored = pDict->GetIntegerFor("PaintType") == 1; 22 m_Pattern2Form.Concat(parentMatrix); 23 } 24 25 CPDF_TilingPattern::~CPDF_TilingPattern() {} 26 27 CPDF_TilingPattern* CPDF_TilingPattern::AsTilingPattern() { 28 return this; 29 } 30 31 CPDF_ShadingPattern* CPDF_TilingPattern::AsShadingPattern() { 32 return nullptr; 33 } 34 35 bool CPDF_TilingPattern::Load() { 36 if (m_pForm) 37 return true; 38 39 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 40 if (!pDict) 41 return false; 42 43 m_bColored = pDict->GetIntegerFor("PaintType") == 1; 44 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberFor("XStep")); 45 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberFor("YStep")); 46 47 CPDF_Stream* pStream = m_pPatternObj->AsStream(); 48 if (!pStream) 49 return false; 50 51 m_pForm = pdfium::MakeUnique<CPDF_Form>(m_pDocument, nullptr, pStream); 52 m_pForm->ParseContent(nullptr, &m_ParentMatrix, nullptr); 53 m_BBox = pDict->GetRectFor("BBox"); 54 return true; 55 } 56