blob: 4069cc9762e345b8460ced9f1b3f605b9ae99de7 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 The Android Open Source Project
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000010#include "SkPDFCatalog.h"
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000011
halcanaryf41061c2015-03-25 11:29:18 -070012SkPDFCatalog::SkPDFCatalog() {}
vandebo@chromium.orgf66025d2010-10-01 23:26:55 +000013
vandebo@chromium.org2ef12d42011-07-06 23:31:24 +000014SkPDFCatalog::~SkPDFCatalog() {
halcanaryf41061c2015-03-25 11:29:18 -070015 fSubstituteMap.foreach(
16 [](SkPDFObject*, SkPDFObject** v) { (*v)->unref(); });
vandebo@chromium.org2ef12d42011-07-06 23:31:24 +000017}
vandebo@chromium.orgf66025d2010-10-01 23:26:55 +000018
halcanaryf41061c2015-03-25 11:29:18 -070019bool SkPDFCatalog::addObject(SkPDFObject* obj) {
20 if (fObjectNumbers.find(obj)) {
21 return false;
vandebo@chromium.org2ef12d42011-07-06 23:31:24 +000022 }
halcanaryf41061c2015-03-25 11:29:18 -070023 fObjectNumbers.set(obj, fObjectNumbers.count() + 1);
halcanaryd4714af2015-03-25 13:23:13 -070024 fObjects.push(obj);
halcanaryf41061c2015-03-25 11:29:18 -070025 return true;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000026}
27
halcanaryf41061c2015-03-25 11:29:18 -070028int32_t SkPDFCatalog::getObjectNumber(SkPDFObject* obj) const {
29 int32_t* objectNumberFound = fObjectNumbers.find(obj);
30 SkASSERT(objectNumberFound);
31 return *objectNumberFound;
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000032}
vandebo@chromium.org2ef12d42011-07-06 23:31:24 +000033
34void SkPDFCatalog::setSubstitute(SkPDFObject* original,
35 SkPDFObject* substitute) {
halcanaryf41061c2015-03-25 11:29:18 -070036 SkASSERT(original != substitute);
37 SkASSERT(!fSubstituteMap.find(original));
38 fSubstituteMap.set(original, SkRef(substitute));
vandebo@chromium.org2ef12d42011-07-06 23:31:24 +000039}
40
halcanaryf41061c2015-03-25 11:29:18 -070041SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) const {
42 SkPDFObject** found = fSubstituteMap.find(object);
43 return found ? *found : object;
vandebo@chromium.org2ef12d42011-07-06 23:31:24 +000044}