Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: src/pdf/SkPDFCatalog.h

Issue 1033543002: SKPDF: refactor pdfcatalog and pdfdocument (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-03-25 (Wednesday) 14:17:42 EDT Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pdf/SkPDFCatalog.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 The Android Open Source Project 3 * Copyright 2010 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkPDFCatalog_DEFINED 10 #ifndef SkPDFCatalog_DEFINED
11 #define SkPDFCatalog_DEFINED 11 #define SkPDFCatalog_DEFINED
12 12
13 #include <sys/types.h>
14
15 #include "SkPDFTypes.h" 13 #include "SkPDFTypes.h"
16 #include "SkTDArray.h" 14 #include "SkTDArray.h"
15 #include "SkTHash.h"
17 16
18 /** \class SkPDFCatalog 17 /** \class SkPDFCatalog
19 18
20 The PDF catalog manages object numbers and file offsets. It is used 19 The PDF catalog manages object numbers. It is used
21 to create the PDF cross reference table. 20 to create the PDF cross reference table.
22 */ 21 */
23 class SkPDFCatalog { 22 class SkPDFCatalog {
24 public: 23 public:
25 /** Create a PDF catalog.
26 */
27 SkPDFCatalog(); 24 SkPDFCatalog();
28 ~SkPDFCatalog(); 25 ~SkPDFCatalog();
29 26
30 /** Add the passed object to the catalog. Refs obj. 27 /** Add the passed object to the catalog.
31 * @param obj The object to add. 28 * @param obj The object to add.
32 * @param onFirstPage Is the object on the first page. 29 * @return True iff the object was not already added to the catalog.
33 * @return The obj argument is returned.
34 */ 30 */
35 SkPDFObject* addObject(SkPDFObject* obj, bool onFirstPage); 31 bool addObject(SkPDFObject* obj);
36
37 /** Inform the catalog of the object's position in the final stream.
38 * The object should already have been added to the catalog.
39 * @param obj The object to add.
40 * @param offset The byte offset in the output stream of this object.
41 */
42 void setFileOffset(SkPDFObject* obj, off_t offset);
43 32
44 /** Get the object number for the passed object. 33 /** Get the object number for the passed object.
45 * @param obj The object of interest. 34 * @param obj The object of interest.
46 */ 35 */
47 int32_t getObjectNumber(SkPDFObject* obj); 36 int32_t getObjectNumber(SkPDFObject* obj) const;
48
49 /** Output the cross reference table for objects in the catalog.
50 * Returns the total number of objects.
51 * @param stream The writable output stream to send the output to.
52 * @param firstPage If true, include first page objects only, otherwise
53 * include all objects not on the first page.
54 */
55 int32_t emitXrefTable(SkWStream* stream, bool firstPage);
56 37
57 /** Set substitute object for the passed object. 38 /** Set substitute object for the passed object.
39 Refs substitute.
58 */ 40 */
59 void setSubstitute(SkPDFObject* original, SkPDFObject* substitute); 41 void setSubstitute(SkPDFObject* original, SkPDFObject* substitute);
60 42
61 /** Find and return any substitute object set for the passed object. If 43 /** Find and return any substitute object set for the passed object. If
62 * there is none, return the passed object. 44 * there is none, return the passed object.
63 */ 45 */
64 SkPDFObject* getSubstituteObject(SkPDFObject* object); 46 SkPDFObject* getSubstituteObject(SkPDFObject* object) const;
65 47
66 private: 48 private:
67 struct Rec { 49 SkTHashMap<SkPDFObject*, int32_t> fObjectNumbers;
68 Rec(SkPDFObject* object, bool onFirstPage) 50 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap;
69 : fObject(object),
70 fFileOffset(0),
71 fObjNumAssigned(false),
72 fOnFirstPage(onFirstPage) {
73 }
74 SkPDFObject* fObject;
75 off_t fFileOffset;
76 bool fObjNumAssigned;
77 bool fOnFirstPage;
78 };
79
80 struct SubstituteMapping {
81 SubstituteMapping(SkPDFObject* original, SkPDFObject* substitute)
82 : fOriginal(original), fSubstitute(substitute) {
83 }
84 SkPDFObject* fOriginal;
85 SkPDFObject* fSubstitute;
86 };
87
88 // TODO(vandebo): Make this a hash if it's a performance problem.
89 SkTDArray<Rec> fCatalog;
90
91 // TODO(arthurhsu): Make this a hash if it's a performance problem.
92 SkTDArray<SubstituteMapping> fSubstituteMap;
93 SkTSet<SkPDFObject*> fSubstituteResourcesFirstPage;
94 SkTSet<SkPDFObject*> fSubstituteResourcesRemaining;
95
96 // Number of objects on the first page.
97 uint32_t fFirstPageCount;
98 // Next object number to assign (on page > 1).
99 uint32_t fNextObjNum;
100 // Next object number to assign on the first page.
101 uint32_t fNextFirstPageObjNum;
102
103 int findObjectIndex(SkPDFObject* obj);
104
105 int assignObjNum(SkPDFObject* obj);
106 }; 51 };
107 52
108 #endif 53 #endif
OLDNEW
« no previous file with comments | « no previous file | src/pdf/SkPDFCatalog.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698