summaryrefslogtreecommitdiff
path: root/core/fpdfapi/edit/cpdf_xrefstream.h
blob: 2ca990732bc282d58716be08df5da990477bc63b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FPDFAPI_EDIT_CPDF_XREFSTREAM_H_
#define CORE_FPDFAPI_EDIT_CPDF_XREFSTREAM_H_

#include <vector>

#include "core/fpdfapi/edit/cpdf_objectstream.h"
#include "core/fxcrt/fx_basic.h"

class CPDF_Creator;
class CPDF_Object;

class CPDF_XRefStream {
 public:
  struct Index {
    uint32_t objnum;
    uint32_t count;
  };

  CPDF_XRefStream();
  ~CPDF_XRefStream();

  bool Start();
  int32_t CompressIndirectObject(uint32_t dwObjNum,
                                 const CPDF_Object* pObj,
                                 CPDF_Creator* pCreator);
  int32_t CompressIndirectObject(uint32_t dwObjNum,
                                 const uint8_t* pBuffer,
                                 uint32_t dwSize,
                                 CPDF_Creator* pCreator);
  bool End(CPDF_Creator* pCreator, bool bEOF);
  void AddObjectNumberToIndexArray(uint32_t objnum);
  bool EndXRefStream(CPDF_Creator* pCreator);

  FX_FILESIZE GetPreviousOffset() const { return m_PrevOffset; }
  void SetPreviousOffset(FX_FILESIZE offset) { m_PrevOffset = offset; }

  uint32_t CountIndexArrayItems() const {
    uint32_t size = 0;
    for (const auto& pair : m_IndexArray)
      size += pair.count;
    return size;
  }

 private:
  int32_t EndObjectStream(CPDF_Creator* pCreator, bool bEOF);
  bool GenerateXRefStream(CPDF_Creator* pCreator, bool bEOF);

  std::vector<Index> m_IndexArray;
  FX_FILESIZE m_PrevOffset;
  uint32_t m_dwTempObjNum;
  size_t m_iSeg;
  CPDF_ObjectStream m_ObjStream;
  CFX_ByteTextBuf m_Buffer;
};

#endif  // CORE_FPDFAPI_EDIT_CPDF_XREFSTREAM_H_