• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkPDFTag_DEFINED
9 #define SkPDFTag_DEFINED
10 
11 #include "include/docs/SkPDFDocument.h"
12 #include "include/private/SkTArray.h"
13 #include "include/private/SkTHash.h"
14 #include "src/core/SkArenaAlloc.h"
15 
16 class SkPDFDocument;
17 struct SkPDFIndirectReference;
18 struct SkPDFTagNode;
19 
20 class SkPDFTagTree {
21 public:
22     SkPDFTagTree();
23     ~SkPDFTagTree();
24     void init(SkPDF::StructureElementNode*);
25     // Used to allow marked content to refer to its corresponding structure
26     // tree node, via a page entry in the parent tree. Returns -1 if no
27     // mark ID.
28     int createMarkIdForNodeId(int nodeId, unsigned pageIndex);
29     // Used to allow annotations to refer to their corresponding structure
30     // tree node, via the struct parent tree. Returns -1 if no struct parent
31     // key.
32     int createStructParentKeyForNodeId(int nodeId, unsigned pageIndex);
33 
34     void addNodeAnnotation(int nodeId, SkPDFIndirectReference annotationRef, unsigned pageIndex);
35     SkPDFIndirectReference makeStructTreeRoot(SkPDFDocument* doc);
36 
37 private:
38     // An entry in a map from a node ID to an indirect reference to its
39     // corresponding structure element node.
40     struct IDTreeEntry {
41         int nodeId;
42         SkPDFIndirectReference ref;
43     };
44 
45     static void Copy(SkPDF::StructureElementNode& node,
46                      SkPDFTagNode* dst,
47                      SkArenaAlloc* arena,
48                      SkTHashMap<int, SkPDFTagNode*>* nodeMap);
49     SkPDFIndirectReference PrepareTagTreeToEmit(SkPDFIndirectReference parent,
50                                                 SkPDFTagNode* node,
51                                                 SkPDFDocument* doc);
52 
53     SkArenaAlloc fArena;
54     SkTHashMap<int, SkPDFTagNode*> fNodeMap;
55     SkPDFTagNode* fRoot = nullptr;
56     SkTArray<SkTArray<SkPDFTagNode*>> fMarksPerPage;
57     std::vector<IDTreeEntry> fIdTreeEntries;
58     std::vector<int> fParentTreeAnnotationNodeIds;
59 
60     SkPDFTagTree(const SkPDFTagTree&) = delete;
61     SkPDFTagTree& operator=(const SkPDFTagTree&) = delete;
62 };
63 
64 #endif
65