blob: 7c1716dc01c0e9a06a9e3d27547e977341148a1b [file] [log] [blame]
dan sinclair61b2fc72016-03-23 19:21:44 -04001// 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/fpdf_page/cpdf_tilingpattern.h"
8
9#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
10#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
11#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
12#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
13
14CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc,
15 CPDF_Object* pPatternObj,
thestig12168d72016-04-26 22:41:36 -070016 const CFX_Matrix& parentMatrix)
dan sinclair61b2fc72016-03-23 19:21:44 -040017 : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) {
18 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
dsinclair38fd8442016-09-15 10:15:32 -070019 m_Pattern2Form = pDict->GetMatrixFor("Matrix");
20 m_bColored = pDict->GetIntegerFor("PaintType") == 1;
thestig12168d72016-04-26 22:41:36 -070021 m_Pattern2Form.Concat(parentMatrix);
dan sinclair61b2fc72016-03-23 19:21:44 -040022}
23
24CPDF_TilingPattern::~CPDF_TilingPattern() {
dan sinclair61b2fc72016-03-23 19:21:44 -040025}
26
weili868150b2016-06-13 14:57:29 -070027CPDF_TilingPattern* CPDF_TilingPattern::AsTilingPattern() {
28 return this;
29}
30
31CPDF_ShadingPattern* CPDF_TilingPattern::AsShadingPattern() {
32 return nullptr;
33}
34
dan sinclair61b2fc72016-03-23 19:21:44 -040035FX_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
dsinclair38fd8442016-09-15 10:15:32 -070043 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"));
dan sinclair61b2fc72016-03-23 19:21:44 -040046
47 CPDF_Stream* pStream = m_pPatternObj->AsStream();
48 if (!pStream)
49 return FALSE;
50
thestig5cc24652016-04-26 11:46:02 -070051 m_pForm.reset(new CPDF_Form(m_pDocument, nullptr, pStream));
52 m_pForm->ParseContent(nullptr, &m_ParentMatrix, nullptr);
dsinclair38fd8442016-09-15 10:15:32 -070053 m_BBox = pDict->GetRectFor("BBox");
dan sinclair61b2fc72016-03-23 19:21:44 -040054 return TRUE;
55}