aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFFormXObject.cpp
blob: 99146a29f354ad888a39e6d4d3ed368274cd6da6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * Copyright 2010 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#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->dict()->insertName("Type", "XObject");
    form->dict()->insertName("Subtype", "Form");
    if (!inverseTransform.isIdentity()) {
        sk_sp<SkPDFObject> mat(SkPDFUtils::MatrixToArray(inverseTransform));
        form->dict()->insertObject("Matrix", std::move(mat));
    }
    form->dict()->insertObject("Resources", std::move(resourceDict));
    form->dict()->insertObject("BBox", std::move(mediaBox));

    // Right now FormXObject is only used for saveLayer, which implies
    // isolated blending.  Do this conditionally if that changes.
    // TODO(halcanary): Is this comment obsolete, since we use it for
    // alpha masks?
    auto group = sk_make_sp<SkPDFDict>("Group");
    group->insertName("S", "Transparency");
    if (colorSpace != nullptr) {
        group->insertName("CS", colorSpace);
    }
    group->insertBool("I", true);  // Isolated.
    form->dict()->insertObject("Group", std::move(group));
    return std::move(form);
}