OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
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 "SkPDFCatalog.h" | 10 #include "SkPDFCatalog.h" |
11 #include "SkPDFTypes.h" | 11 #include "SkPDFTypes.h" |
12 #include "SkStream.h" | 12 #include "SkStream.h" |
13 | 13 |
14 #ifdef SK_BUILD_FOR_WIN | 14 #ifdef SK_BUILD_FOR_WIN |
15 #define SNPRINTF _snprintf | 15 #define SNPRINTF _snprintf |
16 #else | 16 #else |
17 #define SNPRINTF snprintf | 17 #define SNPRINTF snprintf |
18 #endif | 18 #endif |
19 | 19 |
20 /////////////////////////////////////////////////////////////////////////////// | 20 /////////////////////////////////////////////////////////////////////////////// |
21 | 21 |
22 void SkPDFObject::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, | 22 void SkPDFObject::addResources(SkPDFObjectSet*, SkPDFCatalog*) {} |
23 SkTSet<SkPDFObject*>* newResourceObjects) {} | |
24 | |
25 void SkPDFObject::AddResourceHelper(SkPDFObject* resource, | |
26 SkTDArray<SkPDFObject*>* list) { | |
27 list->push(resource); | |
28 resource->ref(); | |
29 } | |
30 | |
31 void SkPDFObject::GetResourcesHelper( | |
32 const SkTDArray<SkPDFObject*>* resources, | |
33 const SkTSet<SkPDFObject*>& knownResourceObjects, | |
34 SkTSet<SkPDFObject*>* newResourceObjects) { | |
35 if (resources->count()) { | |
36 newResourceObjects->setReserve( | |
37 newResourceObjects->count() + resources->count()); | |
38 for (int i = 0; i < resources->count(); i++) { | |
39 if (!knownResourceObjects.contains((*resources)[i]) && | |
40 !newResourceObjects->contains((*resources)[i])) { | |
41 newResourceObjects->add((*resources)[i]); | |
42 (*resources)[i]->ref(); | |
43 (*resources)[i]->getResources(knownResourceObjects, | |
44 newResourceObjects); | |
45 } | |
46 } | |
47 } | |
48 } | |
49 | 23 |
50 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
51 | 25 |
52 SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) { | 26 SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) { |
53 SkSafeRef(obj); | 27 SkSafeRef(obj); |
54 } | 28 } |
55 | 29 |
56 SkPDFObjRef::~SkPDFObjRef() {} | 30 SkPDFObjRef::~SkPDFObjRef() {} |
57 | 31 |
58 void SkPDFObjRef::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { | 32 void SkPDFObjRef::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { |
59 catalog->emitObjectNumber(stream, fObj.get()); | 33 catalog->emitObjectNumber(stream, fObj.get()); |
60 stream->writeText(" R"); | 34 stream->writeText(" R"); |
61 } | 35 } |
62 | 36 |
| 37 void SkPDFObjRef::addResources(SkPDFObjectSet* resourceSet, |
| 38 SkPDFCatalog* catalog) { |
| 39 SkPDFObject* obj = catalog->getSubstituteObject(fObj); |
| 40 SkASSERT(obj); |
| 41 if (resourceSet->add(obj)) { |
| 42 obj->addResources(resourceSet, catalog); |
| 43 } |
| 44 } |
| 45 |
63 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
64 | 47 |
65 SkPDFInt::SkPDFInt(int32_t value) : fValue(value) {} | 48 SkPDFInt::SkPDFInt(int32_t value) : fValue(value) {} |
66 SkPDFInt::~SkPDFInt() {} | 49 SkPDFInt::~SkPDFInt() {} |
67 | 50 |
68 void SkPDFInt::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { | 51 void SkPDFInt::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { |
69 stream->writeDecAsText(fValue); | 52 stream->writeDecAsText(fValue); |
70 } | 53 } |
71 | 54 |
72 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 stream->writeText("["); | 253 stream->writeText("["); |
271 for (int i = 0; i < fValue.count(); i++) { | 254 for (int i = 0; i < fValue.count(); i++) { |
272 catalog->getSubstituteObject(fValue[i])->emitObject(stream, catalog); | 255 catalog->getSubstituteObject(fValue[i])->emitObject(stream, catalog); |
273 if (i + 1 < fValue.count()) { | 256 if (i + 1 < fValue.count()) { |
274 stream->writeText(" "); | 257 stream->writeText(" "); |
275 } | 258 } |
276 } | 259 } |
277 stream->writeText("]"); | 260 stream->writeText("]"); |
278 } | 261 } |
279 | 262 |
| 263 void SkPDFArray::addResources(SkPDFObjectSet* resourceSet, |
| 264 SkPDFCatalog* catalog) { |
| 265 for (int i = 0; i < fValue.count(); i++) { |
| 266 catalog->getSubstituteObject(fValue[i]) |
| 267 ->addResources(resourceSet, catalog); |
| 268 } |
| 269 } |
| 270 |
280 void SkPDFArray::reserve(int length) { | 271 void SkPDFArray::reserve(int length) { |
281 SkASSERT(length <= kMaxLen); | 272 SkASSERT(length <= kMaxLen); |
282 fValue.setReserve(length); | 273 fValue.setReserve(length); |
283 } | 274 } |
284 | 275 |
285 SkPDFObject* SkPDFArray::setAt(int offset, SkPDFObject* value) { | 276 SkPDFObject* SkPDFArray::setAt(int offset, SkPDFObject* value) { |
286 SkASSERT(offset < fValue.count()); | 277 SkASSERT(offset < fValue.count()); |
287 value->ref(); | 278 value->ref(); |
288 fValue[offset]->unref(); | 279 fValue[offset]->unref(); |
289 fValue[offset] = value; | 280 fValue[offset] = value; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 SkASSERT(fValue[i].value); | 331 SkASSERT(fValue[i].value); |
341 fValue[i].key->emitObject(stream, catalog); | 332 fValue[i].key->emitObject(stream, catalog); |
342 stream->writeText(" "); | 333 stream->writeText(" "); |
343 catalog->getSubstituteObject(fValue[i].value) | 334 catalog->getSubstituteObject(fValue[i].value) |
344 ->emitObject(stream, catalog); | 335 ->emitObject(stream, catalog); |
345 stream->writeText("\n"); | 336 stream->writeText("\n"); |
346 } | 337 } |
347 stream->writeText(">>"); | 338 stream->writeText(">>"); |
348 } | 339 } |
349 | 340 |
| 341 void SkPDFDict::addResources(SkPDFObjectSet* resourceSet, |
| 342 SkPDFCatalog* catalog) { |
| 343 for (int i = 0; i < fValue.count(); i++) { |
| 344 SkASSERT(fValue[i].key); |
| 345 SkASSERT(fValue[i].value); |
| 346 fValue[i].key->addResources(resourceSet, catalog); |
| 347 catalog->getSubstituteObject(fValue[i].value) |
| 348 ->addResources(resourceSet, catalog); |
| 349 } |
| 350 } |
| 351 |
350 SkPDFObject* SkPDFDict::append(SkPDFName* key, SkPDFObject* value) { | 352 SkPDFObject* SkPDFDict::append(SkPDFName* key, SkPDFObject* value) { |
351 SkASSERT(key); | 353 SkASSERT(key); |
352 SkASSERT(value); | 354 SkASSERT(value); |
353 SkAutoMutexAcquire lock(fMutex); // If the SkTDArray resizes while | 355 SkAutoMutexAcquire lock(fMutex); // If the SkTDArray resizes while |
354 // two threads access array, one | 356 // two threads access array, one |
355 // is left with a bad pointer. | 357 // is left with a bad pointer. |
356 *(fValue.append()) = Rec(key, value); | 358 *(fValue.append()) = Rec(key, value); |
357 return value; | 359 return value; |
358 } | 360 } |
359 | 361 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 void SkPDFDict::mergeFrom(const SkPDFDict& other) { | 409 void SkPDFDict::mergeFrom(const SkPDFDict& other) { |
408 SkAutoMutexAcquire lockOther(other.fMutex); | 410 SkAutoMutexAcquire lockOther(other.fMutex); |
409 SkTDArray<Rec> copy(other.fValue); | 411 SkTDArray<Rec> copy(other.fValue); |
410 lockOther.release(); // Do not hold both mutexes at once. | 412 lockOther.release(); // Do not hold both mutexes at once. |
411 | 413 |
412 SkAutoMutexAcquire lock(fMutex); | 414 SkAutoMutexAcquire lock(fMutex); |
413 for (int i = 0; i < copy.count(); i++) { | 415 for (int i = 0; i < copy.count(); i++) { |
414 *(fValue.append()) = Rec(SkRef(copy[i].key), SkRef(copy[i].value)); | 416 *(fValue.append()) = Rec(SkRef(copy[i].key), SkRef(copy[i].value)); |
415 } | 417 } |
416 } | 418 } |
OLD | NEW |