Index: src/pdf/SkPDFFormXObject.cpp |
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp |
index 6958e276edd6b269d32b1791e5dcddbc8e029708..1635b0ff9649d102ec7e21e7638f9ddaf582003b 100644 |
--- a/src/pdf/SkPDFFormXObject.cpp |
+++ b/src/pdf/SkPDFFormXObject.cpp |
@@ -28,10 +28,8 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { |
SkAutoTUnref<SkStream> content(device->content()); |
setData(content.get()); |
- insertName("Type", "XObject"); |
- insertName("Subtype", "Form"); |
- SkSafeUnref(this->insert("BBox", device->copyMediaBox())); |
- insert("Resources", resourceDict); |
+ SkAutoTUnref<SkPDFArray> bboxArray(device->copyMediaBox()); |
+ init(NULL, resourceDict, bboxArray); |
// We invert the initial transform and apply that to the xobject so that |
// it doesn't get applied twice. We can't just undo it because it's |
@@ -45,11 +43,41 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { |
} |
insert("Matrix", SkPDFUtils::MatrixToArray(inverse))->unref(); |
} |
+} |
+ |
+/** |
+ * Creates a FormXObject from a content stream and associated resources. |
+ */ |
+SkPDFFormXObject::SkPDFFormXObject(SkStream* content, SkRect bbox, |
+ SkPDFResourceDict* resourceDict) { |
+ SkTSet<SkPDFObject*> emptySet; |
+ resourceDict->getReferencedResources(emptySet, &fResources, false); |
+ |
+ setData(content); |
+ |
+ SkAutoTUnref<SkPDFArray> bboxArray(SkPDFUtils::RectToArray(bbox)); |
+ init("DeviceRGB", resourceDict, bboxArray); |
+} |
+ |
+/** |
+ * Common initialization code. |
+ * Note that bbox is unreferenced here, so calling code does not need worry. |
+ */ |
+void SkPDFFormXObject::init(const char* colorSpace, |
+ SkPDFDict* resourceDict, SkPDFArray* bbox) { |
+ insertName("Type", "XObject"); |
+ insertName("Subtype", "Form"); |
+ insert("Resources", resourceDict); |
+ insert("BBox", bbox); |
// Right now SkPDFFormXObject is only used for saveLayer, which implies |
// isolated blending. Do this conditionally if that changes. |
SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group")); |
group->insertName("S", "Transparency"); |
+ |
+ if (colorSpace != NULL) { |
+ group->insertName("CS", colorSpace); |
+ } |
group->insert("I", new SkPDFBool(true))->unref(); // Isolated. |
insert("Group", group.get()); |
} |