Chromium Code Reviews| 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"); | |
| 30 insertName("Subtype", "Form"); | |
| 31 SkSafeUnref(this->insert("BBox", device->copyMediaBox())); | 29 SkSafeUnref(this->insert("BBox", device->copyMediaBox())); |
| 32 insert("Resources", device->getResourceDict()); | 30 insert("Resources", device->getResourceDict()); |
| 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 |
| 45 commonInit(NULL); | |
|
vandebo (ex-Chrome)
2013/07/08 19:02:25
nit: move to line 28
ducky
2013/07/09 02:56:23
Done.
| |
| 46 } | |
| 47 | |
| 48 /** | |
| 49 * Creates a FormXObject from a content stream and associated resources. | |
| 50 */ | |
| 51 SkPDFFormXObject::SkPDFFormXObject(SkData* content, SkRect bbox, | |
| 52 SkPDFResourceDict* resourceDict) { | |
| 53 SkTSet<SkPDFObject*> emptySet; | |
| 54 SkSafeUnref(this->insert("BBox", SkPDFUtils::RectToArray(bbox))); | |
| 55 insert("Resources", resourceDict); | |
| 56 resourceDict->ref(); | |
| 57 resourceDict->getResources(emptySet, &fResources); | |
| 58 | |
| 59 setData(content); | |
| 60 | |
| 61 commonInit("DeviceRGB"); | |
| 62 } | |
| 63 | |
| 64 void SkPDFFormXObject::commonInit(const char colorSpace[]) { | |
|
vandebo (ex-Chrome)
2013/07/08 19:02:25
pass as much as possible into init. i.e. bbox and
ducky
2013/07/09 02:56:23
Done. Though, it's still not a completely clean so
vandebo (ex-Chrome)
2013/07/09 17:47:44
As you pointed out at a different point, you proba
ducky
2013/07/10 21:42:26
Fixed. Ownership is no longer transferred, and the
| |
| 65 insertName("Type", "XObject"); | |
| 66 insertName("Subtype", "Form"); | |
| 67 | |
| 47 // Right now SkPDFFormXObject is only used for saveLayer, which implies | 68 // Right now SkPDFFormXObject is only used for saveLayer, which implies |
| 48 // isolated blending. Do this conditionally if that changes. | 69 // isolated blending. Do this conditionally if that changes. |
| 49 SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group")); | 70 SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group")); |
| 50 group->insertName("S", "Transparency"); | 71 group->insertName("S", "Transparency"); |
| 72 | |
| 73 if (colorSpace != NULL) { | |
| 74 group->insertName("CS", colorSpace); | |
| 75 } | |
| 51 group->insert("I", new SkPDFBool(true))->unref(); // Isolated. | 76 group->insert("I", new SkPDFBool(true))->unref(); // Isolated. |
| 52 insert("Group", group.get()); | 77 insert("Group", group.get()); |
| 53 } | 78 } |
| 54 | 79 |
| 55 SkPDFFormXObject::~SkPDFFormXObject() { | 80 SkPDFFormXObject::~SkPDFFormXObject() { |
| 56 fResources.unrefAll(); | 81 fResources.unrefAll(); |
| 57 } | 82 } |
| 58 | 83 |
| 59 void SkPDFFormXObject::getResources( | 84 void SkPDFFormXObject::getResources( |
| 60 const SkTSet<SkPDFObject*>& knownResourceObjects, | 85 const SkTSet<SkPDFObject*>& knownResourceObjects, |
| 61 SkTSet<SkPDFObject*>* newResourceObjects) { | 86 SkTSet<SkPDFObject*>* newResourceObjects) { |
| 62 GetResourcesHelper(&fResources.toArray(), | 87 GetResourcesHelper(&fResources.toArray(), |
| 63 knownResourceObjects, | 88 knownResourceObjects, |
| 64 newResourceObjects); | 89 newResourceObjects); |
| 65 } | 90 } |
| OLD | NEW |