OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPDFResourceDict.h" | 8 #include "SkPDFResourceDict.h" |
9 #include "SkPostConfig.h" | 9 #include "SkPostConfig.h" |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 SkPDFResourceDict::SkPDFResourceType type) { | 39 SkPDFResourceDict::SkPDFResourceType type) { |
40 SkASSERT(type >= 0); | 40 SkASSERT(type >= 0); |
41 SkASSERT(type < SkPDFResourceDict::kResourceTypeCount); | 41 SkASSERT(type < SkPDFResourceDict::kResourceTypeCount); |
42 | 42 |
43 return resource_type_prefixes[type]; | 43 return resource_type_prefixes[type]; |
44 } | 44 } |
45 | 45 |
46 static const char* get_resource_type_name( | 46 static const char* get_resource_type_name( |
47 SkPDFResourceDict::SkPDFResourceType type) { | 47 SkPDFResourceDict::SkPDFResourceType type) { |
48 SkASSERT(type >= 0); | 48 SkASSERT(type >= 0); |
49 SkASSERT(type < SkPDFResourceDict::kResourceTypeCount); | 49 SkASSERT(type < SK_ARRAY_COUNT(resource_type_names)); |
50 | 50 |
51 return resource_type_names[type]; | 51 return resource_type_names[type]; |
52 } | 52 } |
53 | 53 |
54 SkString SkPDFResourceDict::getResourceName( | 54 SkString SkPDFResourceDict::getResourceName( |
55 SkPDFResourceDict::SkPDFResourceType type, int key) { | 55 SkPDFResourceDict::SkPDFResourceType type, int key) { |
56 SkString keyString; | 56 SkString keyString; |
57 keyString.printf("%c%d", get_resource_type_prefix(type), key); | 57 keyString.printf("%c%d", get_resource_type_prefix(type), key); |
58 return keyString; | 58 return keyString; |
59 } | 59 } |
60 | 60 |
61 static void add_subdict( | 61 static void add_subdict( |
62 const SkTDArray<SkPDFObject*>& resourceList, | 62 const SkTDArray<SkPDFObject*>& resourceList, |
63 SkPDFResourceDict::SkPDFResourceType type, | 63 SkPDFResourceDict::SkPDFResourceType type, |
64 SkPDFDict* dst) { | 64 SkPDFDict* dst) { |
65 if (0 == resourceList.count()) { | 65 if (0 == resourceList.count()) { |
66 return; | 66 return; |
67 } | 67 } |
68 SkAutoTUnref<SkPDFDict> resources(SkNEW(SkPDFDict)); | 68 SkAutoTUnref<SkPDFDict> resources(SkNEW(SkPDFDict)); |
69 for (int i = 0; i < resourceList.count(); i++) { | 69 for (int i = 0; i < resourceList.count(); i++) { |
70 SkString keyString = SkPDFResourceDict::getResourceName(type, i); | 70 resources->insertObjRef(SkPDFResourceDict::getResourceName(type, i), |
71 SkAutoTUnref<SkPDFName> keyName(SkNEW_ARGS(SkPDFName, (keyString))); | 71 SkRef(resourceList[i])); |
72 SkAutoTUnref<SkPDFObjRef> ref( | |
73 SkNEW_ARGS(SkPDFObjRef, (resourceList[i]))); | |
74 resources->insert(keyName, ref); | |
75 } | 72 } |
76 dst->insert(get_resource_type_name(type), resources); | 73 dst->insertObject(get_resource_type_name(type), resources.detach()); |
77 } | 74 } |
78 | 75 |
79 SkPDFDict* SkPDFResourceDict::Create( | 76 SkPDFDict* SkPDFResourceDict::Create( |
80 const SkTDArray<SkPDFObject*>* gStateResources, | 77 const SkTDArray<SkPDFObject*>* gStateResources, |
81 const SkTDArray<SkPDFObject*>* patternResources, | 78 const SkTDArray<SkPDFObject*>* patternResources, |
82 const SkTDArray<SkPDFObject*>* xObjectResources, | 79 const SkTDArray<SkPDFObject*>* xObjectResources, |
83 const SkTDArray<SkPDFObject*>* fontResources) { | 80 const SkTDArray<SkPDFObject*>* fontResources) { |
84 SkAutoTUnref<SkPDFDict> dict(SkNEW(SkPDFDict)); | 81 SkAutoTUnref<SkPDFDict> dict(SkNEW(SkPDFDict)); |
85 static const char kProcs[][7] = { | 82 static const char kProcs[][7] = { |
86 "PDF", "Text", "ImageB", "ImageC", "ImageI"}; | 83 "PDF", "Text", "ImageB", "ImageC", "ImageI"}; |
87 SkAutoTUnref<SkPDFArray> procSets(SkNEW(SkPDFArray)); | 84 SkAutoTUnref<SkPDFArray> procSets(SkNEW(SkPDFArray)); |
88 | 85 |
89 procSets->reserve(SK_ARRAY_COUNT(kProcs)); | 86 procSets->reserve(SK_ARRAY_COUNT(kProcs)); |
90 for (size_t i = 0; i < SK_ARRAY_COUNT(kProcs); i++) { | 87 for (size_t i = 0; i < SK_ARRAY_COUNT(kProcs); i++) { |
91 procSets->appendName(kProcs[i]); | 88 procSets->appendName(kProcs[i]); |
92 } | 89 } |
93 dict->insert("ProcSets", procSets); | 90 dict->insertObject("ProcSets", procSets.detach()); |
94 | 91 |
95 if (gStateResources) { | 92 if (gStateResources) { |
96 add_subdict(*gStateResources, kExtGState_ResourceType, dict); | 93 add_subdict(*gStateResources, kExtGState_ResourceType, dict); |
97 } | 94 } |
98 if (patternResources) { | 95 if (patternResources) { |
99 add_subdict(*patternResources, kPattern_ResourceType, dict); | 96 add_subdict(*patternResources, kPattern_ResourceType, dict); |
100 } | 97 } |
101 if (xObjectResources) { | 98 if (xObjectResources) { |
102 add_subdict(*xObjectResources, kXObject_ResourceType, dict); | 99 add_subdict(*xObjectResources, kXObject_ResourceType, dict); |
103 } | 100 } |
104 if (fontResources) { | 101 if (fontResources) { |
105 add_subdict(*fontResources, kFont_ResourceType, dict); | 102 add_subdict(*fontResources, kFont_ResourceType, dict); |
106 } | 103 } |
107 return dict.detach(); | 104 return dict.detach(); |
108 } | 105 } |
OLD | NEW |