1 2 /* 3 * Copyright 2010 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #include "SkPDFFormXObject.h" 11 12 #include "SkMatrix.h" 13 #include "SkPDFCatalog.h" 14 #include "SkPDFDevice.h" 15 #include "SkPDFUtils.h" 16 #include "SkStream.h" 17 #include "SkTypes.h" 18 19 SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { 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 22 // resources). 23 device->getResources(&fResources); 24 25 SkRefPtr<SkStream> content = device->content(); 26 content->unref(); // SkRefPtr and content() both took a reference. 27 setData(content.get()); 28 29 insertName("Type", "XObject"); 30 insertName("Subtype", "Form"); 31 insert("BBox", device->getMediaBox().get()); 32 insert("Resources", device->getResourceDict()); 33 34 // 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 36 // embedded in things like shaders and images. 37 if (!device->initialTransform().isIdentity()) { 38 SkMatrix inverse; 39 inverse.reset(); 40 device->initialTransform().invert(&inverse); 41 insert("Matrix", SkPDFUtils::MatrixToArray(inverse))->unref(); 42 } 43 44 // Right now SkPDFFormXObject is only used for saveLayer, which implies 45 // isolated blending. Do this conditionally if that changes. 46 SkRefPtr<SkPDFDict> group = new SkPDFDict("Group"); 47 group->unref(); // SkRefPtr and new both took a reference. 48 group->insertName("S", "Transparency"); 49 group->insert("I", new SkPDFBool(true))->unref(); // Isolated. 50 insert("Group", group.get()); 51 } 52 53 SkPDFFormXObject::~SkPDFFormXObject() { 54 fResources.unrefAll(); 55 } 56 57 void SkPDFFormXObject::getResources(SkTDArray<SkPDFObject*>* resourceList) { 58 GetResourcesHelper(&fResources, resourceList); 59 } 60