blob: fa159384dea80ec2729b710925313122c660c12f [file] [log] [blame]
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkPDFCatalog_DEFINED
18#define SkPDFCatalog_DEFINED
19
20#include "SkPDFTypes.h"
21#include "SkRefCnt.h"
22#include "SkTDArray.h"
23
24/** \class SkPDFCatalog
25
26 The PDF catalog object manages object numbers and when emitted to the
27 PDF stream, indexes all the objects in the file by offset.
28*/
29class SkPDFCatalog {
30public:
31 /** Create a PDF catalog.
32 */
33 SkPDFCatalog()
34 : fNextObjNum(1),
35 fStartedAssigningObjNums(false),
36 fAssigningFirstPageObjNums(false) {
37 }
38 virtual ~SkPDFCatalog() {}
39
40 /** Add the passed object to the catalog.
41 * @param obj The object to add.
42 * @param onFirstPage Is the object on the first page.
43 */
44 void addObject(SkPDFObject* obj, bool onFirstPage);
45
46 /** Output the object number for the passed object.
47 * @param obj The object of interest.
48 * @param stream The writable output stream to send the output to.
49 */
50 void emitObjectNumber(SkWStream* stream, SkPDFObject* obj);
51
52 /** Return the number of bytes that would be emitted for the passed
53 * object's object number.
54 * @param obj The object of interest
55 */
56 size_t getObjectNumberSize(SkPDFObject* obj);
57
58private:
59 struct Rec {
60 Rec(SkPDFObject* object, bool onFirstPage)
61 : fObject(object),
62 fFileOffset(0),
63 fObjNumAssigned(false),
64 fOnFirstPage(onFirstPage) {
65 }
66 SkPDFObject* fObject;
67 off_t fFileOffset;
68 bool fObjNumAssigned;
69 bool fOnFirstPage;
70 };
71
72 // TODO(vandebo) Make this a hash if it's a performance problem.
73 SkTDArray<struct Rec> fCatalog;
74
75 uint32_t fNextObjNum;
76 bool fStartedAssigningObjNums;
77 bool fAssigningFirstPageObjNums;
78
79 int findObjectIndex(SkPDFObject* obj) const;
80
81 int assignObjNum(SkPDFObject* obj);
82};
83
84#endif