diff options
author | halcanary <halcanary@google.com> | 2015-04-09 13:27:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-09 13:27:40 -0700 |
commit | 2b86155b42c2493ff0c558ce105a464769962274 (patch) | |
tree | 1a4a5d3b1613662902dbb1e96c29c61b11cb98dc /src/pdf/SkPDFResourceDict.cpp | |
parent | 29be7958de367a7067a3a236c5a23f88ce8e53a4 (diff) |
SkPDF: ResourceDict replaced by factory function
Motivation: Having a class here was unnecessary, since the only thing
that set this class apart was how it is created, not how it behaves.
BUG=skia:3585
Review URL: https://codereview.chromium.org/1068343003
Diffstat (limited to 'src/pdf/SkPDFResourceDict.cpp')
-rw-r--r-- | src/pdf/SkPDFResourceDict.cpp | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/src/pdf/SkPDFResourceDict.cpp b/src/pdf/SkPDFResourceDict.cpp index 69618de714..de5c910c20 100644 --- a/src/pdf/SkPDFResourceDict.cpp +++ b/src/pdf/SkPDFResourceDict.cpp @@ -51,52 +51,58 @@ static const char* get_resource_type_name( return resource_type_names[type]; } -SkPDFResourceDict::SkPDFResourceDict() : SkPDFDict() { - const char procs[][7] = {"PDF", "Text", "ImageB", "ImageC", "ImageI"}; - SkPDFArray* procSets = SkNEW(SkPDFArray()); - - procSets->reserve(SK_ARRAY_COUNT(procs)); - for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++) { - procSets->appendName(procs[i]); - } - insert("ProcSets", procSets)->unref(); - - // Actual sub-dicts will be lazily added later - fTypes.setCount(kResourceTypeCount); - for (int i=0; i < kResourceTypeCount; i++) { - fTypes[i] = NULL; - } -} - -SkPDFObject* SkPDFResourceDict::insertResourceAsReference( - SkPDFResourceType type, int key, SkPDFObject* value) { - SkAutoTUnref<SkPDFObjRef> ref(SkNEW_ARGS(SkPDFObjRef, (value))); - insertResource(type, key, ref); - - return value; -} - SkString SkPDFResourceDict::getResourceName( - SkPDFResourceType type, int key) { + SkPDFResourceDict::SkPDFResourceType type, int key) { SkString keyString; keyString.printf("%c%d", get_resource_type_prefix(type), key); return keyString; } -SkPDFObject* SkPDFResourceDict::insertResource( - SkPDFResourceType type, int key, SkPDFObject* value) { - SkPDFDict* typeDict = fTypes[type]; - if (NULL == typeDict) { - SkAutoTUnref<SkPDFDict> newDict(SkNEW(SkPDFDict())); - SkAutoTUnref<SkPDFName> typeName( - SkNEW_ARGS(SkPDFName, (get_resource_type_name(type)))); - insert(typeName, newDict); // ref counting handled here - fTypes[type] = newDict; - typeDict = newDict.get(); +static void add_subdict( + const SkTDArray<SkPDFObject*>& resourceList, + SkPDFResourceDict::SkPDFResourceType type, + SkPDFDict* dst) { + if (0 == resourceList.count()) { + return; } + SkAutoTUnref<SkPDFDict> resources(SkNEW(SkPDFDict)); + for (int i = 0; i < resourceList.count(); i++) { + SkString keyString = SkPDFResourceDict::getResourceName(type, i); + SkAutoTUnref<SkPDFName> keyName(SkNEW_ARGS(SkPDFName, (keyString))); + SkAutoTUnref<SkPDFObjRef> ref( + SkNEW_ARGS(SkPDFObjRef, (resourceList[i]))); + resources->insert(keyName, ref); + } + dst->insert(get_resource_type_name(type), resources); +} + +SkPDFDict* SkPDFResourceDict::Create( + const SkTDArray<SkPDFObject*>* gStateResources, + const SkTDArray<SkPDFObject*>* patternResources, + const SkTDArray<SkPDFObject*>* xObjectResources, + const SkTDArray<SkPDFObject*>* fontResources) { + SkAutoTUnref<SkPDFDict> dict(SkNEW(SkPDFDict)); + static const char kProcs[][7] = { + "PDF", "Text", "ImageB", "ImageC", "ImageI"}; + SkAutoTUnref<SkPDFArray> procSets(SkNEW(SkPDFArray)); + + procSets->reserve(SK_ARRAY_COUNT(kProcs)); + for (size_t i = 0; i < SK_ARRAY_COUNT(kProcs); i++) { + procSets->appendName(kProcs[i]); + } + dict->insert("ProcSets", procSets); - SkAutoTUnref<SkPDFName> keyName( - SkNEW_ARGS(SkPDFName, (getResourceName(type, key)))); - typeDict->insert(keyName, value); - return value; + if (gStateResources) { + add_subdict(*gStateResources, kExtGState_ResourceType, dict); + } + if (patternResources) { + add_subdict(*patternResources, kPattern_ResourceType, dict); + } + if (xObjectResources) { + add_subdict(*xObjectResources, kXObject_ResourceType, dict); + } + if (fontResources) { + add_subdict(*fontResources, kFont_ResourceType, dict); + } + return dict.detach(); } |