• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 #ifndef CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTMANAGER_H_
6 #define CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTMANAGER_H_
7 
8 #include <set>
9 #include <sstream>
10 
11 #include "core/fxcrt/retain_ptr.h"
12 #include "core/fxcrt/unowned_ptr.h"
13 
14 class CPDF_Array;
15 class CPDF_Document;
16 class CPDF_Object;
17 class CPDF_Stream;
18 class CPDF_PageObjectHolder;
19 
20 class CPDF_PageContentManager {
21  public:
22   explicit CPDF_PageContentManager(const CPDF_PageObjectHolder* obj_holder);
23   ~CPDF_PageContentManager();
24 
25   // Gets the Content stream at a given index. If Contents is a single stream
26   // rather than an array, it is considered to be at index 0.
27   CPDF_Stream* GetStreamByIndex(size_t stream_index);
28 
29   // Adds a new Content stream. Its index in the array will be returned, or 0
30   // if Contents is not an array, but only a single stream.
31   size_t AddStream(std::ostringstream* buf);
32 
33   // Schedule the removal of the Content stream at a given index. It will be
34   // removed when ExecuteScheduledRemovals() is called.
35   void ScheduleRemoveStreamByIndex(size_t stream_index);
36 
37   // Remove all Content streams for which ScheduleRemoveStreamByIndex() was
38   // called. Update the content stream of all page objects with the shifted
39   // indexes.
40   void ExecuteScheduledRemovals();
41 
42  private:
43   UnownedPtr<const CPDF_PageObjectHolder> const obj_holder_;
44   UnownedPtr<CPDF_Document> const doc_;
45   RetainPtr<CPDF_Array> contents_array_;
46   RetainPtr<CPDF_Stream> contents_stream_;
47   std::set<size_t> streams_to_remove_;
48 };
49 
50 #endif  // CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTMANAGER_H_
51