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

Side by Side Diff: core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp

Issue 2224623002: Add CPDF_ImageObject::GetImage(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: merge failure handlers Created 4 years, 4 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 | « no previous file | core/fpdfapi/fpdf_font/cpdf_type3char.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 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_edit/include/cpdf_pagecontentgenerator.h" 7 #include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h"
8 8
9 #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h" 9 #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" 10 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 CPDF_Object* pContent = 51 CPDF_Object* pContent =
52 pPageDict ? pPageDict->GetDirectObjectBy("Contents") : nullptr; 52 pPageDict ? pPageDict->GetDirectObjectBy("Contents") : nullptr;
53 if (pContent) { 53 if (pContent) {
54 pPageDict->RemoveAt("Contents"); 54 pPageDict->RemoveAt("Contents");
55 } 55 }
56 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); 56 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr);
57 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); 57 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE);
58 m_pDocument->AddIndirectObject(pStream); 58 m_pDocument->AddIndirectObject(pStream);
59 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); 59 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum());
60 } 60 }
61
61 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( 62 CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
62 CPDF_Object* pResourceObj, 63 CPDF_Object* pResourceObj,
63 const CFX_ByteString& bsType) { 64 const CFX_ByteString& bsType) {
64 if (!m_pPage->m_pResources) { 65 if (!m_pPage->m_pResources) {
65 m_pPage->m_pResources = new CPDF_Dictionary; 66 m_pPage->m_pResources = new CPDF_Dictionary;
66 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); 67 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources);
67 m_pPage->m_pFormDict->SetAtReference("Resources", m_pDocument, objnum); 68 m_pPage->m_pFormDict->SetAtReference("Resources", m_pDocument, objnum);
68 } 69 }
69 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictBy(bsType); 70 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictBy(bsType);
70 if (!pResList) { 71 if (!pResList) {
71 pResList = new CPDF_Dictionary; 72 pResList = new CPDF_Dictionary;
72 m_pPage->m_pResources->SetAt(bsType, pResList); 73 m_pPage->m_pResources->SetAt(bsType, pResList);
73 } 74 }
74 m_pDocument->AddIndirectObject(pResourceObj); 75 m_pDocument->AddIndirectObject(pResourceObj);
75 CFX_ByteString name; 76 CFX_ByteString name;
76 int idnum = 1; 77 int idnum = 1;
77 while (1) { 78 while (1) {
78 name.Format("FX%c%d", bsType[0], idnum); 79 name.Format("FX%c%d", bsType[0], idnum);
79 if (!pResList->KeyExist(name)) { 80 if (!pResList->KeyExist(name)) {
80 break; 81 break;
81 } 82 }
82 idnum++; 83 idnum++;
83 } 84 }
84 pResList->SetAtReference(name, m_pDocument, pResourceObj->GetObjNum()); 85 pResList->SetAtReference(name, m_pDocument, pResourceObj->GetObjNum());
85 return name; 86 return name;
86 } 87 }
88
87 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, 89 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf,
88 CPDF_ImageObject* pImageObj) { 90 CPDF_ImageObject* pImageObj) {
89 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || 91 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) ||
90 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { 92 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) {
91 return; 93 return;
92 } 94 }
93 buf << "q " << pImageObj->m_Matrix << " cm "; 95 buf << "q " << pImageObj->m_Matrix << " cm ";
94 if (!pImageObj->m_pImage->IsInline()) { 96 CPDF_Image* pImage = pImageObj->GetImage();
95 CPDF_Stream* pStream = pImageObj->m_pImage->GetStream(); 97 if (!pImage->IsInline()) {
98 CPDF_Stream* pStream = pImage->GetStream();
96 uint32_t dwSavedObjNum = pStream->GetObjNum(); 99 uint32_t dwSavedObjNum = pStream->GetObjNum();
97 CFX_ByteString name = RealizeResource(pStream, "XObject"); 100 CFX_ByteString name = RealizeResource(pStream, "XObject");
98 if (dwSavedObjNum == 0) { 101 if (dwSavedObjNum == 0) {
99 if (pImageObj->m_pImage) 102 pImage->Release();
100 pImageObj->m_pImage->Release();
101 pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pStream); 103 pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pStream);
102 } 104 }
103 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; 105 buf << "/" << PDF_NameEncode(name) << " Do Q\n";
104 } 106 }
105 } 107 }
106 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, 108 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf,
107 const uint8_t* data, 109 const uint8_t* data,
108 uint32_t size, 110 uint32_t size,
109 CFX_Matrix& matrix) { 111 CFX_Matrix& matrix) {
110 if (!data || !size) { 112 if (!data || !size) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 CPDF_StreamAcc contentStream; 163 CPDF_StreamAcc contentStream;
162 contentStream.LoadAllData(pStream); 164 contentStream.LoadAllData(pStream);
163 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); 165 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
164 } 166 }
165 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); 167 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr);
166 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); 168 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE);
167 m_pDocument->AddIndirectObject(pStream); 169 m_pDocument->AddIndirectObject(pStream);
168 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, 170 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument,
169 pStream->GetObjNum()); 171 pStream->GetObjNum());
170 } 172 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_font/cpdf_type3char.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698