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 #ifndef CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTGENERATOR_H_ 8 #define CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTGENERATOR_H_ 9 10 #include <map> 11 #include <memory> 12 #include <sstream> 13 #include <vector> 14 15 #include "core/fxcrt/fx_string.h" 16 #include "core/fxcrt/fx_system.h" 17 #include "core/fxcrt/unowned_ptr.h" 18 19 class CPDF_ContentMarks; 20 class CPDF_Document; 21 class CPDF_ImageObject; 22 class CPDF_Object; 23 class CPDF_PageObject; 24 class CPDF_PageObjectHolder; 25 class CPDF_PathObject; 26 class CPDF_TextObject; 27 28 class CPDF_PageContentGenerator { 29 public: 30 explicit CPDF_PageContentGenerator(CPDF_PageObjectHolder* pObjHolder); 31 ~CPDF_PageContentGenerator(); 32 33 void GenerateContent(); 34 bool ProcessPageObjects(std::ostringstream* buf); 35 36 private: 37 friend class CPDF_PageContentGeneratorTest; 38 39 void ProcessPageObject(std::ostringstream* buf, CPDF_PageObject* pPageObj); 40 void ProcessPath(std::ostringstream* buf, CPDF_PathObject* pPathObj); 41 void ProcessImage(std::ostringstream* buf, CPDF_ImageObject* pImageObj); 42 void ProcessGraphics(std::ostringstream* buf, CPDF_PageObject* pPageObj); 43 void ProcessDefaultGraphics(std::ostringstream* buf); 44 void ProcessText(std::ostringstream* buf, CPDF_TextObject* pTextObj); 45 ByteString GetOrCreateDefaultGraphics() const; 46 ByteString RealizeResource(const CPDF_Object* pResource, 47 const ByteString& bsType) const; 48 const CPDF_ContentMarks* ProcessContentMarks(std::ostringstream* buf, 49 const CPDF_PageObject* pPageObj, 50 const CPDF_ContentMarks* pPrev); 51 void FinishMarks(std::ostringstream* buf, 52 const CPDF_ContentMarks* pContentMarks); 53 54 // Returns a map from content stream index to new stream data. Unmodified 55 // streams are not touched. 56 std::map<int32_t, std::unique_ptr<std::ostringstream>> 57 GenerateModifiedStreams(); 58 59 // Add buffer as a stream in page's 'Contents' 60 void UpdateContentStreams( 61 std::map<int32_t, std::unique_ptr<std::ostringstream>>* new_stream_data); 62 63 // Set the stream index of all page objects with stream index == 64 // |CPDF_PageObject::kNoContentStream|. These are new objects that had not 65 // been parsed from or written to any content stream yet. 66 void UpdateStreamlessPageObjects(int new_content_stream_index); 67 68 UnownedPtr<CPDF_PageObjectHolder> const m_pObjHolder; 69 UnownedPtr<CPDF_Document> const m_pDocument; 70 std::vector<UnownedPtr<CPDF_PageObject>> m_pageObjects; 71 }; 72 73 #endif // CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTGENERATOR_H_ 74