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/include/cpdf_shadingobject.h" 8 9 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" 10 #include "core/fpdfapi/fpdf_page/pageint.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 12 CPDF_ShadingObject()13CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {} 14 ~CPDF_ShadingObject()15CPDF_ShadingObject::~CPDF_ShadingObject() {} 16 Clone() const17CPDF_ShadingObject* CPDF_ShadingObject::Clone() const { 18 CPDF_ShadingObject* obj = new CPDF_ShadingObject; 19 obj->CopyData(this); 20 21 obj->m_pShading = m_pShading; 22 if (obj->m_pShading && obj->m_pShading->document()) { 23 CPDF_DocPageData* pDocPageData = obj->m_pShading->document()->GetPageData(); 24 CPDF_Pattern* pattern = pDocPageData->GetPattern( 25 obj->m_pShading->GetShadingObject(), m_pShading->IsShadingObject(), 26 obj->m_pShading->parent_matrix()); 27 obj->m_pShading = pattern ? pattern->AsShadingPattern() : nullptr; 28 } 29 obj->m_Matrix = m_Matrix; 30 return obj; 31 } 32 GetType() const33CPDF_PageObject::Type CPDF_ShadingObject::GetType() const { 34 return SHADING; 35 } 36 Transform(const CFX_Matrix & matrix)37void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) { 38 if (!m_ClipPath.IsNull()) { 39 m_ClipPath.GetModify(); 40 m_ClipPath.Transform(matrix); 41 } 42 m_Matrix.Concat(matrix); 43 if (!m_ClipPath.IsNull()) { 44 CalcBoundingBox(); 45 } else { 46 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); 47 } 48 } 49 IsShading() const50bool CPDF_ShadingObject::IsShading() const { 51 return true; 52 } 53 AsShading()54CPDF_ShadingObject* CPDF_ShadingObject::AsShading() { 55 return this; 56 } 57 AsShading() const58const CPDF_ShadingObject* CPDF_ShadingObject::AsShading() const { 59 return this; 60 } 61 CalcBoundingBox()62void CPDF_ShadingObject::CalcBoundingBox() { 63 if (m_ClipPath.IsNull()) { 64 return; 65 } 66 CFX_FloatRect rect = m_ClipPath.GetClipBox(); 67 m_Left = rect.left; 68 m_Bottom = rect.bottom; 69 m_Right = rect.right; 70 m_Top = rect.top; 71 } 72