xref: /aosp_15_r20/external/pdfium/core/fpdfapi/page/cpdf_pathobject.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2016 The PDFium Authors
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_pathobject.h"
8 
CPDF_PathObject(int32_t content_stream)9 CPDF_PathObject::CPDF_PathObject(int32_t content_stream)
10     : CPDF_PageObject(content_stream) {}
11 
CPDF_PathObject()12 CPDF_PathObject::CPDF_PathObject() : CPDF_PathObject(kNoContentStream) {}
13 
14 CPDF_PathObject::~CPDF_PathObject() = default;
15 
GetType() const16 CPDF_PageObject::Type CPDF_PathObject::GetType() const {
17   return Type::kPath;
18 }
19 
Transform(const CFX_Matrix & matrix)20 void CPDF_PathObject::Transform(const CFX_Matrix& matrix) {
21   m_Matrix.Concat(matrix);
22   CalcBoundingBox();
23   SetDirty(true);
24 }
25 
IsPath() const26 bool CPDF_PathObject::IsPath() const {
27   return true;
28 }
29 
AsPath()30 CPDF_PathObject* CPDF_PathObject::AsPath() {
31   return this;
32 }
33 
AsPath() const34 const CPDF_PathObject* CPDF_PathObject::AsPath() const {
35   return this;
36 }
37 
CalcBoundingBox()38 void CPDF_PathObject::CalcBoundingBox() {
39   if (!m_Path.HasRef())
40     return;
41   CFX_FloatRect rect;
42   float width = m_GraphState.GetLineWidth();
43   if (m_bStroke && width != 0) {
44     rect =
45         m_Path.GetBoundingBoxForStrokePath(width, m_GraphState.GetMiterLimit());
46   } else {
47     rect = m_Path.GetBoundingBox();
48   }
49   rect = m_Matrix.TransformRect(rect);
50 
51   if (width == 0 && m_bStroke)
52     rect.Inflate(0.5f, 0.5f);
53   SetRect(rect);
54 }
55 
SetPathMatrix(const CFX_Matrix & matrix)56 void CPDF_PathObject::SetPathMatrix(const CFX_Matrix& matrix) {
57   m_Matrix = matrix;
58   CalcBoundingBox();
59 }
60