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