OLD | NEW |
(Empty) | |
| 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/fpdf_page/cpdf_clippathdata.h" |
| 8 |
| 9 #include "core/fpdfapi/fpdf_page/include/cpdf_path.h" |
| 10 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" |
| 11 |
| 12 CPDF_ClipPathData::CPDF_ClipPathData() |
| 13 : m_PathCount(0), |
| 14 m_pPathList(nullptr), |
| 15 m_pTypeList(nullptr), |
| 16 m_TextCount(0), |
| 17 m_pTextList(nullptr) {} |
| 18 |
| 19 CPDF_ClipPathData::~CPDF_ClipPathData() { |
| 20 delete[] m_pPathList; |
| 21 FX_Free(m_pTypeList); |
| 22 |
| 23 for (int i = m_TextCount - 1; i > -1; i--) |
| 24 delete m_pTextList[i]; |
| 25 FX_Free(m_pTextList); |
| 26 } |
| 27 |
| 28 CPDF_ClipPathData::CPDF_ClipPathData(const CPDF_ClipPathData& src) { |
| 29 m_pPathList = nullptr; |
| 30 m_pPathList = nullptr; |
| 31 m_pTextList = nullptr; |
| 32 |
| 33 m_PathCount = src.m_PathCount; |
| 34 if (m_PathCount) { |
| 35 int alloc_size = m_PathCount; |
| 36 if (alloc_size % 8) |
| 37 alloc_size += 8 - (alloc_size % 8); |
| 38 |
| 39 m_pPathList = new CPDF_Path[alloc_size]; |
| 40 for (int i = 0; i < m_PathCount; i++) |
| 41 m_pPathList[i] = src.m_pPathList[i]; |
| 42 |
| 43 m_pTypeList = FX_Alloc(uint8_t, alloc_size); |
| 44 FXSYS_memcpy(m_pTypeList, src.m_pTypeList, m_PathCount); |
| 45 } else { |
| 46 m_pPathList = nullptr; |
| 47 m_pTypeList = nullptr; |
| 48 } |
| 49 |
| 50 m_TextCount = src.m_TextCount; |
| 51 if (m_TextCount) { |
| 52 m_pTextList = FX_Alloc(CPDF_TextObject*, m_TextCount); |
| 53 for (int i = 0; i < m_TextCount; i++) { |
| 54 if (src.m_pTextList[i]) |
| 55 m_pTextList[i] = src.m_pTextList[i]->Clone(); |
| 56 else |
| 57 m_pTextList[i] = nullptr; |
| 58 } |
| 59 } else { |
| 60 m_pTextList = nullptr; |
| 61 } |
| 62 } |
| 63 |
| 64 void CPDF_ClipPathData::SetCount(int path_count, int text_count) { |
| 65 ASSERT(m_TextCount == 0 && m_PathCount == 0); |
| 66 if (path_count) { |
| 67 m_PathCount = path_count; |
| 68 int alloc_size = (path_count + 7) / 8 * 8; |
| 69 m_pPathList = new CPDF_Path[alloc_size]; |
| 70 m_pTypeList = FX_Alloc(uint8_t, alloc_size); |
| 71 } |
| 72 |
| 73 if (text_count) { |
| 74 m_TextCount = text_count; |
| 75 m_pTextList = FX_Alloc(CPDF_TextObject*, text_count); |
| 76 } |
| 77 } |
OLD | NEW |