1 // Copyright 2024 The PDFium Authors 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 #ifndef CORE_FPDFAPI_EDIT_CPDF_PAGEORGANIZER_H_ 8 #define CORE_FPDFAPI_EDIT_CPDF_PAGEORGANIZER_H_ 9 10 #include <stdint.h> 11 12 #include <map> 13 14 #include "core/fxcrt/bytestring.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 18 class CPDF_Dictionary; 19 class CPDF_Document; 20 class CPDF_Object; 21 class CPDF_Reference; 22 23 class CPDF_PageOrganizer { 24 protected: 25 CPDF_PageOrganizer(CPDF_Document* dest_doc, CPDF_Document* src_doc); 26 ~CPDF_PageOrganizer(); 27 28 // Must be called after construction before doing anything else. 29 bool Init(); 30 31 bool UpdateReference(RetainPtr<CPDF_Object> obj); 32 dest()33 CPDF_Document* dest() { return dest_doc_; } dest()34 const CPDF_Document* dest() const { return dest_doc_; } 35 src()36 CPDF_Document* src() { return src_doc_; } src()37 const CPDF_Document* src() const { return src_doc_; } 38 AddObjectMapping(uint32_t old_page_obj_num,uint32_t new_page_obj_num)39 void AddObjectMapping(uint32_t old_page_obj_num, uint32_t new_page_obj_num) { 40 object_number_map_[old_page_obj_num] = new_page_obj_num; 41 } 42 ClearObjectNumberMap()43 void ClearObjectNumberMap() { object_number_map_.clear(); } 44 45 static bool CopyInheritable(RetainPtr<CPDF_Dictionary> dest_page_dict, 46 RetainPtr<const CPDF_Dictionary> src_page_dict, 47 const ByteString& key); 48 49 static RetainPtr<const CPDF_Object> PageDictGetInheritableTag( 50 RetainPtr<const CPDF_Dictionary> dict, 51 const ByteString& src_tag); 52 53 private: 54 bool InitDestDoc(); 55 56 uint32_t GetNewObjId(CPDF_Reference* ref); 57 58 UnownedPtr<CPDF_Document> const dest_doc_; 59 UnownedPtr<CPDF_Document> const src_doc_; 60 61 // Mapping of source object number to destination object number. 62 std::map<uint32_t, uint32_t> object_number_map_; 63 }; 64 65 #endif // CORE_FPDFAPI_EDIT_CPDF_PAGEORGANIZER_H_ 66