Index: src/pdf/SkPDFFormXObject.cpp |
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp |
index 884e6db2e4a1535c20d6f1dd62e87e637eceb2c1..f48a119f45645f6815a8943ea4717d52c69b5fbd 100644 |
--- a/src/pdf/SkPDFFormXObject.cpp |
+++ b/src/pdf/SkPDFFormXObject.cpp |
@@ -26,10 +26,7 @@ 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", device->getResourceDict()); |
+ init(NULL, device->getResourceDict(), device->copyMediaBox()); |
// 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 |
@@ -43,11 +40,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->ref(); |
vandebo (ex-Chrome)
2013/07/09 17:47:44
This ref is for the call to init, right? It shoul
ducky
2013/07/10 21:42:26
Done. The insert call should actually handle refin
|
+ resourceDict->getResources(emptySet, &fResources); |
+ |
+ setData(content); |
+ |
+ init("DeviceRGB", resourceDict, SkPDFUtils::RectToArray(bbox)); |
+} |
+ |
+/** |
+ * 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); |
+ SkSafeUnref(this->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()); |
} |