summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_cross_ref_table.h
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-06-27 17:52:40 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-27 17:52:40 +0000
commit9e12f14814722c0c0d46d4968f636b5e1a72a1e7 (patch)
tree540394b17d4f94227bec1064ebedbd475f88a26c /core/fpdfapi/parser/cpdf_cross_ref_table.h
parent2d7cb9267899902ce455165303e2373ac38c867d (diff)
downloadpdfium-9e12f14814722c0c0d46d4968f636b5e1a72a1e7.tar.xz
Implement CPDF_CrossRefTable
Change-Id: I5ac61ab323adb5eec2de8660064fff95ee877b5e Reviewed-on: https://pdfium-review.googlesource.com/35432 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_cross_ref_table.h')
-rw-r--r--core/fpdfapi/parser/cpdf_cross_ref_table.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/core/fpdfapi/parser/cpdf_cross_ref_table.h b/core/fpdfapi/parser/cpdf_cross_ref_table.h
new file mode 100644
index 0000000000..ade1b336b2
--- /dev/null
+++ b/core/fpdfapi/parser/cpdf_cross_ref_table.h
@@ -0,0 +1,68 @@
+// Copyright 2018 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.
+
+#ifndef CORE_FPDFAPI_PARSER_CPDF_CROSS_REF_TABLE_H_
+#define CORE_FPDFAPI_PARSER_CPDF_CROSS_REF_TABLE_H_
+
+#include <map>
+#include <memory>
+
+#include "core/fxcrt/fx_system.h"
+
+class CPDF_Dictionary;
+
+class CPDF_CrossRefTable {
+ public:
+ enum class ObjectType : uint8_t {
+ kFree = 0x00,
+ kNormal = 0x01,
+ kNotCompressed = kNormal,
+ kCompressed = 0x02,
+ kObjStream = 0xFF,
+ kNull = kObjStream,
+ };
+
+ struct ObjectInfo {
+ ObjectInfo() : pos(0), type(ObjectType::kFree), gennum(0) {}
+ // if type is ObjectType::kCompressed the archive_obj_num should be used.
+ // if type is ObjectType::kNotCompressed the pos should be used.
+ // In other cases its are unused.
+ union {
+ FX_FILESIZE pos;
+ uint32_t archive_obj_num;
+ };
+ ObjectType type;
+ uint16_t gennum;
+ };
+
+ CPDF_CrossRefTable();
+ explicit CPDF_CrossRefTable(std::unique_ptr<CPDF_Dictionary> trailer);
+ ~CPDF_CrossRefTable();
+
+ void AddCompressed(uint32_t obj_num, uint32_t archive_obj_num);
+ void AddNormal(uint32_t obj_num, uint16_t gen_num, FX_FILESIZE pos);
+ void SetFree(uint32_t obj_num);
+
+ const CPDF_Dictionary* trailer() const { return trailer_.get(); }
+ void SetTrailer(std::unique_ptr<CPDF_Dictionary> trailer);
+
+ const ObjectInfo* GetObjectInfo(uint32_t obj_num) const;
+
+ const std::map<uint32_t, ObjectInfo>& objects_info() const {
+ return objects_info_;
+ }
+
+ void Update(std::unique_ptr<CPDF_CrossRefTable> new_cross_ref);
+
+ void ShrinkObjectMap(uint32_t objnum);
+
+ private:
+ void UpdateInfo(std::map<uint32_t, ObjectInfo>&& new_objects_info);
+ void UpdateTrailer(std::unique_ptr<CPDF_Dictionary> new_trailer);
+
+ std::unique_ptr<CPDF_Dictionary> trailer_;
+ std::map<uint32_t, ObjectInfo> objects_info_;
+};
+
+#endif // CORE_FPDFAPI_PARSER_CPDF_CROSS_REF_TABLE_H_