OLD | NEW |
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 "public/fpdf_ppo.h" | 7 #include "public/fpdf_ppo.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 pDocInfoDict->SetFor("Producer", new CPDF_String(producerstr, false)); | 163 pDocInfoDict->SetFor("Producer", new CPDF_String(producerstr, false)); |
164 | 164 |
165 CFX_ByteString cbRootType = pNewRoot->GetStringFor("Type", ""); | 165 CFX_ByteString cbRootType = pNewRoot->GetStringFor("Type", ""); |
166 if (cbRootType.IsEmpty()) | 166 if (cbRootType.IsEmpty()) |
167 pNewRoot->SetFor("Type", new CPDF_Name("Catalog")); | 167 pNewRoot->SetFor("Type", new CPDF_Name("Catalog")); |
168 | 168 |
169 CPDF_Object* pElement = pNewRoot->GetObjectFor("Pages"); | 169 CPDF_Object* pElement = pNewRoot->GetObjectFor("Pages"); |
170 CPDF_Dictionary* pNewPages = | 170 CPDF_Dictionary* pNewPages = |
171 pElement ? ToDictionary(pElement->GetDirect()) : nullptr; | 171 pElement ? ToDictionary(pElement->GetDirect()) : nullptr; |
172 if (!pNewPages) { | 172 if (!pNewPages) { |
173 pNewPages = new CPDF_Dictionary(m_pDestPDFDoc->GetByteStringPool()); | 173 pNewPages = m_pDestPDFDoc->NewIndirect<CPDF_Dictionary>( |
174 pNewRoot->SetReferenceFor("Pages", m_pDestPDFDoc, | 174 m_pDestPDFDoc->GetByteStringPool()); |
175 m_pDestPDFDoc->AddIndirectObject(pNewPages)); | 175 pNewRoot->SetReferenceFor("Pages", m_pDestPDFDoc, pNewPages); |
176 } | 176 } |
177 | 177 |
178 CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", ""); | 178 CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", ""); |
179 if (cbPageType.IsEmpty()) | 179 if (cbPageType.IsEmpty()) |
180 pNewPages->SetFor("Type", new CPDF_Name("Pages")); | 180 pNewPages->SetFor("Type", new CPDF_Name("Pages")); |
181 | 181 |
182 if (!pNewPages->GetArrayFor("Kids")) { | 182 if (!pNewPages->GetArrayFor("Kids")) { |
183 pNewPages->SetIntegerFor("Count", 0); | 183 pNewPages->SetIntegerFor("Count", 0); |
184 pNewPages->SetReferenceFor( | 184 pNewPages->SetReferenceFor("Kids", m_pDestPDFDoc, |
185 "Kids", m_pDestPDFDoc, | 185 m_pDestPDFDoc->NewIndirect<CPDF_Array>()); |
186 m_pDestPDFDoc->AddIndirectObject(new CPDF_Array)); | |
187 } | 186 } |
188 | 187 |
189 return true; | 188 return true; |
190 } | 189 } |
191 | 190 |
192 bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums, | 191 bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums, |
193 int nIndex) { | 192 int nIndex) { |
194 int curpage = nIndex; | 193 int curpage = nIndex; |
195 auto pObjNumberMap = pdfium::MakeUnique<ObjectNumberMap>(); | 194 auto pObjNumberMap = pdfium::MakeUnique<ObjectNumberMap>(); |
196 int nSize = pdfium::CollectionSize<int>(pageNums); | 195 int nSize = pdfium::CollectionSize<int>(pageNums); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 std::unique_ptr<CPDF_Object> pClone = pDirect->Clone(); | 323 std::unique_ptr<CPDF_Object> pClone = pDirect->Clone(); |
325 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) { | 324 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) { |
326 if (pDictClone->KeyExist("Type")) { | 325 if (pDictClone->KeyExist("Type")) { |
327 CFX_ByteString strType = pDictClone->GetStringFor("Type"); | 326 CFX_ByteString strType = pDictClone->GetStringFor("Type"); |
328 if (!FXSYS_stricmp(strType.c_str(), "Pages")) | 327 if (!FXSYS_stricmp(strType.c_str(), "Pages")) |
329 return 4; | 328 return 4; |
330 if (!FXSYS_stricmp(strType.c_str(), "Page")) | 329 if (!FXSYS_stricmp(strType.c_str(), "Page")) |
331 return 0; | 330 return 0; |
332 } | 331 } |
333 } | 332 } |
334 CPDF_Object* pUnownedClone = pClone.get(); | 333 CPDF_Object* pUnownedClone = |
335 dwNewObjNum = m_pDestPDFDoc->AddIndirectObject(pClone.release()); | 334 m_pDestPDFDoc->AddIndirectObject(std::move(pClone)); |
| 335 dwNewObjNum = pUnownedClone->GetObjNum(); |
336 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; | 336 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; |
337 if (!UpdateReference(pUnownedClone, pObjNumberMap)) | 337 if (!UpdateReference(pUnownedClone, pObjNumberMap)) |
338 return 0; | 338 return 0; |
339 | 339 |
340 return dwNewObjNum; | 340 return dwNewObjNum; |
341 } | 341 } |
342 | 342 |
343 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, | 343 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, |
344 FPDF_DOCUMENT src_doc, | 344 FPDF_DOCUMENT src_doc, |
345 FPDF_BYTESTRING pagerange, | 345 FPDF_BYTESTRING pagerange, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 return false; | 383 return false; |
384 | 384 |
385 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 385 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
386 if (!pDstDict) | 386 if (!pDstDict) |
387 return false; | 387 return false; |
388 | 388 |
389 pDstDict->SetFor("ViewerPreferences", | 389 pDstDict->SetFor("ViewerPreferences", |
390 pSrcDict->CloneDirectObject().release()); | 390 pSrcDict->CloneDirectObject().release()); |
391 return true; | 391 return true; |
392 } | 392 } |
OLD | NEW |