Line data Source code
1 : /*
2 : * Copyright 2010 The Android Open Source Project
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 :
9 : #include "SkPDFFormXObject.h"
10 : #include "SkPDFUtils.h"
11 :
12 0 : sk_sp<SkPDFObject> SkPDFMakeFormXObject(std::unique_ptr<SkStreamAsset> content,
13 : sk_sp<SkPDFArray> mediaBox,
14 : sk_sp<SkPDFDict> resourceDict,
15 : const SkMatrix& inverseTransform,
16 : const char* colorSpace) {
17 0 : auto form = sk_make_sp<SkPDFStream>(std::move(content));
18 0 : form->dict()->insertName("Type", "XObject");
19 0 : form->dict()->insertName("Subtype", "Form");
20 0 : if (!inverseTransform.isIdentity()) {
21 0 : sk_sp<SkPDFObject> mat(SkPDFUtils::MatrixToArray(inverseTransform));
22 0 : form->dict()->insertObject("Matrix", std::move(mat));
23 : }
24 0 : form->dict()->insertObject("Resources", std::move(resourceDict));
25 0 : form->dict()->insertObject("BBox", std::move(mediaBox));
26 :
27 : // Right now FormXObject is only used for saveLayer, which implies
28 : // isolated blending. Do this conditionally if that changes.
29 : // TODO(halcanary): Is this comment obsolete, since we use it for
30 : // alpha masks?
31 0 : auto group = sk_make_sp<SkPDFDict>("Group");
32 0 : group->insertName("S", "Transparency");
33 0 : if (colorSpace != nullptr) {
34 0 : group->insertName("CS", colorSpace);
35 : }
36 0 : group->insertBool("I", true); // Isolated.
37 0 : form->dict()->insertObject("Group", std::move(group));
38 0 : return form;
39 : }
|