vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 The Android Open Source Project |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 9 | #include "SkPDFFormXObject.h" |
halcanary | 5abbb44 | 2016-07-29 08:41:33 -0700 | [diff] [blame] | 10 | #include "SkPDFUtils.h" |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 11 | |
halcanary | 4b1e17e | 2016-07-27 14:49:46 -0700 | [diff] [blame] | 12 | sk_sp<SkPDFObject> SkPDFMakeFormXObject(std::unique_ptr<SkStreamAsset> content, |
| 13 | sk_sp<SkPDFArray> mediaBox, |
| 14 | sk_sp<SkPDFDict> resourceDict, |
halcanary | 5abbb44 | 2016-07-29 08:41:33 -0700 | [diff] [blame] | 15 | const SkMatrix& inverseTransform, |
halcanary | 4b1e17e | 2016-07-27 14:49:46 -0700 | [diff] [blame] | 16 | const char* colorSpace) { |
| 17 | auto form = sk_make_sp<SkPDFStream>(std::move(content)); |
halcanary | fa25106 | 2016-07-29 10:13:18 -0700 | [diff] [blame] | 18 | form->dict()->insertName("Type", "XObject"); |
| 19 | form->dict()->insertName("Subtype", "Form"); |
halcanary | 5abbb44 | 2016-07-29 08:41:33 -0700 | [diff] [blame] | 20 | if (!inverseTransform.isIdentity()) { |
halcanary | fa25106 | 2016-07-29 10:13:18 -0700 | [diff] [blame] | 21 | sk_sp<SkPDFObject> mat(SkPDFUtils::MatrixToArray(inverseTransform)); |
| 22 | form->dict()->insertObject("Matrix", std::move(mat)); |
halcanary | 5abbb44 | 2016-07-29 08:41:33 -0700 | [diff] [blame] | 23 | } |
halcanary | fa25106 | 2016-07-29 10:13:18 -0700 | [diff] [blame] | 24 | form->dict()->insertObject("Resources", std::move(resourceDict)); |
| 25 | form->dict()->insertObject("BBox", std::move(mediaBox)); |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 26 | |
halcanary | 4b1e17e | 2016-07-27 14:49:46 -0700 | [diff] [blame] | 27 | // Right now FormXObject is only used for saveLayer, which implies |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 28 | // isolated blending. Do this conditionally if that changes. |
halcanary | 4b1e17e | 2016-07-27 14:49:46 -0700 | [diff] [blame] | 29 | // TODO(halcanary): Is this comment obsolete, since we use it for |
| 30 | // alpha masks? |
halcanary | ece8392 | 2016-03-08 08:32:12 -0800 | [diff] [blame] | 31 | auto group = sk_make_sp<SkPDFDict>("Group"); |
vandebo@chromium.org | 06f7f40 | 2011-07-20 18:39:20 +0000 | [diff] [blame] | 32 | group->insertName("S", "Transparency"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 33 | if (colorSpace != nullptr) { |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 34 | group->insertName("CS", colorSpace); |
| 35 | } |
halcanary | a25b337 | 2015-04-27 14:00:09 -0700 | [diff] [blame] | 36 | group->insertBool("I", true); // Isolated. |
halcanary | fa25106 | 2016-07-29 10:13:18 -0700 | [diff] [blame] | 37 | form->dict()->insertObject("Group", std::move(group)); |
halcanary | 4b1e17e | 2016-07-27 14:49:46 -0700 | [diff] [blame] | 38 | return form; |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 39 | } |