| 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 |
#include "src/pdf/SkPDFFormXObject.h" |
| 9 |
|
| 10 |
#include "include/core/SkMatrix.h" |
| 11 |
#include "include/core/SkStream.h" |
| 12 |
#include "src/pdf/SkPDFUtils.h" |
| 13 |
|
| 14 |
#include <utility> |
| 15 |
|
| 16 |
SkPDFIndirectReference SkPDFMakeFormXObject(SkPDFDocument* doc, |
| 17 |
std::unique_ptr<SkStreamAsset> content, |
| 18 |
std::unique_ptr<SkPDFArray> mediaBox, |
| 19 |
std::unique_ptr<SkPDFDict> resourceDict, |
| 20 |
const SkMatrix& inverseTransform, |
| 21 |
const char* colorSpace) { |
| 22 |
std::unique_ptr<SkPDFDict> dict = SkPDFMakeDict(); |
| 23 |
dict->insertName("Type", "XObject"); |
| 24 |
dict->insertName("Subtype", "Form"); |
| 25 |
if (!inverseTransform.isIdentity()) { |
| 26 |
dict->insertObject("Matrix", SkPDFUtils::MatrixToArray(inverseTransform)); |
| 27 |
} |
| 28 |
dict->insertObject("Resources", std::move(resourceDict)); |
| 29 |
dict->insertObject("BBox", std::move(mediaBox)); |
| 30 |
|
| 31 |
// Right now FormXObject is only used for saveLayer, which implies |
| 32 |
// isolated blending. Do this conditionally if that changes. |
| 33 |
// TODO(halcanary): Is this comment obsolete, since we use it for |
| 34 |
// alpha masks? |
| 35 |
auto group = SkPDFMakeDict("Group"); |
| 36 |
group->insertName("S", "Transparency"); |
| 37 |
if (colorSpace != nullptr) { |
| 38 |
group->insertName("CS", colorSpace); |
| 39 |
} |
| 40 |
group->insertBool("I", true); // Isolated. |
| 41 |
dict->insertObject("Group", std::move(group)); |
| 42 |
return SkPDFStreamOut(std::move(dict), std::move(content), doc); |
| 43 |
} |