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