blob: d0c7fe76c51d04937c23d7599f9c84df84f34053 [file] [log] [blame]
vandebo@chromium.orgeb6c7592010-10-26 19:54:45 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 The Android Open Source Project
vandebo@chromium.orgeb6c7592010-10-26 19:54:45 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
vandebo@chromium.orgeb6c7592010-10-26 19:54:45 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
vandebo@chromium.orgeb6c7592010-10-26 19:54:45 +00009#include "SkPDFFormXObject.h"
halcanary5abbb442016-07-29 08:41:33 -070010#include "SkPDFUtils.h"
vandebo@chromium.orgeb6c7592010-10-26 19:54:45 +000011
halcanary4b1e17e2016-07-27 14:49:46 -070012sk_sp<SkPDFObject> SkPDFMakeFormXObject(std::unique_ptr<SkStreamAsset> content,
13 sk_sp<SkPDFArray> mediaBox,
14 sk_sp<SkPDFDict> resourceDict,
halcanary5abbb442016-07-29 08:41:33 -070015 const SkMatrix& inverseTransform,
halcanary4b1e17e2016-07-27 14:49:46 -070016 const char* colorSpace) {
17 auto form = sk_make_sp<SkPDFStream>(std::move(content));
halcanaryfa251062016-07-29 10:13:18 -070018 form->dict()->insertName("Type", "XObject");
19 form->dict()->insertName("Subtype", "Form");
halcanary5abbb442016-07-29 08:41:33 -070020 if (!inverseTransform.isIdentity()) {
halcanaryfa251062016-07-29 10:13:18 -070021 sk_sp<SkPDFObject> mat(SkPDFUtils::MatrixToArray(inverseTransform));
22 form->dict()->insertObject("Matrix", std::move(mat));
halcanary5abbb442016-07-29 08:41:33 -070023 }
halcanaryfa251062016-07-29 10:13:18 -070024 form->dict()->insertObject("Resources", std::move(resourceDict));
25 form->dict()->insertObject("BBox", std::move(mediaBox));
vandebo@chromium.orgeb6c7592010-10-26 19:54:45 +000026
halcanary4b1e17e2016-07-27 14:49:46 -070027 // Right now FormXObject is only used for saveLayer, which implies
vandebo@chromium.org48543272011-02-08 19:28:07 +000028 // isolated blending. Do this conditionally if that changes.
halcanary4b1e17e2016-07-27 14:49:46 -070029 // TODO(halcanary): Is this comment obsolete, since we use it for
30 // alpha masks?
halcanaryece83922016-03-08 08:32:12 -080031 auto group = sk_make_sp<SkPDFDict>("Group");
vandebo@chromium.org06f7f402011-07-20 18:39:20 +000032 group->insertName("S", "Transparency");
halcanary96fcdcc2015-08-27 07:41:13 -070033 if (colorSpace != nullptr) {
commit-bot@chromium.org93a2e212013-07-23 23:16:03 +000034 group->insertName("CS", colorSpace);
35 }
halcanarya25b3372015-04-27 14:00:09 -070036 group->insertBool("I", true); // Isolated.
halcanaryfa251062016-07-29 10:13:18 -070037 form->dict()->insertObject("Group", std::move(group));
halcanary4b1e17e2016-07-27 14:49:46 -070038 return form;
vandebo@chromium.orgeb6c7592010-10-26 19:54:45 +000039}