| Index: core/fpdfapi/fpdf_page/cpdf_clippath.cpp
|
| diff --git a/core/fpdfapi/fpdf_page/cpdf_clippath.cpp b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
|
| index 3a3300ae2f8fc62ce5a0df83f90786f5912b33ac..ea854d1b29051c9aff298912c8cb8cd85ce30dee 100644
|
| --- a/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
|
| +++ b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
|
| @@ -6,10 +6,33 @@
|
|
|
| #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h"
|
|
|
| +#include <utility>
|
| +
|
| #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
|
| +#include "third_party/base/stl_util.h"
|
|
|
| #define FPDF_CLIPPATH_MAX_TEXTS 1024
|
|
|
| +uint32_t CPDF_ClipPath::GetPathCount() const {
|
| + return pdfium::CollectionSize<uint32_t>(m_pObject->m_PathAndTypeList);
|
| +}
|
| +
|
| +CPDF_Path CPDF_ClipPath::GetPath(size_t i) const {
|
| + return m_pObject->m_PathAndTypeList[i].first;
|
| +}
|
| +
|
| +uint8_t CPDF_ClipPath::GetClipType(size_t i) const {
|
| + return m_pObject->m_PathAndTypeList[i].second;
|
| +}
|
| +
|
| +uint32_t CPDF_ClipPath::GetTextCount() const {
|
| + return pdfium::CollectionSize<uint32_t>(m_pObject->m_TextList);
|
| +}
|
| +
|
| +CPDF_TextObject* CPDF_ClipPath::GetText(size_t i) const {
|
| + return m_pObject->m_TextList[i].get();
|
| +}
|
| +
|
| CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
|
| CFX_FloatRect rect;
|
| FX_BOOL bStarted = FALSE;
|
| @@ -49,83 +72,38 @@ CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
|
| return rect;
|
| }
|
|
|
| -void CPDF_ClipPath::AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge) {
|
| +void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) {
|
| CPDF_ClipPathData* pData = GetModify();
|
| - if (pData->m_PathCount && bAutoMerge) {
|
| - CPDF_Path old_path = pData->m_pPathList[pData->m_PathCount - 1];
|
| + if (!pData->m_PathAndTypeList.empty() && bAutoMerge) {
|
| + const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first;
|
| if (old_path.IsRect()) {
|
| CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0),
|
| old_path.GetPointX(2), old_path.GetPointY(2));
|
| CFX_FloatRect new_rect = path.GetBoundingBox();
|
| - if (old_rect.Contains(new_rect)) {
|
| - pData->m_PathCount--;
|
| - pData->m_pPathList[pData->m_PathCount].SetNull();
|
| - }
|
| + if (old_rect.Contains(new_rect))
|
| + pData->m_PathAndTypeList.pop_back();
|
| }
|
| }
|
| - if (pData->m_PathCount % 8 == 0) {
|
| - CPDF_Path* pNewPath = new CPDF_Path[pData->m_PathCount + 8];
|
| - for (int i = 0; i < pData->m_PathCount; i++) {
|
| - pNewPath[i] = pData->m_pPathList[i];
|
| - }
|
| - delete[] pData->m_pPathList;
|
| - uint8_t* pNewType = FX_Alloc(uint8_t, pData->m_PathCount + 8);
|
| - FXSYS_memcpy(pNewType, pData->m_pTypeList, pData->m_PathCount);
|
| - FX_Free(pData->m_pTypeList);
|
| - pData->m_pPathList = pNewPath;
|
| - pData->m_pTypeList = pNewType;
|
| - }
|
| - pData->m_pPathList[pData->m_PathCount] = path;
|
| - pData->m_pTypeList[pData->m_PathCount] = (uint8_t)type;
|
| - pData->m_PathCount++;
|
| -}
|
| -
|
| -void CPDF_ClipPath::DeletePath(int index) {
|
| - CPDF_ClipPathData* pData = GetModify();
|
| - if (index >= pData->m_PathCount) {
|
| - return;
|
| - }
|
| - pData->m_pPathList[index].SetNull();
|
| - for (int i = index; i < pData->m_PathCount - 1; i++) {
|
| - pData->m_pPathList[i] = pData->m_pPathList[i + 1];
|
| - }
|
| - pData->m_pPathList[pData->m_PathCount - 1].SetNull();
|
| - FXSYS_memmove(pData->m_pTypeList + index, pData->m_pTypeList + index + 1,
|
| - pData->m_PathCount - index - 1);
|
| - pData->m_PathCount--;
|
| + pData->m_PathAndTypeList.push_back(std::make_pair(path, type));
|
| }
|
|
|
| -void CPDF_ClipPath::AppendTexts(CPDF_TextObject** pTexts, int count) {
|
| +void CPDF_ClipPath::AppendTexts(
|
| + std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) {
|
| CPDF_ClipPathData* pData = GetModify();
|
| - if (pData->m_TextCount + count > FPDF_CLIPPATH_MAX_TEXTS) {
|
| - for (int i = 0; i < count; i++) {
|
| - delete pTexts[i];
|
| - }
|
| - return;
|
| + if (pData->m_TextList.size() + pTexts->size() <= FPDF_CLIPPATH_MAX_TEXTS) {
|
| + for (size_t i = 0; i < pTexts->size(); i++)
|
| + pData->m_TextList.push_back(std::move((*pTexts)[i]));
|
| + pData->m_TextList.push_back(std::unique_ptr<CPDF_TextObject>());
|
| }
|
| - CPDF_TextObject** pNewList =
|
| - FX_Alloc(CPDF_TextObject*, pData->m_TextCount + count + 1);
|
| - if (pData->m_pTextList) {
|
| - FXSYS_memcpy(pNewList, pData->m_pTextList,
|
| - pData->m_TextCount * sizeof(CPDF_TextObject*));
|
| - FX_Free(pData->m_pTextList);
|
| - }
|
| - pData->m_pTextList = pNewList;
|
| - for (int i = 0; i < count; i++) {
|
| - pData->m_pTextList[pData->m_TextCount + i] = pTexts[i];
|
| - }
|
| - pData->m_pTextList[pData->m_TextCount + count] = NULL;
|
| - pData->m_TextCount += count + 1;
|
| + pTexts->clear();
|
| }
|
|
|
| void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
|
| CPDF_ClipPathData* pData = GetModify();
|
| - int i;
|
| - for (i = 0; i < pData->m_PathCount; i++) {
|
| - pData->m_pPathList[i].Transform(&matrix);
|
| + for (auto& obj : pData->m_PathAndTypeList)
|
| + obj.first.Transform(&matrix);
|
| + for (auto& text : pData->m_TextList) {
|
| + if (text)
|
| + text->Transform(matrix);
|
| }
|
| - for (i = 0; i < pData->m_TextCount; i++)
|
| - if (pData->m_pTextList[i]) {
|
| - pData->m_pTextList[i]->Transform(matrix);
|
| - }
|
| }
|
|
|