OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #ifndef SkPDFDocument_DEFINED | 7 #ifndef SkPDFDocument_DEFINED |
8 #define SkPDFDocument_DEFINED | 8 #define SkPDFDocument_DEFINED |
9 | 9 |
10 #include "SkDocument.h" | 10 #include "SkDocument.h" |
11 #include "SkPDFCanon.h" | 11 #include "SkPDFCanon.h" |
12 #include "SkPDFMetadata.h" | 12 #include "SkPDFMetadata.h" |
13 #include "SkPDFFont.h" | 13 #include "SkPDFFont.h" |
14 | 14 |
15 class SkPDFDevice; | 15 class SkPDFDevice; |
16 | 16 |
17 sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream, | 17 sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream, |
18 void (*doneProc)(SkWStream*, bool), | 18 void (*doneProc)(SkWStream*, bool), |
19 SkScalar rasterDpi, | 19 SkScalar rasterDpi, |
20 const SkDocument::PDFMetadata&, | 20 const SkDocument::PDFMetadata&, |
21 sk_sp<SkPixelSerializer>, | 21 sk_sp<SkPixelSerializer>, |
22 bool pdfa); | 22 bool pdfa); |
23 | 23 |
24 // Logically part of SkPDFDocument (like SkPDFCanon), but separate to | 24 // Logically part of SkPDFDocument (like SkPDFCanon), but separate to |
25 // keep similar functionality together. | 25 // keep similar functionality together. |
26 struct SkPDFObjectSerializer : SkNoncopyable { | 26 struct SkPDFObjectSerializer : SkNoncopyable { |
27 SkPDFObjNumMap fObjNumMap; | 27 SkPDFObjNumMap fObjNumMap; |
28 SkPDFSubstituteMap fSubstituteMap; | |
29 SkTDArray<int32_t> fOffsets; | 28 SkTDArray<int32_t> fOffsets; |
30 sk_sp<SkPDFObject> fInfoDict; | 29 sk_sp<SkPDFObject> fInfoDict; |
31 size_t fBaseOffset; | 30 size_t fBaseOffset; |
32 int32_t fNextToBeSerialized; // index in fObjNumMap | 31 int32_t fNextToBeSerialized; // index in fObjNumMap |
33 | 32 |
34 SkPDFObjectSerializer(); | 33 SkPDFObjectSerializer(); |
35 ~SkPDFObjectSerializer(); | 34 ~SkPDFObjectSerializer(); |
36 void addObjectRecursively(const sk_sp<SkPDFObject>&); | 35 void addObjectRecursively(const sk_sp<SkPDFObject>&); |
37 void serializeHeader(SkWStream*, const SkDocument::PDFMetadata&); | 36 void serializeHeader(SkWStream*, const SkDocument::PDFMetadata&); |
38 void serializeObjects(SkWStream*); | 37 void serializeObjects(SkWStream*); |
(...skipping 24 matching lines...) Expand all Loading... |
63 const SkTime::DateTime*) override; | 62 const SkTime::DateTime*) override; |
64 #endif // SK_SUPPORT_LEGACY_DOCUMENT_API | 63 #endif // SK_SUPPORT_LEGACY_DOCUMENT_API |
65 /** | 64 /** |
66 Serialize the object, as well as any other objects it | 65 Serialize the object, as well as any other objects it |
67 indirectly refers to. If any any other objects have been added | 66 indirectly refers to. If any any other objects have been added |
68 to the SkPDFObjNumMap without serializing them, they will be | 67 to the SkPDFObjNumMap without serializing them, they will be |
69 serialized as well. | 68 serialized as well. |
70 | 69 |
71 It might go without saying that objects should not be changed | 70 It might go without saying that objects should not be changed |
72 after calling serialize, since those changes will be too late. | 71 after calling serialize, since those changes will be too late. |
73 The same goes for changes to the SkPDFSubstituteMap that effect | |
74 the object or its dependencies. | |
75 */ | 72 */ |
76 void serialize(const sk_sp<SkPDFObject>&); | 73 void serialize(const sk_sp<SkPDFObject>&); |
77 SkPDFCanon* canon() { return &fCanon; } | 74 SkPDFCanon* canon() { return &fCanon; } |
78 SkPDFGlyphSetMap* getGlyphUsage() { return &fGlyphUsage; } | 75 void registerFont(SkPDFFont* f) { fFonts.add(f); } |
79 | 76 |
80 private: | 77 private: |
81 SkPDFObjectSerializer fObjectSerializer; | 78 SkPDFObjectSerializer fObjectSerializer; |
82 SkPDFCanon fCanon; | 79 SkPDFCanon fCanon; |
83 SkPDFGlyphSetMap fGlyphUsage; | |
84 SkTArray<sk_sp<SkPDFDict>> fPages; | 80 SkTArray<sk_sp<SkPDFDict>> fPages; |
| 81 SkTHashSet<SkPDFFont*> fFonts; |
85 sk_sp<SkPDFDict> fDests; | 82 sk_sp<SkPDFDict> fDests; |
86 sk_sp<SkPDFDevice> fPageDevice; | 83 sk_sp<SkPDFDevice> fPageDevice; |
87 sk_sp<SkCanvas> fCanvas; | 84 sk_sp<SkCanvas> fCanvas; |
88 sk_sp<SkPDFObject> fID; | 85 sk_sp<SkPDFObject> fID; |
89 sk_sp<SkPDFObject> fXMP; | 86 sk_sp<SkPDFObject> fXMP; |
90 SkScalar fRasterDpi; | 87 SkScalar fRasterDpi; |
91 SkDocument::PDFMetadata fMetadata; | 88 SkDocument::PDFMetadata fMetadata; |
92 bool fPDFA; | 89 bool fPDFA; |
| 90 |
| 91 void reset(); |
93 }; | 92 }; |
94 | 93 |
95 #endif // SkPDFDocument_DEFINED | 94 #endif // SkPDFDocument_DEFINED |
OLD | NEW |