Home | History | Annotate | Download | only in page
      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 
     12 CPDF_ShadingObject::CPDF_ShadingObject(CPDF_ShadingPattern* pattern,
     13                                        const CFX_Matrix& matrix)
     14     : m_pShading(pattern), m_Matrix(matrix) {}
     15 
     16 CPDF_ShadingObject::~CPDF_ShadingObject() {}
     17 
     18 CPDF_PageObject::Type CPDF_ShadingObject::GetType() const {
     19   return SHADING;
     20 }
     21 
     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 
     35 bool CPDF_ShadingObject::IsShading() const {
     36   return true;
     37 }
     38 
     39 CPDF_ShadingObject* CPDF_ShadingObject::AsShading() {
     40   return this;
     41 }
     42 
     43 const CPDF_ShadingObject* CPDF_ShadingObject::AsShading() const {
     44   return this;
     45 }
     46 
     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