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

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

Issue 18585002: Implemented transparent gradients (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 The Android Open Source Project 3 * Copyright 2010 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkPDFFormXObject.h" 10 #include "SkPDFFormXObject.h"
11 11
12 #include "SkMatrix.h" 12 #include "SkMatrix.h"
13 #include "SkPDFCatalog.h" 13 #include "SkPDFCatalog.h"
14 #include "SkPDFDevice.h" 14 #include "SkPDFDevice.h"
15 #include "SkPDFUtils.h" 15 #include "SkPDFUtils.h"
16 #include "SkStream.h" 16 #include "SkStream.h"
17 #include "SkTypes.h" 17 #include "SkTypes.h"
18 18
19 static SkPDFArray* rectToArray(SkRect rect) {
vandebo (ex-Chrome) 2013/07/03 17:07:01 Put this in SkPDFUtil and use it in SkPDFDevice::c
ducky 2013/07/03 23:32:09 Done.
20 SkPDFArray* mediaBox = SkNEW(SkPDFArray);
21 mediaBox->reserve(4);
22 mediaBox->appendScalar(rect.left());
23 mediaBox->appendScalar(rect.top());
24 mediaBox->appendScalar(rect.right());
25 mediaBox->appendScalar(rect.bottom());
26 return mediaBox;
27 }
28
19 SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { 29 SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
20 // We don't want to keep around device because we'd have two copies 30 // We don't want to keep around device because we'd have two copies
21 // of content, so reference or copy everything we need (content and 31 // of content, so reference or copy everything we need (content and
22 // resources). 32 // resources).
23 SkTSet<SkPDFObject*> emptySet; 33 SkTSet<SkPDFObject*> emptySet;
24 device->getResources(emptySet, &fResources, false); 34 device->getResources(emptySet, &fResources, false);
25 35
26 SkAutoTUnref<SkStream> content(device->content()); 36 SkAutoTUnref<SkStream> content(device->content());
27 setData(content.get()); 37 setData(content.get());
28 38
29 insertName("Type", "XObject"); 39 insertName("Type", "XObject");
30 insertName("Subtype", "Form"); 40 insertName("Subtype", "Form");
31 SkSafeUnref(this->insert("BBox", device->copyMediaBox())); 41 SkSafeUnref(this->insert("BBox", device->copyMediaBox()));
32 insert("Resources", device->getResourceDict()); 42 insert("Resources", device->getResourceDict());
33 43
34 // We invert the initial transform and apply that to the xobject so that 44 // We invert the initial transform and apply that to the xobject so that
35 // it doesn't get applied twice. We can't just undo it because it's 45 // it doesn't get applied twice. We can't just undo it because it's
36 // embedded in things like shaders and images. 46 // embedded in things like shaders and images.
37 if (!device->initialTransform().isIdentity()) { 47 if (!device->initialTransform().isIdentity()) {
vandebo (ex-Chrome) 2013/07/03 17:07:01 In your uses of the new constructor, do you take i
ducky 2013/07/03 23:32:09 I don't think there's a way to specify the initial
vandebo (ex-Chrome) 2013/07/08 19:02:25 Since SkGradientShader is implemented in terms of
38 SkMatrix inverse; 48 SkMatrix inverse;
39 if (!device->initialTransform().invert(&inverse)) { 49 if (!device->initialTransform().invert(&inverse)) {
40 // The initial transform should be invertible. 50 // The initial transform should be invertible.
41 SkASSERT(false); 51 SkASSERT(false);
42 inverse.reset(); 52 inverse.reset();
43 } 53 }
44 insert("Matrix", SkPDFUtils::MatrixToArray(inverse))->unref(); 54 insert("Matrix", SkPDFUtils::MatrixToArray(inverse))->unref();
45 } 55 }
46 56
47 // Right now SkPDFFormXObject is only used for saveLayer, which implies 57 // Right now SkPDFFormXObject is only used for saveLayer, which implies
48 // isolated blending. Do this conditionally if that changes. 58 // isolated blending. Do this conditionally if that changes.
49 SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group")); 59 SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group"));
50 group->insertName("S", "Transparency"); 60 group->insertName("S", "Transparency");
51 group->insert("I", new SkPDFBool(true))->unref(); // Isolated. 61 group->insert("I", new SkPDFBool(true))->unref(); // Isolated.
52 insert("Group", group.get()); 62 insert("Group", group.get());
53 } 63 }
54 64
65 /**
66 * Creates a FormXObject from a content stream and associated resources.
67 */
68 SkPDFFormXObject::SkPDFFormXObject(SkStream* content,
69 SkPDFDict* resourceDict,
70 SkTSet<SkPDFObject*>& resources,
71 SkRect bbox) {
72 setData(content);
vandebo (ex-Chrome) 2013/07/03 17:07:01 This whole body can be shared with the other const
ducky 2013/07/03 23:32:09 Done.
73 resourceDict->ref();
vandebo (ex-Chrome) 2013/07/03 17:07:01 This should be next to where the reference is used
ducky 2013/07/03 23:32:09 Done.
74
75 insertName("Type", "XObject");
76 insertName("Subtype", "Form");
77 SkSafeUnref(this->insert("BBox", rectToArray(bbox)));
78 insert("Resources", resourceDict);
79 fResources = resources;
80
81 // Right now SkPDFFormXObject is only used for saveLayer, which implies
82 // isolated blending. Do this conditionally if that changes.
83 SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group"));
84 group->insertName("S", "Transparency");
85 group->insertName("CS", "DeviceRGB");
86 group->insert("I", new SkPDFBool(true))->unref(); // Isolated.
87 insert("Group", group.get());
88 }
89
55 SkPDFFormXObject::~SkPDFFormXObject() { 90 SkPDFFormXObject::~SkPDFFormXObject() {
56 fResources.unrefAll(); 91 fResources.unrefAll();
57 } 92 }
58 93
59 void SkPDFFormXObject::getResources( 94 void SkPDFFormXObject::getResources(
60 const SkTSet<SkPDFObject*>& knownResourceObjects, 95 const SkTSet<SkPDFObject*>& knownResourceObjects,
61 SkTSet<SkPDFObject*>* newResourceObjects) { 96 SkTSet<SkPDFObject*>* newResourceObjects) {
62 GetResourcesHelper(&fResources.toArray(), 97 GetResourcesHelper(&fResources.toArray(),
63 knownResourceObjects, 98 knownResourceObjects,
64 newResourceObjects); 99 newResourceObjects);
65 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698