OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 The Android Open Source Project | 3 * Copyright 2010 The Android Open Source Project |
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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 SkASSERT(fCatalog[objIndex].fObjNumAssigned); | 43 SkASSERT(fCatalog[objIndex].fObjNumAssigned); |
44 SkASSERT(fCatalog[objIndex].fFileOffset == 0); | 44 SkASSERT(fCatalog[objIndex].fFileOffset == 0); |
45 fCatalog[objIndex].fFileOffset = offset; | 45 fCatalog[objIndex].fFileOffset = offset; |
46 } | 46 } |
47 | 47 |
48 void SkPDFCatalog::emitObjectNumber(SkWStream* stream, SkPDFObject* obj) { | 48 void SkPDFCatalog::emitObjectNumber(SkWStream* stream, SkPDFObject* obj) { |
49 stream->writeDecAsText(assignObjNum(obj)); | 49 stream->writeDecAsText(assignObjNum(obj)); |
50 stream->writeText(" 0"); // Generation number is always 0. | 50 stream->writeText(" 0"); // Generation number is always 0. |
51 } | 51 } |
52 | 52 |
53 size_t SkPDFCatalog::getObjectNumberSize(SkPDFObject* obj) { | 53 int SkPDFCatalog::findObjectIndex(SkPDFObject* obj) { |
54 SkDynamicMemoryWStream buffer; | |
55 emitObjectNumber(&buffer, obj); | |
56 return buffer.getOffset(); | |
57 } | |
58 | |
59 int SkPDFCatalog::findObjectIndex(SkPDFObject* obj) const { | |
60 for (int i = 0; i < fCatalog.count(); i++) { | 54 for (int i = 0; i < fCatalog.count(); i++) { |
61 if (fCatalog[i].fObject == obj) { | 55 if (fCatalog[i].fObject == obj) { |
62 return i; | 56 return i; |
63 } | 57 } |
64 } | 58 } |
65 // If it's not in the main array, check if it's a substitute object. | 59 // If it's not in the main array, check if it's a substitute object. |
66 for (int i = 0; i < fSubstituteMap.count(); ++i) { | 60 for (int i = 0; i < fSubstituteMap.count(); ++i) { |
67 if (fSubstituteMap[i].fSubstitute == obj) { | 61 if (fSubstituteMap[i].fSubstitute == obj) { |
68 return findObjectIndex(fSubstituteMap[i].fOriginal); | 62 return findObjectIndex(fSubstituteMap[i].fOriginal); |
69 } | 63 } |
70 } | 64 } |
71 return -1; | 65 struct Rec newEntry(obj, false); |
mtklein
2015/02/10 17:25:52
drop struct? This is not C.
hal.canary
2015/02/10 17:44:59
Done.
| |
66 fCatalog.append(1, &newEntry); | |
67 return fCatalog.count() - 1; | |
72 } | 68 } |
73 | 69 |
74 int SkPDFCatalog::assignObjNum(SkPDFObject* obj) { | 70 int SkPDFCatalog::assignObjNum(SkPDFObject* obj) { |
75 int pos = findObjectIndex(obj); | 71 int pos = findObjectIndex(obj); |
76 // If this assert fails, it means you probably forgot to add an object | 72 // If this assert fails, it means you probably forgot to add an object |
77 // to the resource list. | 73 // to the resource list. |
78 SkASSERT(pos >= 0); | 74 SkASSERT(pos >= 0); |
79 uint32_t currentIndex = pos; | 75 uint32_t currentIndex = pos; |
80 if (fCatalog[currentIndex].fObjNumAssigned) { | 76 if (fCatalog[currentIndex].fObjNumAssigned) { |
81 return currentIndex + 1; | 77 return currentIndex + 1; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 #if defined(SK_DEBUG) | 139 #if defined(SK_DEBUG) |
144 // Sanity check: is the original already in substitute list? | 140 // Sanity check: is the original already in substitute list? |
145 for (int i = 0; i < fSubstituteMap.count(); ++i) { | 141 for (int i = 0; i < fSubstituteMap.count(); ++i) { |
146 if (original == fSubstituteMap[i].fSubstitute || | 142 if (original == fSubstituteMap[i].fSubstitute || |
147 original == fSubstituteMap[i].fOriginal) { | 143 original == fSubstituteMap[i].fOriginal) { |
148 SkASSERT(false); | 144 SkASSERT(false); |
149 return; | 145 return; |
150 } | 146 } |
151 } | 147 } |
152 #endif | 148 #endif |
153 // Check if the original is on first page. | |
154 bool onFirstPage = false; | |
155 for (int i = 0; i < fCatalog.count(); ++i) { | |
156 if (fCatalog[i].fObject == original) { | |
157 onFirstPage = fCatalog[i].fOnFirstPage; | |
158 break; | |
159 } | |
160 #if defined(SK_DEBUG) | |
161 if (i == fCatalog.count() - 1) { | |
162 SkASSERT(false); // original not in catalog | |
163 return; | |
164 } | |
165 #endif | |
166 } | |
167 | |
168 SubstituteMapping newMapping(original, substitute); | 149 SubstituteMapping newMapping(original, substitute); |
169 fSubstituteMap.append(1, &newMapping); | 150 fSubstituteMap.append(1, &newMapping); |
170 | |
171 // Add resource objects of substitute object to catalog. | |
172 SkTSet<SkPDFObject*>* targetSet = getSubstituteList(onFirstPage); | |
173 SkTSet<SkPDFObject*> newResourceObjects; | |
174 newMapping.fSubstitute->getResources(*targetSet, &newResourceObjects); | |
175 for (int i = 0; i < newResourceObjects.count(); ++i) { | |
176 addObject(newResourceObjects[i], onFirstPage); | |
177 } | |
178 // mergeInto returns the number of duplicates. | |
179 // If there are duplicates, there is a bug and we mess ref counting. | |
180 SkDEBUGCODE(int duplicates =) targetSet->mergeInto(newResourceObjects); | |
181 SkASSERT(duplicates == 0); | |
182 } | 151 } |
183 | 152 |
184 SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) { | 153 SkPDFObject* SkPDFCatalog::getSubstituteObject(SkPDFObject* object) { |
185 for (int i = 0; i < fSubstituteMap.count(); ++i) { | 154 for (int i = 0; i < fSubstituteMap.count(); ++i) { |
186 if (object == fSubstituteMap[i].fOriginal) { | 155 if (object == fSubstituteMap[i].fOriginal) { |
187 return fSubstituteMap[i].fSubstitute; | 156 return fSubstituteMap[i].fSubstitute; |
188 } | 157 } |
189 } | 158 } |
190 return object; | 159 return object; |
191 } | 160 } |
192 | 161 |
193 SkTSet<SkPDFObject*>* SkPDFCatalog::getSubstituteList(bool firstPage) { | |
194 return firstPage ? &fSubstituteResourcesFirstPage : | |
195 &fSubstituteResourcesRemaining; | |
196 } | |
OLD | NEW |