epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 The Android Open Source Project |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 10 | #include "SkPDFCatalog.h" |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 11 | |
halcanary | f41061c | 2015-03-25 11:29:18 -0700 | [diff] [blame] | 12 | SkPDFCatalog::SkPDFCatalog() {} |
vandebo@chromium.org | f66025d | 2010-10-01 23:26:55 +0000 | [diff] [blame] | 13 | |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 14 | SkPDFCatalog::~SkPDFCatalog() { |
halcanary | f41061c | 2015-03-25 11:29:18 -0700 | [diff] [blame] | 15 | fSubstituteMap.foreach( |
| 16 | [](SkPDFObject*, SkPDFObject** v) { (*v)->unref(); }); |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 17 | } |
vandebo@chromium.org | f66025d | 2010-10-01 23:26:55 +0000 | [diff] [blame] | 18 | |
halcanary | f41061c | 2015-03-25 11:29:18 -0700 | [diff] [blame] | 19 | bool SkPDFCatalog::addObject(SkPDFObject* obj) { |
| 20 | if (fObjectNumbers.find(obj)) { |
| 21 | return false; |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 22 | } |
halcanary | f41061c | 2015-03-25 11:29:18 -0700 | [diff] [blame] | 23 | fObjectNumbers.set(obj, fObjectNumbers.count() + 1); |
halcanary | d4714af | 2015-03-25 13:23:13 -0700 | [diff] [blame] | 24 | fObjects.push(obj); |
halcanary | f41061c | 2015-03-25 11:29:18 -0700 | [diff] [blame] | 25 | return true; |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 26 | } |
| 27 | |
halcanary | f41061c | 2015-03-25 11:29:18 -0700 | [diff] [blame] | 28 | int32_t SkPDFCatalog::getObjectNumber(SkPDFObject* obj) const { |
| 29 | int32_t* objectNumberFound = fObjectNumbers.find(obj); |
| 30 | SkASSERT(objectNumberFound); |
| 31 | return *objectNumberFound; |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 32 | } |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 33 | |
| 34 | void SkPDFCatalog::setSubstitute(SkPDFObject* original, |
| 35 | SkPDFObject* substitute) { |
halcanary | f41061c | 2015-03-25 11:29:18 -0700 | [diff] [blame] | 36 | SkASSERT(original != substitute); |
| 37 | SkASSERT(!fSubstituteMap.find(original)); |
| 38 | fSubstituteMap.set(original, SkRef(substitute)); |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 39 | } |
| 40 | |
halcanary | f41061c | 2015-03-25 11:29:18 -0700 | [diff] [blame] | 41 | SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) const { |
| 42 | SkPDFObject** found = fSubstituteMap.find(object); |
| 43 | return found ? *found : object; |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 44 | } |