OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 #include "SkPDFResourceDict.h" | 8 #include "SkPDFResourceDict.h" |
9 #include "SkPostConfig.h" | 9 #include "SkPostConfig.h" |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 SkPDFObject* SkPDFResourceDict::insertResourceAsReference( | 71 SkPDFObject* SkPDFResourceDict::insertResourceAsReference( |
72 SkPDFResourceType type, int key, SkPDFObject* value) { | 72 SkPDFResourceType type, int key, SkPDFObject* value) { |
73 SkAutoTUnref<SkPDFObjRef> ref(SkNEW_ARGS(SkPDFObjRef, (value))); | 73 SkAutoTUnref<SkPDFObjRef> ref(SkNEW_ARGS(SkPDFObjRef, (value))); |
74 insertResource(type, key, ref); | 74 insertResource(type, key, ref); |
75 fResources.add(value); | 75 fResources.add(value); |
76 | 76 |
77 return value; | 77 return value; |
78 } | 78 } |
79 | 79 |
80 void SkPDFResourceDict::getReferencedResources( | |
81 const SkTSet<SkPDFObject*>& knownResourceObjects, | |
82 SkTSet<SkPDFObject*>* newResourceObjects, | |
83 bool recursive) const { | |
84 // TODO: reserve not correct if we need to recursively explore. | |
85 newResourceObjects->setReserve(newResourceObjects->count() + | |
86 fResources.count()); | |
87 | |
88 for (int i = 0; i < fResources.count(); i++) { | |
89 if (!knownResourceObjects.contains(fResources[i]) && | |
90 !newResourceObjects->contains(fResources[i])) { | |
91 newResourceObjects->add(fResources[i]); | |
92 fResources[i]->ref(); | |
93 if (recursive) { | |
94 fResources[i]->getResources(knownResourceObjects, | |
95 newResourceObjects); | |
96 } | |
97 } | |
98 } | |
99 } | |
100 | |
101 SkString SkPDFResourceDict::getResourceName( | 80 SkString SkPDFResourceDict::getResourceName( |
102 SkPDFResourceType type, int key) { | 81 SkPDFResourceType type, int key) { |
103 SkString keyString; | 82 SkString keyString; |
104 keyString.printf("%c%d", get_resource_type_prefix(type), key); | 83 keyString.printf("%c%d", get_resource_type_prefix(type), key); |
105 return keyString; | 84 return keyString; |
106 } | 85 } |
107 | 86 |
108 SkPDFObject* SkPDFResourceDict::insertResource( | 87 SkPDFObject* SkPDFResourceDict::insertResource( |
109 SkPDFResourceType type, int key, SkPDFObject* value) { | 88 SkPDFResourceType type, int key, SkPDFObject* value) { |
110 SkPDFDict* typeDict = fTypes[type]; | 89 SkPDFDict* typeDict = fTypes[type]; |
111 if (NULL == typeDict) { | 90 if (NULL == typeDict) { |
112 SkAutoTUnref<SkPDFDict> newDict(SkNEW(SkPDFDict())); | 91 SkAutoTUnref<SkPDFDict> newDict(SkNEW(SkPDFDict())); |
113 SkAutoTUnref<SkPDFName> typeName( | 92 SkAutoTUnref<SkPDFName> typeName( |
114 SkNEW_ARGS(SkPDFName, (get_resource_type_name(type)))); | 93 SkNEW_ARGS(SkPDFName, (get_resource_type_name(type)))); |
115 insert(typeName, newDict); // ref counting handled here | 94 insert(typeName, newDict); // ref counting handled here |
116 fTypes[type] = newDict; | 95 fTypes[type] = newDict; |
117 typeDict = newDict.get(); | 96 typeDict = newDict.get(); |
118 } | 97 } |
119 | 98 |
120 SkAutoTUnref<SkPDFName> keyName( | 99 SkAutoTUnref<SkPDFName> keyName( |
121 SkNEW_ARGS(SkPDFName, (getResourceName(type, key)))); | 100 SkNEW_ARGS(SkPDFName, (getResourceName(type, key)))); |
122 typeDict->insert(keyName, value); | 101 typeDict->insert(keyName, value); |
123 return value; | 102 return value; |
124 } | 103 } |
OLD | NEW |