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