| 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 "SkPdfNativeDoc.h" | 8 #include "SkPdfNativeDoc.h" |
| 9 #include "SkPdfNativeTokenizer.h" | 9 #include "SkPdfNativeTokenizer.h" |
| 10 #include "SkPdfNativeObject.h" | 10 #include "SkPdfNativeObject.h" |
| 11 #include "SkPdfReporter.h" |
| 11 | 12 |
| 12 #include <stdio.h> | 13 #include <stdio.h> |
| 13 #include <string.h> | 14 #include <string.h> |
| 14 #include <sys/types.h> | 15 #include <sys/types.h> |
| 15 #include <sys/stat.h> | 16 #include <sys/stat.h> |
| 16 | 17 |
| 17 // TODO(edisonn): for some reason on mac these files are found here, but are fou
nd from headers | 18 // TODO(edisonn): for some reason on mac these files are found here, but are fou
nd from headers |
| 18 //#include "SkPdfFileTrailerDictionary_autogen.h" | 19 //#include "SkPdfFileTrailerDictionary_autogen.h" |
| 19 //#include "SkPdfCatalogDictionary_autogen.h" | 20 //#include "SkPdfCatalogDictionary_autogen.h" |
| 20 //#include "SkPdfPageObjectDictionary_autogen.h" | 21 //#include "SkPdfPageObjectDictionary_autogen.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 gDoc = this; | 101 gDoc = this; |
| 101 FILE* file = fopen(path, "r"); | 102 FILE* file = fopen(path, "r"); |
| 102 // TODO(edisonn): put this in a function that can return NULL | 103 // TODO(edisonn): put this in a function that can return NULL |
| 103 if (file) { | 104 if (file) { |
| 104 size_t size = getFileSize(path); | 105 size_t size = getFileSize(path); |
| 105 void* content = sk_malloc_throw(size); | 106 void* content = sk_malloc_throw(size); |
| 106 bool ok = (0 != fread(content, size, 1, file)); | 107 bool ok = (0 != fread(content, size, 1, file)); |
| 107 fclose(file); | 108 fclose(file); |
| 108 if (!ok) { | 109 if (!ok) { |
| 109 sk_free(content); | 110 sk_free(content); |
| 110 // TODO(edisonn): report read error | 111 SkPdfReport(kFatalError_SkPdfIssueSeverity, kReadStreamError_SkPdfIs
sue, "could not read file", NULL, NULL); |
| 111 // TODO(edisonn): not nice to return like this from constructor, cre
ate a static | 112 // TODO(edisonn): not nice to return like this from constructor, cre
ate a static |
| 112 // function that can report NULL for failures. | 113 // function that can report NULL for failures. |
| 113 return; // Doc will have 0 pages | 114 return; // Doc will have 0 pages |
| 114 } | 115 } |
| 115 | 116 |
| 116 init(content, size); | 117 init(content, size); |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 void SkPdfNativeDoc::init(const void* bytes, size_t length) { | 121 void SkPdfNativeDoc::init(const void* bytes, size_t length) { |
| 121 fFileContent = (const unsigned char*)bytes; | 122 fFileContent = (const unsigned char*)bytes; |
| 122 fContentLength = length; | 123 fContentLength = length; |
| 123 const unsigned char* eofLine = lineHome(fFileContent, fFileContent + fConten
tLength - 1); | 124 const unsigned char* eofLine = lineHome(fFileContent, fFileContent + fConten
tLength - 1); |
| 124 const unsigned char* xrefByteOffsetLine = previousLineHome(fFileContent, eof
Line); | 125 const unsigned char* xrefByteOffsetLine = previousLineHome(fFileContent, eof
Line); |
| 125 const unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, x
refByteOffsetLine); | 126 const unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, x
refByteOffsetLine); |
| 126 | 127 |
| 127 if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) { | 128 if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) { |
| 128 // TODO(edisonn): report/issue | 129 SkPdfReport(kWarning_SkPdfIssueSeverity, kMissingToken_SkPdfIssue, "Coul
d not find startxref", NULL, NULL); |
| 129 } | 130 } |
| 130 | 131 |
| 131 long xrefByteOffset = atol((const char*)xrefByteOffsetLine); | 132 long xrefByteOffset = atol((const char*)xrefByteOffsetLine); |
| 132 | 133 |
| 133 bool storeCatalog = true; | 134 bool storeCatalog = true; |
| 134 while (xrefByteOffset >= 0) { | 135 while (xrefByteOffset >= 0) { |
| 135 const unsigned char* trailerStart = readCrossReferenceSection(fFileConte
nt + xrefByteOffset, xrefstartKeywordLine); | 136 const unsigned char* trailerStart = readCrossReferenceSection(fFileConte
nt + xrefByteOffset, xrefstartKeywordLine); |
| 136 xrefByteOffset = -1; | 137 xrefByteOffset = -1; |
| 137 if (trailerStart < xrefstartKeywordLine) { | 138 if (trailerStart < xrefstartKeywordLine) { |
| 138 readTrailer(trailerStart, xrefstartKeywordLine, storeCatalog, &xrefB
yteOffset, false); | 139 readTrailer(trailerStart, xrefstartKeywordLine, storeCatalog, &xrefB
yteOffset, false); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 int id = (int)token.intValue(); | 183 int id = (int)token.intValue(); |
| 183 | 184 |
| 184 token.reset(); | 185 token.reset(); |
| 185 current = nextObject(0, current, end, &token, NULL, NULL PUT_TRACK_S
TREAM_ARGS_EXPL2(0, fFileContent)); | 186 current = nextObject(0, current, end, &token, NULL, NULL PUT_TRACK_S
TREAM_ARGS_EXPL2(0, fFileContent)); |
| 186 // int generation = (int)token.intValue(); // TODO(edisonn): ignore
d for now | 187 // int generation = (int)token.intValue(); // TODO(edisonn): ignore
d for now |
| 187 | 188 |
| 188 token.reset(); | 189 token.reset(); |
| 189 current = nextObject(0, current, end, &token, NULL, NULL PUT_TRACK_S
TREAM_ARGS_EXPL2(0, fFileContent)); | 190 current = nextObject(0, current, end, &token, NULL, NULL PUT_TRACK_S
TREAM_ARGS_EXPL2(0, fFileContent)); |
| 190 // TODO(edisonn): must be obj, return error if not? ignore ? | 191 // TODO(edisonn): must be obj, return error if not? ignore ? |
| 191 if (!token.isKeyword("obj")) { | 192 if (!token.isKeyword("obj")) { |
| 193 SkPdfReport(kWarning_SkPdfIssueSeverity, kMissingToken_SkPdfIssu
e, "Could not find obj", NULL, NULL); |
| 192 continue; | 194 continue; |
| 193 } | 195 } |
| 194 | 196 |
| 195 while (fObjects.count() < id + 1) { | 197 while (fObjects.count() < id + 1) { |
| 196 reset(fObjects.append()); | 198 reset(fObjects.append()); |
| 197 } | 199 } |
| 198 | 200 |
| 199 fObjects[id].fOffset = current - fFileContent; | 201 fObjects[id].fOffset = current - fFileContent; |
| 200 | 202 |
| 201 SkPdfNativeObject* obj = fAllocator->allocObject(); | 203 SkPdfNativeObject* obj = fAllocator->allocObject(); |
| 202 current = nextObject(0, current, end, obj, fAllocator, this PUT_TRAC
K_STREAM_ARGS_EXPL2(0, fFileContent)); | 204 current = nextObject(0, current, end, obj, fAllocator, this PUT_TRAC
K_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 203 | 205 |
| 204 fObjects[id].fResolvedReference = obj; | 206 fObjects[id].fResolvedReference = obj; |
| 205 fObjects[id].fObj = obj; | 207 fObjects[id].fObj = obj; |
| 208 fObjects[id].fIsReferenceResolved = true; |
| 209 |
| 206 | 210 |
| 207 // set objects | 211 // set objects |
| 208 } else if (token.isKeyword("trailer")) { | 212 } else if (token.isKeyword("trailer")) { |
| 209 long dummy; | 213 long dummy; |
| 210 current = readTrailer(current, end, true, &dummy, true); | 214 current = readTrailer(current, end, true, &dummy, true); |
| 211 } else if (token.isKeyword("startxref")) { | 215 } else if (token.isKeyword("startxref")) { |
| 212 token.reset(); | 216 token.reset(); |
| 213 current = nextObject(0, current, end, &token, NULL, NULL PUT_TRACK_S
TREAM_ARGS_EXPL2(0, fFileContent)); // ignore | 217 current = nextObject(0, current, end, &token, NULL, NULL PUT_TRACK_S
TREAM_ARGS_EXPL2(0, fFileContent)); // ignore |
| 214 } | 218 } |
| 215 | 219 |
| 216 current = skipPdfWhiteSpaces(0, current, end); | 220 current = skipPdfWhiteSpaces(0, current, end); |
| 217 } | 221 } |
| 218 | 222 |
| 219 // TODO(edisonn): hack, detect root catalog - we need to implement liniarize
d support, and remove this hack. | 223 // TODO(edisonn): hack, detect root catalog - we need to implement liniarize
d support, and remove this hack. |
| 220 if (!fRootCatalogRef) { | 224 if (!fRootCatalogRef) { |
| 221 for (unsigned int i = 0 ; i < objects(); i++) { | 225 for (unsigned int i = 0 ; i < objects(); i++) { |
| 222 SkPdfNativeObject* obj = object(i); | 226 SkPdfNativeObject* obj = object(i); |
| 223 SkPdfNativeObject* root = (obj && obj->isDictionary()) ? obj->get("R
oot") : NULL; | 227 SkPdfNativeObject* root = (obj && obj->isDictionary()) ? obj->get("R
oot") : NULL; |
| 224 if (root && root->isReference()) { | 228 if (root && root->isReference()) { |
| 225 fRootCatalogRef = root; | 229 fRootCatalogRef = root; |
| 226 } | 230 } |
| 227 } | 231 } |
| 228 } | 232 } |
| 229 | 233 |
| 230 | |
| 231 if (fRootCatalogRef) { | 234 if (fRootCatalogRef) { |
| 232 fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef
); | 235 fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef
); |
| 233 if (fRootCatalog->isDictionary() && fRootCatalog->valid()) { | 236 if (fRootCatalog->isDictionary() && fRootCatalog->valid()) { |
| 234 SkPdfPageTreeNodeDictionary* tree = fRootCatalog->Pages(this); | 237 SkPdfPageTreeNodeDictionary* tree = fRootCatalog->Pages(this); |
| 235 if (tree && tree->isDictionary() && tree->valid()) { | 238 if (tree && tree->isDictionary() && tree->valid()) { |
| 236 fillPages(tree); | 239 fillPages(tree); |
| 237 } | 240 } |
| 238 } | 241 } |
| 239 } | 242 } |
| 240 | 243 |
| 241 | 244 |
| 242 } | 245 } |
| 243 | 246 |
| 244 // TODO(edisonn): NYI | 247 // TODO(edisonn): NYI |
| 245 SkPdfNativeDoc::~SkPdfNativeDoc() { | 248 SkPdfNativeDoc::~SkPdfNativeDoc() { |
| 246 sk_free((void*)fFileContent); | 249 sk_free((void*)fFileContent); |
| 247 delete fAllocator; | 250 delete fAllocator; |
| 248 } | 251 } |
| 249 | 252 |
| 250 const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned ch
ar* xrefStart, const unsigned char* trailerEnd) { | 253 const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned ch
ar* xrefStart, const unsigned char* trailerEnd) { |
| 251 SkPdfNativeObject xref; | 254 SkPdfNativeObject xref; |
| 252 const unsigned char* current = nextObject(0, xrefStart, trailerEnd, &xref, N
ULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); | 255 const unsigned char* current = nextObject(0, xrefStart, trailerEnd, &xref, N
ULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 253 | 256 |
| 254 if (!xref.isKeyword("xref")) { | 257 if (!xref.isKeyword("xref")) { |
| 258 SkPdfReport(kWarning_SkPdfIssueSeverity, kMissingToken_SkPdfIssue, "Coul
d not find sref", NULL, NULL); |
| 255 return trailerEnd; | 259 return trailerEnd; |
| 256 } | 260 } |
| 257 | 261 |
| 258 SkPdfNativeObject token; | 262 SkPdfNativeObject token; |
| 259 while (current < trailerEnd) { | 263 while (current < trailerEnd) { |
| 260 token.reset(); | 264 token.reset(); |
| 261 const unsigned char* previous = current; | 265 const unsigned char* previous = current; |
| 262 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRAC
K_STREAM_ARGS_EXPL2(0, fFileContent)); | 266 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRAC
K_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 263 if (!token.isInteger()) { | 267 if (!token.isInteger()) { |
| 268 SkPdfReport(kInfo_SkPdfIssueSeverity, kNoIssue_SkPdfIssue, "Done rea
dCrossReferenceSection", NULL, NULL); |
| 264 return previous; | 269 return previous; |
| 265 } | 270 } |
| 266 | 271 |
| 267 int startId = (int)token.intValue(); | 272 int startId = (int)token.intValue(); |
| 268 token.reset(); | 273 token.reset(); |
| 269 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRAC
K_STREAM_ARGS_EXPL2(0, fFileContent)); | 274 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRAC
K_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 270 | 275 |
| 271 if (!token.isInteger()) { | 276 if (!token.isInteger()) { |
| 272 // TODO(edisonn): report/warning | 277 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readCros
sReferenceSection", &token, SkPdfNativeObject::kInteger_PdfObjectType, NULL); |
| 273 return current; | 278 return current; |
| 274 } | 279 } |
| 275 | 280 |
| 276 int entries = (int)token.intValue(); | 281 int entries = (int)token.intValue(); |
| 277 | 282 |
| 278 for (int i = 0; i < entries; i++) { | 283 for (int i = 0; i < entries; i++) { |
| 279 token.reset(); | 284 token.reset(); |
| 280 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_
TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); | 285 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_
TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 281 if (!token.isInteger()) { | 286 if (!token.isInteger()) { |
| 282 // TODO(edisonn): report/warning | 287 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "read
CrossReferenceSection", &token, SkPdfNativeObject::kInteger_PdfObjectType, NULL)
; |
| 283 return current; | 288 return current; |
| 284 } | 289 } |
| 285 int offset = (int)token.intValue(); | 290 int offset = (int)token.intValue(); |
| 286 | 291 |
| 287 token.reset(); | 292 token.reset(); |
| 288 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_
TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); | 293 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_
TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 289 if (!token.isInteger()) { | 294 if (!token.isInteger()) { |
| 290 // TODO(edisonn): report/warning | 295 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "read
CrossReferenceSection", &token, SkPdfNativeObject::kInteger_PdfObjectType, NULL)
; |
| 291 return current; | 296 return current; |
| 292 } | 297 } |
| 293 int generation = (int)token.intValue(); | 298 int generation = (int)token.intValue(); |
| 294 | 299 |
| 295 token.reset(); | 300 token.reset(); |
| 296 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_
TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); | 301 current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_
TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 297 if (!token.isKeyword() || token.lenstr() != 1 || (*token.c_str() !=
'f' && *token.c_str() != 'n')) { | 302 if (!token.isKeyword() || token.lenstr() != 1 || (*token.c_str() !=
'f' && *token.c_str() != 'n')) { |
| 298 // TODO(edisonn): report/warning | 303 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "read
CrossReferenceSection: f or n expected", &token, SkPdfNativeObject::kKeyword_Pdf
ObjectType, NULL); |
| 299 return current; | 304 return current; |
| 300 } | 305 } |
| 301 | 306 |
| 302 addCrossSectionInfo(startId + i, generation, offset, *token.c_str()
== 'f'); | 307 addCrossSectionInfo(startId + i, generation, offset, *token.c_str()
== 'f'); |
| 303 } | 308 } |
| 304 } | 309 } |
| 305 // TODO(edisonn): it should never get here? there is no trailer? | 310 SkPdfReport(kInfo_SkPdfIssueSeverity, kNoIssue_SkPdfIssue, "Unexpected end o
f readCrossReferenceSection", NULL, NULL); |
| 306 return current; | 311 return current; |
| 307 } | 312 } |
| 308 | 313 |
| 309 const unsigned char* SkPdfNativeDoc::readTrailer(const unsigned char* trailerSta
rt, const unsigned char* trailerEnd, bool storeCatalog, long* prev, bool skipKey
word) { | 314 const unsigned char* SkPdfNativeDoc::readTrailer(const unsigned char* trailerSta
rt, const unsigned char* trailerEnd, bool storeCatalog, long* prev, bool skipKey
word) { |
| 310 *prev = -1; | 315 *prev = -1; |
| 311 | 316 |
| 312 const unsigned char* current = trailerStart; | 317 const unsigned char* current = trailerStart; |
| 313 if (!skipKeyword) { | 318 if (!skipKeyword) { |
| 314 SkPdfNativeObject trailerKeyword; | 319 SkPdfNativeObject trailerKeyword; |
| 315 // TODO(edisonn): use null allocator, and let it just fail if memory | 320 // TODO(edisonn): use null allocator, and let it just fail if memory |
| 316 // needs allocated (but no crash)! | 321 // needs allocated (but no crash)! |
| 317 current = nextObject(0, current, trailerEnd, &trailerKeyword, NULL, NULL
PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); | 322 current = nextObject(0, current, trailerEnd, &trailerKeyword, NULL, NULL
PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 318 | 323 |
| 319 if (!trailerKeyword.isKeyword() || strlen("trailer") != trailerKeyword.l
enstr() || | 324 if (!trailerKeyword.isKeyword() || strlen("trailer") != trailerKeyword.l
enstr() || |
| 320 strncmp(trailerKeyword.c_str(), "trailer", strlen("trailer")) != 0)
{ | 325 strncmp(trailerKeyword.c_str(), "trailer", strlen("trailer")) != 0)
{ |
| 321 // TODO(edisonn): report warning, rebuild trailer from objects. | 326 // TODO(edisonn): report warning, rebuild trailer from objects. |
| 327 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readTrai
ler: trailer keyword expected", &trailerKeyword, SkPdfNativeObject::kKeyword_Pdf
ObjectType, NULL); |
| 322 return current; | 328 return current; |
| 323 } | 329 } |
| 324 } | 330 } |
| 325 | 331 |
| 326 SkPdfNativeObject token; | 332 SkPdfNativeObject token; |
| 327 current = nextObject(0, current, trailerEnd, &token, fAllocator, NULL PUT_TR
ACK_STREAM_ARGS_EXPL2(0, fFileContent)); | 333 current = nextObject(0, current, trailerEnd, &token, fAllocator, NULL PUT_TR
ACK_STREAM_ARGS_EXPL2(0, fFileContent)); |
| 328 if (!token.isDictionary()) { | 334 if (!token.isDictionary()) { |
| 329 return current; | 335 return current; |
| 330 } | 336 } |
| 331 SkPdfFileTrailerDictionary* trailer = (SkPdfFileTrailerDictionary*)&token; | 337 SkPdfFileTrailerDictionary* trailer = (SkPdfFileTrailerDictionary*)&token; |
| 332 if (!trailer->valid()) { | 338 if (!trailer->valid()) { |
| 333 return current; | 339 return current; |
| 334 } | 340 } |
| 335 | 341 |
| 336 if (storeCatalog) { | 342 if (storeCatalog) { |
| 337 SkPdfNativeObject* ref = trailer->Root(NULL); | 343 SkPdfNativeObject* ref = trailer->Root(NULL); |
| 338 if (ref == NULL || !ref->isReference()) { | 344 if (ref == NULL || !ref->isReference()) { |
| 339 // TODO(edisonn): oops, we have to fix the corrup pdf file | 345 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readTrai
ler: unexpected root reference", ref, SkPdfNativeObject::kReference_PdfObjectTyp
e, NULL); |
| 340 return current; | 346 return current; |
| 341 } | 347 } |
| 342 fRootCatalogRef = ref; | 348 fRootCatalogRef = ref; |
| 343 } | 349 } |
| 344 | 350 |
| 345 if (trailer->has_Prev()) { | 351 if (trailer->has_Prev()) { |
| 346 *prev = (long)trailer->Prev(NULL); | 352 *prev = (long)trailer->Prev(NULL); |
| 347 } | 353 } |
| 348 | 354 |
| 349 return current; | 355 return current; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 374 | 380 |
| 375 SkPdfNativeTokenizer tokenizer(current, end - current, fAllocator, this); | 381 SkPdfNativeTokenizer tokenizer(current, end - current, fAllocator, this); |
| 376 | 382 |
| 377 SkPdfNativeObject idObj; | 383 SkPdfNativeObject idObj; |
| 378 SkPdfNativeObject generationObj; | 384 SkPdfNativeObject generationObj; |
| 379 SkPdfNativeObject objKeyword; | 385 SkPdfNativeObject objKeyword; |
| 380 SkPdfNativeObject* dict = fAllocator->allocObject(); | 386 SkPdfNativeObject* dict = fAllocator->allocObject(); |
| 381 | 387 |
| 382 current = nextObject(0, current, end, &idObj, NULL, NULL PUT_TRACK_STREAM_AR
GS_EXPL2(0, fFileContent)); | 388 current = nextObject(0, current, end, &idObj, NULL, NULL PUT_TRACK_STREAM_AR
GS_EXPL2(0, fFileContent)); |
| 383 if (current >= end) { | 389 if (current >= end) { |
| 384 // TODO(edisonn): report warning/error | 390 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kReadStreamError_SkPdfIssue
, "reading id", NULL, NULL); |
| 385 return NULL; | 391 return NULL; |
| 386 } | 392 } |
| 387 | 393 |
| 388 current = nextObject(0, current, end, &generationObj, NULL, NULL PUT_TRACK_S
TREAM_ARGS_EXPL2(0, fFileContent)); | 394 current = nextObject(0, current, end, &generationObj, NULL, NULL PUT_TRACK_S
TREAM_ARGS_EXPL2(0, fFileContent)); |
| 389 if (current >= end) { | 395 if (current >= end) { |
| 390 // TODO(edisonn): report warning/error | 396 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kReadStreamError_SkPdfIssue
, "reading generation", NULL, NULL); |
| 391 return NULL; | 397 return NULL; |
| 392 } | 398 } |
| 393 | 399 |
| 394 current = nextObject(0, current, end, &objKeyword, NULL, NULL PUT_TRACK_STRE
AM_ARGS_EXPL2(0, fFileContent)); | 400 current = nextObject(0, current, end, &objKeyword, NULL, NULL PUT_TRACK_STRE
AM_ARGS_EXPL2(0, fFileContent)); |
| 395 if (current >= end) { | 401 if (current >= end) { |
| 396 // TODO(edisonn): report warning/error | 402 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kReadStreamError_SkPdfIssue
, "reading keyword obj", NULL, NULL); |
| 397 return NULL; | 403 return NULL; |
| 398 } | 404 } |
| 399 | 405 |
| 400 if (!idObj.isInteger() || !generationObj.isInteger() || id != idObj.intValue
()/* || generation != generationObj.intValue()*/) { | 406 if (!idObj.isInteger() || id != idObj.intValue()) { |
| 401 // TODO(edisonn): report warning/error | 407 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readObject:
unexpected id", &idObj, SkPdfNativeObject::kInteger_PdfObjectType, NULL); |
| 408 } |
| 409 |
| 410 // TODO(edisonn): verify that the generation is the right one |
| 411 if (!generationObj.isInteger() /* || generation != generationObj.intValue()*
/) { |
| 412 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readObject:
unexpected generation", &generationObj, SkPdfNativeObject::kInteger_PdfObjectTyp
e, NULL); |
| 402 } | 413 } |
| 403 | 414 |
| 404 if (!objKeyword.isKeyword() || strcmp(objKeyword.c_str(), "obj") != 0) { | 415 if (!objKeyword.isKeyword() || strcmp(objKeyword.c_str(), "obj") != 0) { |
| 405 // TODO(edisonn): report warning/error | 416 SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readObject:
unexpected obj keyword", &objKeyword, SkPdfNativeObject::kKeyword_PdfObjectType,
NULL); |
| 406 } | 417 } |
| 407 | 418 |
| 408 current = nextObject(1, current, end, dict, fAllocator, this PUT_TRACK_STREA
M_ARGS_EXPL2(0, fFileContent)); | 419 current = nextObject(1, current, end, dict, fAllocator, this PUT_TRACK_STREA
M_ARGS_EXPL2(0, fFileContent)); |
| 409 | 420 |
| 410 // TODO(edisonn): report warning/error - verify last token is endobj | 421 // TODO(edisonn): report warning/error - verify last token is endobj |
| 411 | 422 |
| 412 return dict; | 423 return dict; |
| 413 } | 424 } |
| 414 | 425 |
| 415 void SkPdfNativeDoc::fillPages(SkPdfPageTreeNodeDictionary* tree) { | 426 void SkPdfNativeDoc::fillPages(SkPdfPageTreeNodeDictionary* tree) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 // TODO(edisonn): fix infinite loop if ref to itself! | 547 // TODO(edisonn): fix infinite loop if ref to itself! |
| 537 // TODO(edisonn): perf, fix refs at load, and resolve will simply return fResolv
edReference? | 548 // TODO(edisonn): perf, fix refs at load, and resolve will simply return fResolv
edReference? |
| 538 SkPdfNativeObject* SkPdfNativeDoc::resolveReference(SkPdfNativeObject* ref) { | 549 SkPdfNativeObject* SkPdfNativeDoc::resolveReference(SkPdfNativeObject* ref) { |
| 539 if (ref && ref->isReference()) { | 550 if (ref && ref->isReference()) { |
| 540 int id = ref->referenceId(); | 551 int id = ref->referenceId(); |
| 541 // TODO(edisonn): generation/updates not supported now | 552 // TODO(edisonn): generation/updates not supported now |
| 542 //int gen = ref->referenceGeneration(); | 553 //int gen = ref->referenceGeneration(); |
| 543 | 554 |
| 544 // TODO(edisonn): verify id and gen expected | 555 // TODO(edisonn): verify id and gen expected |
| 545 if (id < 0 || id >= fObjects.count()) { | 556 if (id < 0 || id >= fObjects.count()) { |
| 546 // TODO(edisonn): report error/warning | 557 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kReadStreamError_SkPdfI
ssue, "resolve reference id out of bounds", NULL, NULL); |
| 547 return NULL; | 558 return NULL; |
| 548 } | 559 } |
| 549 | 560 |
| 550 if (fObjects[id].fIsReferenceResolved) { | 561 if (fObjects[id].fIsReferenceResolved) { |
| 551 | 562 |
| 552 #ifdef PDF_TRACE | 563 #ifdef PDF_TRACE |
| 553 printf("\nresolve(%s) = %s\n", ref->toString(0).c_str(), fObjects[id
].fResolvedReference->toString(0, ref->toString().size() + 13).c_str()); | 564 printf("\nresolve(%s) = %s\n", ref->toString(0).c_str(), fObjects[id
].fResolvedReference->toString(0, ref->toString().size() + 13).c_str()); |
| 554 #endif | 565 #endif |
| 555 | 566 |
| 556 // TODO(edisonn): for known good documents, assert here THAT THE REF
ERENCE IS NOT null | 567 SkPdfReportIf(!fObjects[id].fResolvedReference, kIgnoreError_SkPdfIs
sueSeverity, kBadReference_SkPdfIssue, "ref is NULL", NULL, NULL); |
| 557 return fObjects[id].fResolvedReference; | 568 return fObjects[id].fResolvedReference; |
| 558 } | 569 } |
| 559 | 570 |
| 560 // TODO(edisonn): there are pdfs in the crashing suite that cause a stac
k overflow here unless we check for resolved reference on next line | 571 // TODO(edisonn): there are pdfs in the crashing suite that cause a stac
k overflow here unless we check for resolved reference on next line |
| 561 // determine if the pdf is corrupted, or we have a bug here | 572 // determine if the pdf is corrupted, or we have a bug here |
| 562 | 573 |
| 563 // avoids recursive calls | 574 // avoids recursive calls |
| 564 fObjects[id].fIsReferenceResolved = true; | 575 fObjects[id].fIsReferenceResolved = true; |
| 565 | 576 |
| 566 if (fObjects[id].fObj == NULL) { | 577 if (fObjects[id].fObj == NULL) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 585 return (SkPdfNativeObject*)ref; | 596 return (SkPdfNativeObject*)ref; |
| 586 } | 597 } |
| 587 | 598 |
| 588 size_t SkPdfNativeDoc::bytesUsed() const { | 599 size_t SkPdfNativeDoc::bytesUsed() const { |
| 589 return fAllocator->bytesUsed() + | 600 return fAllocator->bytesUsed() + |
| 590 fContentLength + | 601 fContentLength + |
| 591 fObjects.count() * sizeof(PublicObjectEntry) + | 602 fObjects.count() * sizeof(PublicObjectEntry) + |
| 592 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + | 603 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + |
| 593 sizeof(*this); | 604 sizeof(*this); |
| 594 } | 605 } |
| OLD | NEW |