SkPDF: flip saveLayer rightside up
authorhalcanary <halcanary@google.com>
Fri, 29 Jul 2016 15:41:33 +0000 (08:41 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 29 Jul 2016 15:41:33 +0000 (08:41 -0700)
Broken in https://skia.googlesource.com/skia/+/4b1e17e

BUG=632574
TBR=tomhudson@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2197623002

Review-Url: https://codereview.chromium.org/2197623002

src/pdf/SkPDFDevice.cpp
src/pdf/SkPDFFormXObject.cpp
src/pdf/SkPDFFormXObject.h
src/pdf/SkPDFShader.cpp

index 92f1907..1720cd8 100644 (file)
@@ -1588,9 +1588,16 @@ void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const {
 }
 
 sk_sp<SkPDFObject> SkPDFDevice::makeFormXObjectFromDevice() {
+    SkMatrix inverseTransform = SkMatrix::I();
+    if (!this->initialTransform().isIdentity()) {
+        if (!this->initialTransform().invert(&inverseTransform)) {
+            SkDEBUGFAIL("Layer initial transform should be invertible.");
+            inverseTransform.reset();
+        }
+    }
     sk_sp<SkPDFObject> xobject =
         SkPDFMakeFormXObject(this->content(), this->copyMediaBox(),
-                             this->makeResourceDict(), nullptr);
+                             this->makeResourceDict(), inverseTransform, nullptr);
     // We always draw the form xobjects that we create back into the device, so
     // we simply preserve the font usage instead of pulling it out and merging
     // it back in later.
index 1ab391c..e6445f5 100644 (file)
@@ -7,14 +7,20 @@
 
 
 #include "SkPDFFormXObject.h"
+#include "SkPDFUtils.h"
 
 sk_sp<SkPDFObject> SkPDFMakeFormXObject(std::unique_ptr<SkStreamAsset> content,
                                         sk_sp<SkPDFArray> mediaBox,
                                         sk_sp<SkPDFDict> resourceDict,
+                                        const SkMatrix& inverseTransform,
                                         const char* colorSpace) {
     auto form = sk_make_sp<SkPDFStream>(std::move(content));
     form->insertName("Type", "XObject");
     form->insertName("Subtype", "Form");
+    if (!inverseTransform.isIdentity()) {
+        form->insertObject("Matrix",
+                           SkPDFUtils::MatrixToArray(inverseTransform));
+    }
     form->insertObject("Resources", std::move(resourceDict));
     form->insertObject("BBox", std::move(mediaBox));
 
index 6ce8b87..c5e2505 100644 (file)
@@ -20,5 +20,6 @@
 sk_sp<SkPDFObject> SkPDFMakeFormXObject(std::unique_ptr<SkStreamAsset> content,
                                         sk_sp<SkPDFArray> mediaBox,
                                         sk_sp<SkPDFDict> resourceDict,
+                                        const SkMatrix& inverseTransform,
                                         const char* colorSpace);
 #endif
index 51d7442..612ff87 100644 (file)
@@ -706,6 +706,7 @@ static sk_sp<SkPDFObject> create_smask_graphic_state(
     auto alphaMask = SkPDFMakeFormXObject(std::move(alphaStream),
                                           SkPDFUtils::RectToArray(bbox),
                                           std::move(resources),
+                                          SkMatrix::I(),
                                           "DeviceRGB");
     return SkPDFGraphicState::GetSMaskGraphicState(
             alphaMask.get(), false,