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( | 17 sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream, |
18 SkWStream* stream, | 18 void (*doneProc)(SkWStream*, bool), |
19 void (*doneProc)(SkWStream*, bool), | 19 SkScalar rasterDpi, |
20 SkScalar rasterDpi, | 20 const SkDocument::PDFMetadata&, |
21 SkPixelSerializer* jpegEncoder, | 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; | 28 SkPDFSubstituteMap fSubstituteMap; |
29 SkTDArray<int32_t> fOffsets; | 29 SkTDArray<int32_t> fOffsets; |
30 sk_sp<SkPDFObject> fInfoDict; | 30 sk_sp<SkPDFObject> fInfoDict; |
31 size_t fBaseOffset; | 31 size_t fBaseOffset; |
32 int32_t fNextToBeSerialized; // index in fObjNumMap | 32 int32_t fNextToBeSerialized; // index in fObjNumMap |
33 | 33 |
34 SkPDFObjectSerializer(); | 34 SkPDFObjectSerializer(); |
35 ~SkPDFObjectSerializer(); | 35 ~SkPDFObjectSerializer(); |
36 void addObjectRecursively(const sk_sp<SkPDFObject>&); | 36 void addObjectRecursively(const sk_sp<SkPDFObject>&); |
37 void serializeHeader(SkWStream*, const SkPDFMetadata&); | 37 void serializeHeader(SkWStream*, const SkDocument::PDFMetadata&); |
38 void serializeObjects(SkWStream*); | 38 void serializeObjects(SkWStream*); |
39 void serializeFooter(SkWStream*, const sk_sp<SkPDFObject>, sk_sp<SkPDFObject
>); | 39 void serializeFooter(SkWStream*, const sk_sp<SkPDFObject>, sk_sp<SkPDFObject
>); |
40 int32_t offset(SkWStream*); | 40 int32_t offset(SkWStream*); |
41 }; | 41 }; |
42 | 42 |
43 /** Concrete implementation of SkDocument that creates PDF files. This | 43 /** Concrete implementation of SkDocument that creates PDF files. This |
44 class does not produced linearized or optimized PDFs; instead it | 44 class does not produced linearized or optimized PDFs; instead it |
45 it attempts to use a minimum amount of RAM. */ | 45 it attempts to use a minimum amount of RAM. */ |
46 class SkPDFDocument : public SkDocument { | 46 class SkPDFDocument : public SkDocument { |
47 public: | 47 public: |
48 SkPDFDocument(SkWStream*, | 48 SkPDFDocument(SkWStream*, |
49 void (*)(SkWStream*, bool), | 49 void (*)(SkWStream*, bool), |
50 SkScalar, | 50 SkScalar, |
51 SkPixelSerializer*, | 51 const SkDocument::PDFMetadata&, |
| 52 sk_sp<SkPixelSerializer>, |
52 bool); | 53 bool); |
53 virtual ~SkPDFDocument(); | 54 virtual ~SkPDFDocument(); |
54 SkCanvas* onBeginPage(SkScalar, SkScalar, const SkRect&) override; | 55 SkCanvas* onBeginPage(SkScalar, SkScalar, const SkRect&) override; |
55 void onEndPage() override; | 56 void onEndPage() override; |
56 bool onClose(SkWStream*) override; | 57 bool onClose(SkWStream*) override; |
57 void onAbort() override; | 58 void onAbort() override; |
| 59 #ifdef SK_SUPPORT_LEGACY_DOCUMENT_API |
58 void setMetadata(const SkDocument::Attribute[], | 60 void setMetadata(const SkDocument::Attribute[], |
59 int, | 61 int, |
60 const SkTime::DateTime*, | 62 const SkTime::DateTime*, |
61 const SkTime::DateTime*) override; | 63 const SkTime::DateTime*) override; |
| 64 #endif // SK_SUPPORT_LEGACY_DOCUMENT_API |
62 /** | 65 /** |
63 Serialize the object, as well as any other objects it | 66 Serialize the object, as well as any other objects it |
64 indirectly refers to. If any any other objects have been added | 67 indirectly refers to. If any any other objects have been added |
65 to the SkPDFObjNumMap without serializing them, they will be | 68 to the SkPDFObjNumMap without serializing them, they will be |
66 serialized as well. | 69 serialized as well. |
67 | 70 |
68 It might go without saying that objects should not be changed | 71 It might go without saying that objects should not be changed |
69 after calling serialize, since those changes will be too late. | 72 after calling serialize, since those changes will be too late. |
70 The same goes for changes to the SkPDFSubstituteMap that effect | 73 The same goes for changes to the SkPDFSubstituteMap that effect |
71 the object or its dependencies. | 74 the object or its dependencies. |
72 */ | 75 */ |
73 void serialize(const sk_sp<SkPDFObject>&); | 76 void serialize(const sk_sp<SkPDFObject>&); |
74 SkPDFCanon* canon() { return &fCanon; } | 77 SkPDFCanon* canon() { return &fCanon; } |
75 | 78 |
76 private: | 79 private: |
77 SkPDFObjectSerializer fObjectSerializer; | 80 SkPDFObjectSerializer fObjectSerializer; |
78 SkPDFCanon fCanon; | 81 SkPDFCanon fCanon; |
79 SkPDFGlyphSetMap fGlyphUsage; | 82 SkPDFGlyphSetMap fGlyphUsage; |
80 SkTArray<sk_sp<SkPDFDict>> fPages; | 83 SkTArray<sk_sp<SkPDFDict>> fPages; |
81 sk_sp<SkPDFDict> fDests; | 84 sk_sp<SkPDFDict> fDests; |
82 sk_sp<SkPDFDevice> fPageDevice; | 85 sk_sp<SkPDFDevice> fPageDevice; |
83 sk_sp<SkCanvas> fCanvas; | 86 sk_sp<SkCanvas> fCanvas; |
84 sk_sp<SkPDFObject> fID; | 87 sk_sp<SkPDFObject> fID; |
85 sk_sp<SkPDFObject> fXMP; | 88 sk_sp<SkPDFObject> fXMP; |
86 SkScalar fRasterDpi; | 89 SkScalar fRasterDpi; |
87 SkPDFMetadata fMetadata; | 90 SkDocument::PDFMetadata fMetadata; |
88 bool fPDFA; | 91 bool fPDFA; |
89 }; | 92 }; |
90 | 93 |
91 #endif // SkPDFDocument_DEFINED | 94 #endif // SkPDFDocument_DEFINED |
OLD | NEW |