OLD | NEW |
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 #include "SkPDFFormXObject.h" | 10 #include "SkPDFFormXObject.h" |
11 | 11 |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 #include "SkPDFCatalog.h" | 13 #include "SkPDFCatalog.h" |
14 #include "SkPDFDevice.h" | 14 #include "SkPDFDevice.h" |
15 #include "SkPDFResourceDict.h" | 15 #include "SkPDFResourceDict.h" |
16 #include "SkPDFUtils.h" | 16 #include "SkPDFUtils.h" |
17 #include "SkStream.h" | 17 #include "SkStream.h" |
18 #include "SkTypes.h" | 18 #include "SkTypes.h" |
19 | 19 |
20 SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { | 20 SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { |
21 // We don't want to keep around device because we'd have two copies | 21 // We don't want to keep around device because we'd have two copies |
22 // of content, so reference or copy everything we need (content and | 22 // of content, so reference or copy everything we need (content and |
23 // resources). | 23 // resources). |
24 SkTSet<SkPDFObject*> emptySet; | |
25 SkPDFResourceDict* resourceDict = device->getResourceDict(); | 24 SkPDFResourceDict* resourceDict = device->getResourceDict(); |
26 resourceDict->getReferencedResources(emptySet, &fResources, false); | |
27 | 25 |
28 SkAutoTDelete<SkStream> content(device->content()); | 26 SkAutoTDelete<SkStream> content(device->content()); |
29 setData(content.get()); | 27 setData(content.get()); |
30 | 28 |
31 SkAutoTUnref<SkPDFArray> bboxArray(device->copyMediaBox()); | 29 SkAutoTUnref<SkPDFArray> bboxArray(device->copyMediaBox()); |
32 init(NULL, resourceDict, bboxArray); | 30 init(NULL, resourceDict, bboxArray); |
33 | 31 |
34 // We invert the initial transform and apply that to the xobject so that | 32 // We invert the initial transform and apply that to the xobject so that |
35 // it doesn't get applied twice. We can't just undo it because it's | 33 // it doesn't get applied twice. We can't just undo it because it's |
36 // embedded in things like shaders and images. | 34 // embedded in things like shaders and images. |
37 if (!device->initialTransform().isIdentity()) { | 35 if (!device->initialTransform().isIdentity()) { |
38 SkMatrix inverse; | 36 SkMatrix inverse; |
39 if (!device->initialTransform().invert(&inverse)) { | 37 if (!device->initialTransform().invert(&inverse)) { |
40 // The initial transform should be invertible. | 38 // The initial transform should be invertible. |
41 SkASSERT(false); | 39 SkASSERT(false); |
42 inverse.reset(); | 40 inverse.reset(); |
43 } | 41 } |
44 insert("Matrix", SkPDFUtils::MatrixToArray(inverse))->unref(); | 42 insert("Matrix", SkPDFUtils::MatrixToArray(inverse))->unref(); |
45 } | 43 } |
46 } | 44 } |
47 | 45 |
48 /** | 46 /** |
49 * Creates a FormXObject from a content stream and associated resources. | 47 * Creates a FormXObject from a content stream and associated resources. |
50 */ | 48 */ |
51 SkPDFFormXObject::SkPDFFormXObject(SkStream* content, SkRect bbox, | 49 SkPDFFormXObject::SkPDFFormXObject(SkStream* content, SkRect bbox, |
52 SkPDFResourceDict* resourceDict) { | 50 SkPDFResourceDict* resourceDict) { |
53 SkTSet<SkPDFObject*> emptySet; | |
54 resourceDict->getReferencedResources(emptySet, &fResources, false); | |
55 | |
56 setData(content); | 51 setData(content); |
57 | 52 |
58 SkAutoTUnref<SkPDFArray> bboxArray(SkPDFUtils::RectToArray(bbox)); | 53 SkAutoTUnref<SkPDFArray> bboxArray(SkPDFUtils::RectToArray(bbox)); |
59 init("DeviceRGB", resourceDict, bboxArray); | 54 init("DeviceRGB", resourceDict, bboxArray); |
60 } | 55 } |
61 | 56 |
62 /** | 57 /** |
63 * Common initialization code. | 58 * Common initialization code. |
64 * Note that bbox is unreferenced here, so calling code does not need worry. | 59 * Note that bbox is unreferenced here, so calling code does not need worry. |
65 */ | 60 */ |
66 void SkPDFFormXObject::init(const char* colorSpace, | 61 void SkPDFFormXObject::init(const char* colorSpace, |
67 SkPDFDict* resourceDict, SkPDFArray* bbox) { | 62 SkPDFDict* resourceDict, SkPDFArray* bbox) { |
68 insertName("Type", "XObject"); | 63 insertName("Type", "XObject"); |
69 insertName("Subtype", "Form"); | 64 insertName("Subtype", "Form"); |
70 insert("Resources", resourceDict); | 65 insert("Resources", resourceDict); |
71 insert("BBox", bbox); | 66 insert("BBox", bbox); |
72 | 67 |
73 // Right now SkPDFFormXObject is only used for saveLayer, which implies | 68 // Right now SkPDFFormXObject is only used for saveLayer, which implies |
74 // isolated blending. Do this conditionally if that changes. | 69 // isolated blending. Do this conditionally if that changes. |
75 SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group")); | 70 SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group")); |
76 group->insertName("S", "Transparency"); | 71 group->insertName("S", "Transparency"); |
77 | 72 |
78 if (colorSpace != NULL) { | 73 if (colorSpace != NULL) { |
79 group->insertName("CS", colorSpace); | 74 group->insertName("CS", colorSpace); |
80 } | 75 } |
81 group->insert("I", new SkPDFBool(true))->unref(); // Isolated. | 76 group->insert("I", new SkPDFBool(true))->unref(); // Isolated. |
82 insert("Group", group.get()); | 77 insert("Group", group.get()); |
83 } | 78 } |
84 | 79 |
85 SkPDFFormXObject::~SkPDFFormXObject() { | 80 SkPDFFormXObject::~SkPDFFormXObject() {} |
86 fResources.unrefAll(); | |
87 } | |
88 | |
89 void SkPDFFormXObject::getResources( | |
90 const SkTSet<SkPDFObject*>& knownResourceObjects, | |
91 SkTSet<SkPDFObject*>* newResourceObjects) { | |
92 GetResourcesHelper(&fResources.toArray(), | |
93 knownResourceObjects, | |
94 newResourceObjects); | |
95 } | |
OLD | NEW |