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 
CPDF_TilingPattern(CPDF_Document * pDoc,CPDF_Object * pPatternObj,const CFX_Matrix & parentMatrix)15 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc,
16                                        CPDF_Object* pPatternObj,
17                                        const CFX_Matrix& parentMatrix)
18     : CPDF_Pattern(pDoc, pPatternObj, parentMatrix) {
19   assert(document());
20   m_bColored = pattern_obj()->GetDict()->GetIntegerFor("PaintType") == 1;
21   SetPatternToFormMatrix();
22 }
23 
~CPDF_TilingPattern()24 CPDF_TilingPattern::~CPDF_TilingPattern() {}
25 
AsTilingPattern()26 CPDF_TilingPattern* CPDF_TilingPattern::AsTilingPattern() {
27   return this;
28 }
29 
AsShadingPattern()30 CPDF_ShadingPattern* CPDF_TilingPattern::AsShadingPattern() {
31   return nullptr;
32 }
33 
Load()34 bool CPDF_TilingPattern::Load() {
35   if (m_pForm)
36     return true;
37 
38   CPDF_Dictionary* pDict = pattern_obj()->GetDict();
39   if (!pDict)
40     return false;
41 
42   m_bColored = pDict->GetIntegerFor("PaintType") == 1;
43   m_XStep = static_cast<float>(fabs(pDict->GetNumberFor("XStep")));
44   m_YStep = static_cast<float>(fabs(pDict->GetNumberFor("YStep")));
45 
46   CPDF_Stream* pStream = pattern_obj()->AsStream();
47   if (!pStream)
48     return false;
49 
50   const CFX_Matrix& matrix = parent_matrix();
51   m_pForm = pdfium::MakeUnique<CPDF_Form>(document(), nullptr, pStream);
52   m_pForm->ParseContentWithParams(nullptr, &matrix, nullptr, 0);
53   m_BBox = pDict->GetRectFor("BBox");
54   return true;
55 }
56