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/page/cpdf_shadingobject.h"
8 
9 #include "core/fpdfapi/page/cpdf_docpagedata.h"
10 #include "core/fpdfapi/page/cpdf_shadingpattern.h"
11 #include "core/fpdfapi/parser/cpdf_document.h"
12 
CPDF_ShadingObject()13 CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {}
14 
~CPDF_ShadingObject()15 CPDF_ShadingObject::~CPDF_ShadingObject() {}
16 
GetType() const17 CPDF_PageObject::Type CPDF_ShadingObject::GetType() const {
18   return SHADING;
19 }
20 
Transform(const CFX_Matrix & matrix)21 void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
22   if (m_ClipPath)
23     m_ClipPath.Transform(matrix);
24 
25   m_Matrix.Concat(matrix);
26   if (m_ClipPath) {
27     CalcBoundingBox();
28   } else {
29     matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
30   }
31 }
32 
IsShading() const33 bool CPDF_ShadingObject::IsShading() const {
34   return true;
35 }
36 
AsShading()37 CPDF_ShadingObject* CPDF_ShadingObject::AsShading() {
38   return this;
39 }
40 
AsShading() const41 const CPDF_ShadingObject* CPDF_ShadingObject::AsShading() const {
42   return this;
43 }
44 
CalcBoundingBox()45 void CPDF_ShadingObject::CalcBoundingBox() {
46   if (!m_ClipPath)
47     return;
48   CFX_FloatRect rect = m_ClipPath.GetClipBox();
49   m_Left = rect.left;
50   m_Bottom = rect.bottom;
51   m_Right = rect.right;
52   m_Top = rect.top;
53 }
54