Implemented transparent gradients
R=vandebo@chromium.org, edisonn@google.com
Author: richardlin@chromium.org
Review URL: https://chromiumcodereview.appspot.com/18585002
git-svn-id: http://skia.googlecode.com/svn/trunk@10297 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp
index 6958e27..1635b0f 100644
--- a/src/pdf/SkPDFFormXObject.cpp
+++ b/src/pdf/SkPDFFormXObject.cpp
@@ -28,10 +28,8 @@
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 @@
}
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());
}