xref: /aosp_15_r20/external/pdfium/core/fpdfapi/page/cpdf_tilingpattern.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2016 The PDFium Authors
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 <math.h>
10 
11 #include <utility>
12 
13 #include "core/fpdfapi/page/cpdf_allstates.h"
14 #include "core/fpdfapi/page/cpdf_form.h"
15 #include "core/fpdfapi/page/cpdf_pageobject.h"
16 #include "core/fpdfapi/parser/cpdf_dictionary.h"
17 #include "core/fpdfapi/parser/cpdf_object.h"
18 #include "core/fpdfapi/parser/cpdf_stream.h"
19 #include "third_party/base/check.h"
20 
CPDF_TilingPattern(CPDF_Document * pDoc,RetainPtr<CPDF_Object> pPatternObj,const CFX_Matrix & parentMatrix)21 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc,
22                                        RetainPtr<CPDF_Object> pPatternObj,
23                                        const CFX_Matrix& parentMatrix)
24     : CPDF_Pattern(pDoc, std::move(pPatternObj), parentMatrix) {
25   DCHECK(document());
26   m_bColored = pattern_obj()->GetDict()->GetIntegerFor("PaintType") == 1;
27   SetPatternToFormMatrix();
28 }
29 
30 CPDF_TilingPattern::~CPDF_TilingPattern() = default;
31 
AsTilingPattern()32 CPDF_TilingPattern* CPDF_TilingPattern::AsTilingPattern() {
33   return this;
34 }
35 
Load(CPDF_PageObject * pPageObj)36 std::unique_ptr<CPDF_Form> CPDF_TilingPattern::Load(CPDF_PageObject* pPageObj) {
37   RetainPtr<const CPDF_Dictionary> pDict = pattern_obj()->GetDict();
38   m_bColored = pDict->GetIntegerFor("PaintType") == 1;
39   m_XStep = fabsf(pDict->GetFloatFor("XStep"));
40   m_YStep = fabsf(pDict->GetFloatFor("YStep"));
41 
42   RetainPtr<CPDF_Stream> pStream = ToStream(pattern_obj());
43   if (!pStream)
44     return nullptr;
45 
46   const CFX_Matrix& matrix = parent_matrix();
47   auto form =
48       std::make_unique<CPDF_Form>(document(), nullptr, std::move(pStream));
49 
50   CPDF_AllStates allStates;
51   allStates.m_ColorState.Emplace();
52   allStates.m_GraphState.Emplace();
53   allStates.m_TextState.Emplace();
54   allStates.m_GeneralState = pPageObj->m_GeneralState;
55   form->ParseContent(&allStates, &matrix, nullptr);
56   m_BBox = pDict->GetRectFor("BBox");
57   return form;
58 }
59