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

Side by Side Diff: core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp

Issue 1611193003: Rename CPDF_PageContentGenerate to CPDF_PageContentGenerator. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « core/include/fpdfapi/fpdf_page.h ('k') | fpdfsdk/src/fpdfeditpage.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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/include/fpdfapi/fpdf_module.h" 7 #include "core/include/fpdfapi/fpdf_module.h"
8 #include "core/include/fpdfapi/fpdf_page.h" 8 #include "core/include/fpdfapi/fpdf_page.h"
9 #include "core/include/fpdfapi/fpdf_serial.h" 9 #include "core/include/fpdfapi/fpdf_serial.h"
10 #include "core/src/fpdfapi/fpdf_page/pageint.h" 10 #include "core/src/fpdfapi/fpdf_page/pageint.h"
11 11
12 CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& ar, CFX_Matrix& matrix) { 12 CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& ar, CFX_Matrix& matrix) {
13 ar << matrix.a << " " << matrix.b << " " << matrix.c << " " << matrix.d << " " 13 ar << matrix.a << " " << matrix.b << " " << matrix.c << " " << matrix.d << " "
14 << matrix.e << " " << matrix.f; 14 << matrix.e << " " << matrix.f;
15 return ar; 15 return ar;
16 } 16 }
17 CPDF_PageContentGenerate::CPDF_PageContentGenerate(CPDF_Page* pPage) 17 CPDF_PageContentGenerator::CPDF_PageContentGenerator(CPDF_Page* pPage)
18 : m_pPage(pPage) { 18 : m_pPage(pPage) {
19 m_pDocument = NULL; 19 m_pDocument = NULL;
20 if (m_pPage) { 20 if (m_pPage) {
21 m_pDocument = m_pPage->m_pDocument; 21 m_pDocument = m_pPage->m_pDocument;
22 } 22 }
23 FX_POSITION pos = pPage->GetFirstObjectPosition(); 23 FX_POSITION pos = pPage->GetFirstObjectPosition();
24 while (pos) { 24 while (pos) {
25 InsertPageObject(pPage->GetNextObject(pos)); 25 InsertPageObject(pPage->GetNextObject(pos));
26 } 26 }
27 } 27 }
28 CPDF_PageContentGenerate::~CPDF_PageContentGenerate() {} 28 CPDF_PageContentGenerator::~CPDF_PageContentGenerator() {}
29 FX_BOOL CPDF_PageContentGenerate::InsertPageObject( 29 FX_BOOL CPDF_PageContentGenerator::InsertPageObject(
30 CPDF_PageObject* pPageObject) { 30 CPDF_PageObject* pPageObject) {
31 if (!pPageObject) { 31 if (!pPageObject) {
32 return FALSE; 32 return FALSE;
33 } 33 }
34 return m_pageObjects.Add(pPageObject); 34 return m_pageObjects.Add(pPageObject);
35 } 35 }
36 void CPDF_PageContentGenerate::GenerateContent() { 36 void CPDF_PageContentGenerator::GenerateContent() {
37 CFX_ByteTextBuf buf; 37 CFX_ByteTextBuf buf;
38 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; 38 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict;
39 for (int i = 0; i < m_pageObjects.GetSize(); ++i) { 39 for (int i = 0; i < m_pageObjects.GetSize(); ++i) {
40 CPDF_PageObject* pPageObj = m_pageObjects[i]; 40 CPDF_PageObject* pPageObj = m_pageObjects[i];
41 if (!pPageObj || pPageObj->m_Type != PDFPAGE_IMAGE) { 41 if (!pPageObj || pPageObj->m_Type != PDFPAGE_IMAGE) {
42 continue; 42 continue;
43 } 43 }
44 ProcessImage(buf, (CPDF_ImageObject*)pPageObj); 44 ProcessImage(buf, (CPDF_ImageObject*)pPageObj);
45 } 45 }
46 CPDF_Object* pContent = 46 CPDF_Object* pContent =
47 pPageDict ? pPageDict->GetElementValue("Contents") : NULL; 47 pPageDict ? pPageDict->GetElementValue("Contents") : NULL;
48 if (pContent) { 48 if (pContent) {
49 pPageDict->RemoveAt("Contents"); 49 pPageDict->RemoveAt("Contents");
50 } 50 }
51 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); 51 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL);
52 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); 52 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE);
53 m_pDocument->AddIndirectObject(pStream); 53 m_pDocument->AddIndirectObject(pStream);
54 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); 54 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum());
55 } 55 }
56 CFX_ByteString CPDF_PageContentGenerate::RealizeResource( 56 CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
57 CPDF_Object* pResourceObj, 57 CPDF_Object* pResourceObj,
58 const FX_CHAR* szType) { 58 const FX_CHAR* szType) {
59 if (!m_pPage->m_pResources) { 59 if (!m_pPage->m_pResources) {
60 m_pPage->m_pResources = new CPDF_Dictionary; 60 m_pPage->m_pResources = new CPDF_Dictionary;
61 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); 61 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources);
62 m_pPage->m_pFormDict->SetAtReference("Resources", m_pDocument, objnum); 62 m_pPage->m_pFormDict->SetAtReference("Resources", m_pDocument, objnum);
63 } 63 }
64 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDict(szType); 64 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDict(szType);
65 if (!pResList) { 65 if (!pResList) {
66 pResList = new CPDF_Dictionary; 66 pResList = new CPDF_Dictionary;
67 m_pPage->m_pResources->SetAt(szType, pResList); 67 m_pPage->m_pResources->SetAt(szType, pResList);
68 } 68 }
69 m_pDocument->AddIndirectObject(pResourceObj); 69 m_pDocument->AddIndirectObject(pResourceObj);
70 CFX_ByteString name; 70 CFX_ByteString name;
71 int idnum = 1; 71 int idnum = 1;
72 while (1) { 72 while (1) {
73 name.Format("FX%c%d", szType[0], idnum); 73 name.Format("FX%c%d", szType[0], idnum);
74 if (!pResList->KeyExist(name)) { 74 if (!pResList->KeyExist(name)) {
75 break; 75 break;
76 } 76 }
77 idnum++; 77 idnum++;
78 } 78 }
79 pResList->AddReference(name, m_pDocument, pResourceObj->GetObjNum()); 79 pResList->AddReference(name, m_pDocument, pResourceObj->GetObjNum());
80 return name; 80 return name;
81 } 81 }
82 void CPDF_PageContentGenerate::ProcessImage(CFX_ByteTextBuf& buf, 82 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf,
83 CPDF_ImageObject* pImageObj) { 83 CPDF_ImageObject* pImageObj) {
84 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || 84 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) ||
85 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { 85 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) {
86 return; 86 return;
87 } 87 }
88 buf << "q " << pImageObj->m_Matrix << " cm "; 88 buf << "q " << pImageObj->m_Matrix << " cm ";
89 if (!pImageObj->m_pImage->IsInline()) { 89 if (!pImageObj->m_pImage->IsInline()) {
90 CPDF_Stream* pStream = pImageObj->m_pImage->GetStream(); 90 CPDF_Stream* pStream = pImageObj->m_pImage->GetStream();
91 FX_DWORD dwSavedObjNum = pStream->GetObjNum(); 91 FX_DWORD dwSavedObjNum = pStream->GetObjNum();
92 CFX_ByteString name = RealizeResource(pStream, "XObject"); 92 CFX_ByteString name = RealizeResource(pStream, "XObject");
93 if (dwSavedObjNum == 0) { 93 if (dwSavedObjNum == 0) {
94 if (pImageObj->m_pImage) 94 if (pImageObj->m_pImage)
95 pImageObj->m_pImage->Release(); 95 pImageObj->m_pImage->Release();
96 pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pStream); 96 pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pStream);
97 } 97 }
98 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; 98 buf << "/" << PDF_NameEncode(name) << " Do Q\n";
99 } 99 }
100 } 100 }
101 void CPDF_PageContentGenerate::ProcessForm(CFX_ByteTextBuf& buf, 101 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf,
102 const uint8_t* data, 102 const uint8_t* data,
103 FX_DWORD size, 103 FX_DWORD size,
104 CFX_Matrix& matrix) { 104 CFX_Matrix& matrix) {
105 if (!data || !size) { 105 if (!data || !size) {
106 return; 106 return;
107 } 107 }
108 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); 108 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL);
109 CPDF_Dictionary* pFormDict = new CPDF_Dictionary; 109 CPDF_Dictionary* pFormDict = new CPDF_Dictionary;
110 pFormDict->SetAtName("Type", "XObject"); 110 pFormDict->SetAtName("Type", "XObject");
111 pFormDict->SetAtName("Subtype", "Form"); 111 pFormDict->SetAtName("Subtype", "Form");
112 CFX_FloatRect bbox = m_pPage->GetPageBBox(); 112 CFX_FloatRect bbox = m_pPage->GetPageBBox();
113 matrix.TransformRect(bbox); 113 matrix.TransformRect(bbox);
114 pFormDict->SetAtRect("BBox", bbox); 114 pFormDict->SetAtRect("BBox", bbox);
115 pStream->InitStream((uint8_t*)data, size, pFormDict); 115 pStream->InitStream((uint8_t*)data, size, pFormDict);
116 buf << "q " << matrix << " cm "; 116 buf << "q " << matrix << " cm ";
117 CFX_ByteString name = RealizeResource(pStream, "XObject"); 117 CFX_ByteString name = RealizeResource(pStream, "XObject");
118 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; 118 buf << "/" << PDF_NameEncode(name) << " Do Q\n";
119 } 119 }
120 void CPDF_PageContentGenerate::TransformContent(CFX_Matrix& matrix) { 120 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) {
121 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; 121 CPDF_Dictionary* pDict = m_pPage->m_pFormDict;
122 CPDF_Object* pContent = pDict ? pDict->GetElementValue("Contents") : NULL; 122 CPDF_Object* pContent = pDict ? pDict->GetElementValue("Contents") : NULL;
123 if (!pContent) 123 if (!pContent)
124 return; 124 return;
125 125
126 CFX_ByteTextBuf buf; 126 CFX_ByteTextBuf buf;
127 if (CPDF_Array* pArray = pContent->AsArray()) { 127 if (CPDF_Array* pArray = pContent->AsArray()) {
128 int iCount = pArray->GetCount(); 128 int iCount = pArray->GetCount();
129 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); 129 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount);
130 int size = 0; 130 int size = 0;
(...skipping 25 matching lines...) Expand all
156 CPDF_StreamAcc contentStream; 156 CPDF_StreamAcc contentStream;
157 contentStream.LoadAllData(pStream); 157 contentStream.LoadAllData(pStream);
158 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); 158 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
159 } 159 }
160 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); 160 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL);
161 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); 161 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE);
162 m_pDocument->AddIndirectObject(pStream); 162 m_pDocument->AddIndirectObject(pStream);
163 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, 163 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument,
164 pStream->GetObjNum()); 164 pStream->GetObjNum());
165 } 165 }
OLDNEW
« no previous file with comments | « core/include/fpdfapi/fpdf_page.h ('k') | fpdfsdk/src/fpdfeditpage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698