Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_clippath.cpp

Issue 1811053002: Move core/include/fpdfapi/fpdf_pageobj.h into core/fpdfapi. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/include/cpdf_clippath.h"
8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
10
11 #define FPDF_CLIPPATH_MAX_TEXTS 1024
12
13 CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
14 CFX_FloatRect rect;
15 FX_BOOL bStarted = FALSE;
16 int count = GetPathCount();
17 if (count) {
18 rect = GetPath(0).GetBoundingBox();
19 for (int i = 1; i < count; i++) {
20 CFX_FloatRect path_rect = GetPath(i).GetBoundingBox();
21 rect.Intersect(path_rect);
22 }
23 bStarted = TRUE;
24 }
25 count = GetTextCount();
26 if (count) {
27 CFX_FloatRect layer_rect;
28 FX_BOOL bLayerStarted = FALSE;
29 for (int i = 0; i < count; i++) {
30 CPDF_TextObject* pTextObj = GetText(i);
31 if (!pTextObj) {
32 if (!bStarted) {
33 rect = layer_rect;
34 bStarted = TRUE;
35 } else {
36 rect.Intersect(layer_rect);
37 }
38 bLayerStarted = FALSE;
39 } else {
40 if (!bLayerStarted) {
41 layer_rect = CFX_FloatRect(pTextObj->GetBBox(nullptr));
42 bLayerStarted = TRUE;
43 } else {
44 layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr)));
45 }
46 }
47 }
48 }
49 return rect;
50 }
51
52 void CPDF_ClipPath::AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge) {
53 CPDF_ClipPathData* pData = GetModify();
54 if (pData->m_PathCount && bAutoMerge) {
55 CPDF_Path old_path = pData->m_pPathList[pData->m_PathCount - 1];
56 if (old_path.IsRect()) {
57 CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0),
58 old_path.GetPointX(2), old_path.GetPointY(2));
59 CFX_FloatRect new_rect = path.GetBoundingBox();
60 if (old_rect.Contains(new_rect)) {
61 pData->m_PathCount--;
62 pData->m_pPathList[pData->m_PathCount].SetNull();
63 }
64 }
65 }
66 if (pData->m_PathCount % 8 == 0) {
67 CPDF_Path* pNewPath = new CPDF_Path[pData->m_PathCount + 8];
68 for (int i = 0; i < pData->m_PathCount; i++) {
69 pNewPath[i] = pData->m_pPathList[i];
70 }
71 delete[] pData->m_pPathList;
72 uint8_t* pNewType = FX_Alloc(uint8_t, pData->m_PathCount + 8);
73 FXSYS_memcpy(pNewType, pData->m_pTypeList, pData->m_PathCount);
74 FX_Free(pData->m_pTypeList);
75 pData->m_pPathList = pNewPath;
76 pData->m_pTypeList = pNewType;
77 }
78 pData->m_pPathList[pData->m_PathCount] = path;
79 pData->m_pTypeList[pData->m_PathCount] = (uint8_t)type;
80 pData->m_PathCount++;
81 }
82
83 void CPDF_ClipPath::DeletePath(int index) {
84 CPDF_ClipPathData* pData = GetModify();
85 if (index >= pData->m_PathCount) {
86 return;
87 }
88 pData->m_pPathList[index].SetNull();
89 for (int i = index; i < pData->m_PathCount - 1; i++) {
90 pData->m_pPathList[i] = pData->m_pPathList[i + 1];
91 }
92 pData->m_pPathList[pData->m_PathCount - 1].SetNull();
93 FXSYS_memmove(pData->m_pTypeList + index, pData->m_pTypeList + index + 1,
94 pData->m_PathCount - index - 1);
95 pData->m_PathCount--;
96 }
97
98 void CPDF_ClipPath::AppendTexts(CPDF_TextObject** pTexts, int count) {
99 CPDF_ClipPathData* pData = GetModify();
100 if (pData->m_TextCount + count > FPDF_CLIPPATH_MAX_TEXTS) {
101 for (int i = 0; i < count; i++) {
102 delete pTexts[i];
103 }
104 return;
105 }
106 CPDF_TextObject** pNewList =
107 FX_Alloc(CPDF_TextObject*, pData->m_TextCount + count + 1);
108 if (pData->m_pTextList) {
109 FXSYS_memcpy(pNewList, pData->m_pTextList,
110 pData->m_TextCount * sizeof(CPDF_TextObject*));
111 FX_Free(pData->m_pTextList);
112 }
113 pData->m_pTextList = pNewList;
114 for (int i = 0; i < count; i++) {
115 pData->m_pTextList[pData->m_TextCount + i] = pTexts[i];
116 }
117 pData->m_pTextList[pData->m_TextCount + count] = NULL;
118 pData->m_TextCount += count + 1;
119 }
120
121 void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
122 CPDF_ClipPathData* pData = GetModify();
123 int i;
124 for (i = 0; i < pData->m_PathCount; i++) {
125 pData->m_pPathList[i].Transform(&matrix);
126 }
127 for (i = 0; i < pData->m_TextCount; i++)
128 if (pData->m_pTextList[i]) {
129 pData->m_pTextList[i]->Transform(matrix);
130 }
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698