OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 CPDF_TextObject* CPDF_ClipPath::GetText(size_t i) const { | 32 CPDF_TextObject* CPDF_ClipPath::GetText(size_t i) const { |
33 return GetObject()->m_TextList[i].get(); | 33 return GetObject()->m_TextList[i].get(); |
34 } | 34 } |
35 | 35 |
36 CFX_FloatRect CPDF_ClipPath::GetClipBox() const { | 36 CFX_FloatRect CPDF_ClipPath::GetClipBox() const { |
37 CFX_FloatRect rect; | 37 CFX_FloatRect rect; |
38 FX_BOOL bStarted = FALSE; | 38 FX_BOOL bStarted = FALSE; |
39 int count = GetPathCount(); | 39 int count = GetPathCount(); |
40 if (count) { | 40 if (count) { |
41 rect = GetPath(0)->GetBoundingBox(); | 41 rect = GetPath(0).GetBoundingBox(); |
42 for (int i = 1; i < count; i++) { | 42 for (int i = 1; i < count; i++) { |
43 CFX_FloatRect path_rect = GetPath(i)->GetBoundingBox(); | 43 CFX_FloatRect path_rect = GetPath(i).GetBoundingBox(); |
44 rect.Intersect(path_rect); | 44 rect.Intersect(path_rect); |
45 } | 45 } |
46 bStarted = TRUE; | 46 bStarted = TRUE; |
47 } | 47 } |
48 count = GetTextCount(); | 48 count = GetTextCount(); |
49 if (count) { | 49 if (count) { |
50 CFX_FloatRect layer_rect; | 50 CFX_FloatRect layer_rect; |
51 FX_BOOL bLayerStarted = FALSE; | 51 FX_BOOL bLayerStarted = FALSE; |
52 for (int i = 0; i < count; i++) { | 52 for (int i = 0; i < count; i++) { |
53 CPDF_TextObject* pTextObj = GetText(i); | 53 CPDF_TextObject* pTextObj = GetText(i); |
(...skipping 16 matching lines...) Expand all Loading... |
70 } | 70 } |
71 } | 71 } |
72 return rect; | 72 return rect; |
73 } | 73 } |
74 | 74 |
75 void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) { | 75 void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) { |
76 MakePrivateCopy(); | 76 MakePrivateCopy(); |
77 CPDF_ClipPathData* pData = GetObject(); | 77 CPDF_ClipPathData* pData = GetObject(); |
78 if (!pData->m_PathAndTypeList.empty() && bAutoMerge) { | 78 if (!pData->m_PathAndTypeList.empty() && bAutoMerge) { |
79 const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first; | 79 const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first; |
80 if (old_path->IsRect()) { | 80 if (old_path.IsRect()) { |
81 CFX_FloatRect old_rect(old_path->GetPointX(0), old_path->GetPointY(0), | 81 CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0), |
82 old_path->GetPointX(2), old_path->GetPointY(2)); | 82 old_path.GetPointX(2), old_path.GetPointY(2)); |
83 CFX_FloatRect new_rect = path->GetBoundingBox(); | 83 CFX_FloatRect new_rect = path.GetBoundingBox(); |
84 if (old_rect.Contains(new_rect)) | 84 if (old_rect.Contains(new_rect)) |
85 pData->m_PathAndTypeList.pop_back(); | 85 pData->m_PathAndTypeList.pop_back(); |
86 } | 86 } |
87 } | 87 } |
88 pData->m_PathAndTypeList.push_back(std::make_pair(path, type)); | 88 pData->m_PathAndTypeList.push_back(std::make_pair(path, type)); |
89 } | 89 } |
90 | 90 |
91 void CPDF_ClipPath::AppendTexts( | 91 void CPDF_ClipPath::AppendTexts( |
92 std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) { | 92 std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) { |
93 MakePrivateCopy(); | 93 MakePrivateCopy(); |
94 CPDF_ClipPathData* pData = GetObject(); | 94 CPDF_ClipPathData* pData = GetObject(); |
95 if (pData->m_TextList.size() + pTexts->size() <= FPDF_CLIPPATH_MAX_TEXTS) { | 95 if (pData->m_TextList.size() + pTexts->size() <= FPDF_CLIPPATH_MAX_TEXTS) { |
96 for (size_t i = 0; i < pTexts->size(); i++) | 96 for (size_t i = 0; i < pTexts->size(); i++) |
97 pData->m_TextList.push_back(std::move((*pTexts)[i])); | 97 pData->m_TextList.push_back(std::move((*pTexts)[i])); |
98 pData->m_TextList.push_back(std::unique_ptr<CPDF_TextObject>()); | 98 pData->m_TextList.push_back(std::unique_ptr<CPDF_TextObject>()); |
99 } | 99 } |
100 pTexts->clear(); | 100 pTexts->clear(); |
101 } | 101 } |
102 | 102 |
103 void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) { | 103 void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) { |
104 MakePrivateCopy(); | 104 MakePrivateCopy(); |
105 CPDF_ClipPathData* pData = GetObject(); | 105 CPDF_ClipPathData* pData = GetObject(); |
106 for (auto& obj : pData->m_PathAndTypeList) | 106 for (auto& obj : pData->m_PathAndTypeList) |
107 obj.first.Transform(&matrix); | 107 obj.first.Transform(&matrix); |
108 for (auto& text : pData->m_TextList) { | 108 for (auto& text : pData->m_TextList) { |
109 if (text) | 109 if (text) |
110 text->Transform(matrix); | 110 text->Transform(matrix); |
111 } | 111 } |
112 } | 112 } |
OLD | NEW |