dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 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/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 | |
| 14 | CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, |
| 15 | CPDF_Object* pPatternObj, |
thestig | 12168d7 | 2016-04-26 22:41:36 -0700 | [diff] [blame] | 16 | const CFX_Matrix& parentMatrix) |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 17 | : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { |
| 18 | CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 19 | m_Pattern2Form = pDict->GetMatrixFor("Matrix"); |
| 20 | m_bColored = pDict->GetIntegerFor("PaintType") == 1; |
thestig | 12168d7 | 2016-04-26 22:41:36 -0700 | [diff] [blame] | 21 | m_Pattern2Form.Concat(parentMatrix); |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | CPDF_TilingPattern::~CPDF_TilingPattern() { |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 25 | } |
| 26 | |
weili | 868150b | 2016-06-13 14:57:29 -0700 | [diff] [blame] | 27 | CPDF_TilingPattern* CPDF_TilingPattern::AsTilingPattern() { |
| 28 | return this; |
| 29 | } |
| 30 | |
| 31 | CPDF_ShadingPattern* CPDF_TilingPattern::AsShadingPattern() { |
| 32 | return nullptr; |
| 33 | } |
| 34 | |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 35 | FX_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 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 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")); |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 46 | |
| 47 | CPDF_Stream* pStream = m_pPatternObj->AsStream(); |
| 48 | if (!pStream) |
| 49 | return FALSE; |
| 50 | |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 51 | m_pForm.reset(new CPDF_Form(m_pDocument, nullptr, pStream)); |
| 52 | m_pForm->ParseContent(nullptr, &m_ParentMatrix, nullptr); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame^] | 53 | m_BBox = pDict->GetRectFor("BBox"); |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 54 | return TRUE; |
| 55 | } |