| 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 "src/pdf/SkPDFFormXObject.h" |
| 10 | #include "src/pdf/SkPDFUtils.h" |
| 11 | |
| 12 | SkPDFIndirectReference SkPDFMakeFormXObject(SkPDFDocument* doc, |
| 13 | std::unique_ptr<SkStreamAsset> content, |
| 14 | std::unique_ptr<SkPDFArray> mediaBox, |
| 15 | std::unique_ptr<SkPDFDict> resourceDict, |
| 16 | const SkMatrix& inverseTransform, |
| 17 | const char* colorSpace) { |
| 18 | std::unique_ptr<SkPDFDict> dict = SkPDFMakeDict(); |
| 19 | dict->insertName("Type" , "XObject" ); |
| 20 | dict->insertName("Subtype" , "Form" ); |
| 21 | if (!inverseTransform.isIdentity()) { |
| 22 | dict->insertObject("Matrix" , SkPDFUtils::MatrixToArray(inverseTransform)); |
| 23 | } |
| 24 | dict->insertObject("Resources" , std::move(resourceDict)); |
| 25 | 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 | auto group = SkPDFMakeDict("Group" ); |
| 32 | group->insertName("S" , "Transparency" ); |
| 33 | if (colorSpace != nullptr) { |
| 34 | group->insertName("CS" , colorSpace); |
| 35 | } |
| 36 | group->insertBool("I" , true); // Isolated. |
| 37 | dict->insertObject("Group" , std::move(group)); |
| 38 | return SkPDFStreamOut(std::move(dict), std::move(content), doc); |
| 39 | } |
| 40 | |