Index: src/pdf/SkPDFFormXObject.cpp |
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp |
index f31b90b79c389be4c46952261f59de25b16921b3..0dc5895a6a63cc09d91de23732d70fa4f95e3c62 100644 |
--- a/src/pdf/SkPDFFormXObject.cpp |
+++ b/src/pdf/SkPDFFormXObject.cpp |
@@ -28,10 +28,8 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { |
SkAutoTUnref<SkData> content(device->copyContentToData()); |
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(SkData* content, SkRect bbox, |
+ SkPDFResourceDict* resourceDict) { |
+ SkTSet<SkPDFObject*> emptySet; |
+ resourceDict->getResources(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()); |
} |