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, |
| 16 | const CFX_Matrix* parentMatrix) |
| 17 | : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { |
| 18 | CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
| 19 | m_Pattern2Form = pDict->GetMatrixBy("Matrix"); |
| 20 | m_bColored = pDict->GetIntegerBy("PaintType") == 1; |
| 21 | if (parentMatrix) |
| 22 | m_Pattern2Form.Concat(*parentMatrix); |
| 23 | |
| 24 | m_pForm = nullptr; |
| 25 | } |
| 26 | |
| 27 | CPDF_TilingPattern::~CPDF_TilingPattern() { |
| 28 | delete m_pForm; |
| 29 | } |
| 30 | |
| 31 | FX_BOOL CPDF_TilingPattern::Load() { |
| 32 | if (m_pForm) |
| 33 | return TRUE; |
| 34 | |
| 35 | CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
| 36 | if (!pDict) |
| 37 | return FALSE; |
| 38 | |
| 39 | m_bColored = pDict->GetIntegerBy("PaintType") == 1; |
| 40 | m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberBy("XStep")); |
| 41 | m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberBy("YStep")); |
| 42 | |
| 43 | CPDF_Stream* pStream = m_pPatternObj->AsStream(); |
| 44 | if (!pStream) |
| 45 | return FALSE; |
| 46 | |
| 47 | m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); |
| 48 | m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); |
| 49 | m_BBox = pDict->GetRectBy("BBox"); |
| 50 | return TRUE; |
| 51 | } |