Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: src/pdf/SkPDFFormXObject.cpp

Issue 2188623004: SkPDF: SkPDFStream takes a unique_ptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFFormXObject.h ('k') | src/pdf/SkPDFShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010 The Android Open Source Project 2 * Copyright 2010 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "SkPDFFormXObject.h" 9 #include "SkPDFFormXObject.h"
10 10
11 #include "SkMatrix.h" 11 #include "SkMatrix.h"
12 #include "SkPDFDevice.h" 12 #include "SkPDFDevice.h"
13 #include "SkPDFUtils.h" 13 #include "SkPDFUtils.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 #include "SkTypes.h" 15 #include "SkTypes.h"
16 16
17 SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { 17 SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
18 // We don't want to keep around device because we'd have two copies 18 // We don't want to keep around device because we'd have two copies
19 // of content, so reference or copy everything we need (content and 19 // of content, so reference or copy everything we need (content and
20 // resources). 20 // resources).
21 auto resourceDict = device->makeResourceDict(); 21 auto resourceDict = device->makeResourceDict();
22 22
23 auto content = device->content(); 23 this->setData(device->content());
24 this->setData(content.get());
25 24
26 sk_sp<SkPDFArray> bboxArray(device->copyMediaBox()); 25 sk_sp<SkPDFArray> bboxArray(device->copyMediaBox());
27 this->init(nullptr, resourceDict.get(), bboxArray.get()); 26 this->init(nullptr, resourceDict.get(), bboxArray.get());
28 27
29 // We invert the initial transform and apply that to the xobject so that 28 // We invert the initial transform and apply that to the xobject so that
30 // it doesn't get applied twice. We can't just undo it because it's 29 // it doesn't get applied twice. We can't just undo it because it's
31 // embedded in things like shaders and images. 30 // embedded in things like shaders and images.
32 if (!device->initialTransform().isIdentity()) { 31 if (!device->initialTransform().isIdentity()) {
33 SkMatrix inverse; 32 SkMatrix inverse;
34 if (!device->initialTransform().invert(&inverse)) { 33 if (!device->initialTransform().invert(&inverse)) {
35 // The initial transform should be invertible. 34 // The initial transform should be invertible.
36 SkASSERT(false); 35 SkASSERT(false);
37 inverse.reset(); 36 inverse.reset();
38 } 37 }
39 this->insertObject("Matrix", SkPDFUtils::MatrixToArray(inverse)); 38 this->insertObject("Matrix", SkPDFUtils::MatrixToArray(inverse));
40 } 39 }
41 } 40 }
42 41
43 /** 42 /**
44 * Creates a FormXObject from a content stream and associated resources. 43 * Creates a FormXObject from a content stream and associated resources.
45 */ 44 */
46 SkPDFFormXObject::SkPDFFormXObject(SkStreamAsset* content, SkRect bbox, 45 SkPDFFormXObject::SkPDFFormXObject(std::unique_ptr<SkStreamAsset> content,
46 SkRect bbox,
47 SkPDFDict* resourceDict) { 47 SkPDFDict* resourceDict) {
48 setData(content); 48 this->setData(std::move(content));
49
50 sk_sp<SkPDFArray> bboxArray(SkPDFUtils::RectToArray(bbox)); 49 sk_sp<SkPDFArray> bboxArray(SkPDFUtils::RectToArray(bbox));
51 this->init("DeviceRGB", resourceDict, bboxArray.get()); 50 this->init("DeviceRGB", resourceDict, bboxArray.get());
52 } 51 }
53 52
54 /** 53 /**
55 * Common initialization code. 54 * Common initialization code.
56 * Note that bbox is unreferenced here, so calling code does not need worry. 55 * Note that bbox is unreferenced here, so calling code does not need worry.
57 */ 56 */
58 void SkPDFFormXObject::init(const char* colorSpace, 57 void SkPDFFormXObject::init(const char* colorSpace,
59 SkPDFDict* resourceDict, SkPDFArray* bbox) { 58 SkPDFDict* resourceDict, SkPDFArray* bbox) {
60 this->insertName("Type", "XObject"); 59 this->insertName("Type", "XObject");
61 this->insertName("Subtype", "Form"); 60 this->insertName("Subtype", "Form");
62 this->insertObject("Resources", sk_ref_sp(resourceDict)); 61 this->insertObject("Resources", sk_ref_sp(resourceDict));
63 this->insertObject("BBox", sk_ref_sp(bbox)); 62 this->insertObject("BBox", sk_ref_sp(bbox));
64 63
65 // Right now SkPDFFormXObject is only used for saveLayer, which implies 64 // Right now SkPDFFormXObject is only used for saveLayer, which implies
66 // isolated blending. Do this conditionally if that changes. 65 // isolated blending. Do this conditionally if that changes.
67 auto group = sk_make_sp<SkPDFDict>("Group"); 66 auto group = sk_make_sp<SkPDFDict>("Group");
68 group->insertName("S", "Transparency"); 67 group->insertName("S", "Transparency");
69 68
70 if (colorSpace != nullptr) { 69 if (colorSpace != nullptr) {
71 group->insertName("CS", colorSpace); 70 group->insertName("CS", colorSpace);
72 } 71 }
73 group->insertBool("I", true); // Isolated. 72 group->insertBool("I", true); // Isolated.
74 this->insertObject("Group", std::move(group)); 73 this->insertObject("Group", std::move(group));
75 } 74 }
76 75
77 SkPDFFormXObject::~SkPDFFormXObject() {} 76 SkPDFFormXObject::~SkPDFFormXObject() {}
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFormXObject.h ('k') | src/pdf/SkPDFShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698