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_shadingpattern.h"
10 #include "core/fpdfapi/parser/cpdf_document.h"
11 
CPDF_ShadingObject(CPDF_ShadingPattern * pattern,const CFX_Matrix & matrix)12 CPDF_ShadingObject::CPDF_ShadingObject(CPDF_ShadingPattern* pattern,
13                                        const CFX_Matrix& matrix)
14     : m_pShading(pattern), m_Matrix(matrix) {}
15 
~CPDF_ShadingObject()16 CPDF_ShadingObject::~CPDF_ShadingObject() {}
17 
GetType() const18 CPDF_PageObject::Type CPDF_ShadingObject::GetType() const {
19   return SHADING;
20 }
21 
Transform(const CFX_Matrix & matrix)22 void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
23   if (m_ClipPath.HasRef())
24     m_ClipPath.Transform(matrix);
25 
26   m_Matrix.Concat(matrix);
27   if (m_ClipPath.HasRef()) {
28     CalcBoundingBox();
29   } else {
30     std::tie(m_Left, m_Right, m_Top, m_Bottom) =
31         matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
32   }
33 }
34 
IsShading() const35 bool CPDF_ShadingObject::IsShading() const {
36   return true;
37 }
38 
AsShading()39 CPDF_ShadingObject* CPDF_ShadingObject::AsShading() {
40   return this;
41 }
42 
AsShading() const43 const CPDF_ShadingObject* CPDF_ShadingObject::AsShading() const {
44   return this;
45 }
46 
CalcBoundingBox()47 void CPDF_ShadingObject::CalcBoundingBox() {
48   if (!m_ClipPath.HasRef())
49     return;
50   CFX_FloatRect rect = m_ClipPath.GetClipBox();
51   m_Left = rect.left;
52   m_Bottom = rect.bottom;
53   m_Right = rect.right;
54   m_Top = rect.top;
55 }
56