pdfviewer: do not submit, uploaded for backup, and will be done actually after I refactor the params for functions, to put the char* params in a structure: report errors and warnings in pdf, infrastructure
Review URL: https://codereview.chromium.org/23902018 git-svn-id: http://skia.googlecode.com/svn/trunk@11262 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
1fb04e2540
commit
af54a513a5
@ -8,8 +8,12 @@
|
|||||||
#ifndef SkPdfConfig_DEFINED
|
#ifndef SkPdfConfig_DEFINED
|
||||||
#define SkPdfConfig_DEFINED
|
#define SkPdfConfig_DEFINED
|
||||||
|
|
||||||
|
#include "stddef.h"
|
||||||
|
class SkPdfNativeObject;
|
||||||
|
|
||||||
//#define PDF_TRACK_OBJECT_USAGE
|
//#define PDF_TRACK_OBJECT_USAGE
|
||||||
//#define PDF_TRACK_STREAM_OFFSETS
|
//#define PDF_TRACK_STREAM_OFFSETS
|
||||||
|
//#define PDF_REPORT
|
||||||
//#define PDF_TRACE
|
//#define PDF_TRACE
|
||||||
//#define PDF_TRACE_READ_TOKEN
|
//#define PDF_TRACE_READ_TOKEN
|
||||||
//#define PDF_TRACE_DRAWTEXT
|
//#define PDF_TRACE_DRAWTEXT
|
||||||
@ -73,5 +77,34 @@
|
|||||||
#define STORE_TRACK_PARAMETER_OFFSET_END(obj,offsetEnd)
|
#define STORE_TRACK_PARAMETER_OFFSET_END(obj,offsetEnd)
|
||||||
#endif //PDF_TRACK_STREAM_OFFSETS
|
#endif //PDF_TRACK_STREAM_OFFSETS
|
||||||
|
|
||||||
|
// TODO(edisonn): move it somewhere else?
|
||||||
|
struct SkPdfInputStream {
|
||||||
|
#ifdef PDF_TRACK_STREAM_OFFSETS
|
||||||
|
// no parent object -> original file to be rendered
|
||||||
|
// no parent file -> stream object
|
||||||
|
// both -> external stream object
|
||||||
|
int fParentFileID;
|
||||||
|
const SkPdfNativeObject* fParentObject;
|
||||||
|
|
||||||
|
size_t fDelta; // delta in parent stream
|
||||||
|
const unsigned char* fStart;
|
||||||
|
#endif // PDF_TRACK_STREAM_OFFSETS
|
||||||
|
|
||||||
|
const unsigned char* fEnd;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SkPdfInputStreamLocation {
|
||||||
|
SkPdfInputStream fInputStream;
|
||||||
|
const unsigned char* fNow;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef PDF_TRACK_STREAM_OFFSETS
|
||||||
|
struct SkPdfInputStreamRange {
|
||||||
|
SkPdfInputStream fInputStream;
|
||||||
|
const unsigned char* fRangeStart;
|
||||||
|
const unsigned char* fRangeEnd;
|
||||||
|
};
|
||||||
|
#endif // PDF_TRACK_STREAM_OFFSETS
|
||||||
|
|
||||||
|
|
||||||
#endif // SkPdfConfig_DEFINED
|
#endif // SkPdfConfig_DEFINED
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -9,11 +9,17 @@
|
|||||||
#ifndef SkPdfRenderer_DEFINED
|
#ifndef SkPdfRenderer_DEFINED
|
||||||
#define SkPdfRenderer_DEFINED
|
#define SkPdfRenderer_DEFINED
|
||||||
|
|
||||||
|
// TODO(edisonn): how to remove this dependency? Should I remove the ref counting?
|
||||||
|
#include "SkRefCnt.h"
|
||||||
|
// TODO(edisonn): remove this dependency
|
||||||
|
#include "SkString.h"
|
||||||
|
|
||||||
class SkBitmap;
|
class SkBitmap;
|
||||||
class SkCanvas;
|
class SkCanvas;
|
||||||
class SkPdfNativeDoc;
|
class SkPdfNativeDoc;
|
||||||
struct SkRect;
|
struct SkRect;
|
||||||
class SkStream;
|
class SkStream;
|
||||||
|
class SkString;
|
||||||
|
|
||||||
enum SkPdfContent {
|
enum SkPdfContent {
|
||||||
kNoForms_SkPdfContent,
|
kNoForms_SkPdfContent,
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "SkPdfNativeDoc.h"
|
#include "SkPdfNativeDoc.h"
|
||||||
#include "SkPdfNativeTokenizer.h"
|
#include "SkPdfNativeTokenizer.h"
|
||||||
#include "SkPdfNativeObject.h"
|
#include "SkPdfNativeObject.h"
|
||||||
|
#include "SkPdfReporter.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -107,7 +108,7 @@ SkPdfNativeDoc::SkPdfNativeDoc(const char* path)
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
sk_free(content);
|
sk_free(content);
|
||||||
// TODO(edisonn): report read error
|
SkPdfReport(kFatalError_SkPdfIssueSeverity, kReadStreamError_SkPdfIssue, "could not read file", NULL, NULL);
|
||||||
// TODO(edisonn): not nice to return like this from constructor, create a static
|
// TODO(edisonn): not nice to return like this from constructor, create a static
|
||||||
// function that can report NULL for failures.
|
// function that can report NULL for failures.
|
||||||
return; // Doc will have 0 pages
|
return; // Doc will have 0 pages
|
||||||
@ -125,7 +126,7 @@ void SkPdfNativeDoc::init(const void* bytes, size_t length) {
|
|||||||
const unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, xrefByteOffsetLine);
|
const unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, xrefByteOffsetLine);
|
||||||
|
|
||||||
if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) {
|
if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) {
|
||||||
// TODO(edisonn): report/issue
|
SkPdfReport(kWarning_SkPdfIssueSeverity, kMissingToken_SkPdfIssue, "Could not find startxref", NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
long xrefByteOffset = atol((const char*)xrefByteOffsetLine);
|
long xrefByteOffset = atol((const char*)xrefByteOffsetLine);
|
||||||
@ -189,6 +190,7 @@ void SkPdfNativeDoc::loadWithoutXRef() {
|
|||||||
current = nextObject(0, current, end, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, end, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
// TODO(edisonn): must be obj, return error if not? ignore ?
|
// TODO(edisonn): must be obj, return error if not? ignore ?
|
||||||
if (!token.isKeyword("obj")) {
|
if (!token.isKeyword("obj")) {
|
||||||
|
SkPdfReport(kWarning_SkPdfIssueSeverity, kMissingToken_SkPdfIssue, "Could not find obj", NULL, NULL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,6 +205,8 @@ void SkPdfNativeDoc::loadWithoutXRef() {
|
|||||||
|
|
||||||
fObjects[id].fResolvedReference = obj;
|
fObjects[id].fResolvedReference = obj;
|
||||||
fObjects[id].fObj = obj;
|
fObjects[id].fObj = obj;
|
||||||
|
fObjects[id].fIsReferenceResolved = true;
|
||||||
|
|
||||||
|
|
||||||
// set objects
|
// set objects
|
||||||
} else if (token.isKeyword("trailer")) {
|
} else if (token.isKeyword("trailer")) {
|
||||||
@ -227,7 +231,6 @@ void SkPdfNativeDoc::loadWithoutXRef() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (fRootCatalogRef) {
|
if (fRootCatalogRef) {
|
||||||
fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef);
|
fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef);
|
||||||
if (fRootCatalog->isDictionary() && fRootCatalog->valid()) {
|
if (fRootCatalog->isDictionary() && fRootCatalog->valid()) {
|
||||||
@ -252,6 +255,7 @@ const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned ch
|
|||||||
const unsigned char* current = nextObject(0, xrefStart, trailerEnd, &xref, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
const unsigned char* current = nextObject(0, xrefStart, trailerEnd, &xref, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
|
|
||||||
if (!xref.isKeyword("xref")) {
|
if (!xref.isKeyword("xref")) {
|
||||||
|
SkPdfReport(kWarning_SkPdfIssueSeverity, kMissingToken_SkPdfIssue, "Could not find sref", NULL, NULL);
|
||||||
return trailerEnd;
|
return trailerEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,6 +265,7 @@ const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned ch
|
|||||||
const unsigned char* previous = current;
|
const unsigned char* previous = current;
|
||||||
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
if (!token.isInteger()) {
|
if (!token.isInteger()) {
|
||||||
|
SkPdfReport(kInfo_SkPdfIssueSeverity, kNoIssue_SkPdfIssue, "Done readCrossReferenceSection", NULL, NULL);
|
||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +274,7 @@ const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned ch
|
|||||||
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
|
|
||||||
if (!token.isInteger()) {
|
if (!token.isInteger()) {
|
||||||
// TODO(edisonn): report/warning
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readCrossReferenceSection", &token, SkPdfNativeObject::kInteger_PdfObjectType, NULL);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +284,7 @@ const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned ch
|
|||||||
token.reset();
|
token.reset();
|
||||||
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
if (!token.isInteger()) {
|
if (!token.isInteger()) {
|
||||||
// TODO(edisonn): report/warning
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readCrossReferenceSection", &token, SkPdfNativeObject::kInteger_PdfObjectType, NULL);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
int offset = (int)token.intValue();
|
int offset = (int)token.intValue();
|
||||||
@ -287,7 +292,7 @@ const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned ch
|
|||||||
token.reset();
|
token.reset();
|
||||||
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
if (!token.isInteger()) {
|
if (!token.isInteger()) {
|
||||||
// TODO(edisonn): report/warning
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readCrossReferenceSection", &token, SkPdfNativeObject::kInteger_PdfObjectType, NULL);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
int generation = (int)token.intValue();
|
int generation = (int)token.intValue();
|
||||||
@ -295,14 +300,14 @@ const unsigned char* SkPdfNativeDoc::readCrossReferenceSection(const unsigned ch
|
|||||||
token.reset();
|
token.reset();
|
||||||
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, trailerEnd, &token, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
if (!token.isKeyword() || token.lenstr() != 1 || (*token.c_str() != 'f' && *token.c_str() != 'n')) {
|
if (!token.isKeyword() || token.lenstr() != 1 || (*token.c_str() != 'f' && *token.c_str() != 'n')) {
|
||||||
// TODO(edisonn): report/warning
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readCrossReferenceSection: f or n expected", &token, SkPdfNativeObject::kKeyword_PdfObjectType, NULL);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
addCrossSectionInfo(startId + i, generation, offset, *token.c_str() == 'f');
|
addCrossSectionInfo(startId + i, generation, offset, *token.c_str() == 'f');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO(edisonn): it should never get here? there is no trailer?
|
SkPdfReport(kInfo_SkPdfIssueSeverity, kNoIssue_SkPdfIssue, "Unexpected end of readCrossReferenceSection", NULL, NULL);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,6 +324,7 @@ const unsigned char* SkPdfNativeDoc::readTrailer(const unsigned char* trailerSta
|
|||||||
if (!trailerKeyword.isKeyword() || strlen("trailer") != trailerKeyword.lenstr() ||
|
if (!trailerKeyword.isKeyword() || strlen("trailer") != trailerKeyword.lenstr() ||
|
||||||
strncmp(trailerKeyword.c_str(), "trailer", strlen("trailer")) != 0) {
|
strncmp(trailerKeyword.c_str(), "trailer", strlen("trailer")) != 0) {
|
||||||
// TODO(edisonn): report warning, rebuild trailer from objects.
|
// TODO(edisonn): report warning, rebuild trailer from objects.
|
||||||
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readTrailer: trailer keyword expected", &trailerKeyword, SkPdfNativeObject::kKeyword_PdfObjectType, NULL);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,7 +342,7 @@ const unsigned char* SkPdfNativeDoc::readTrailer(const unsigned char* trailerSta
|
|||||||
if (storeCatalog) {
|
if (storeCatalog) {
|
||||||
SkPdfNativeObject* ref = trailer->Root(NULL);
|
SkPdfNativeObject* ref = trailer->Root(NULL);
|
||||||
if (ref == NULL || !ref->isReference()) {
|
if (ref == NULL || !ref->isReference()) {
|
||||||
// TODO(edisonn): oops, we have to fix the corrup pdf file
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readTrailer: unexpected root reference", ref, SkPdfNativeObject::kReference_PdfObjectType, NULL);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
fRootCatalogRef = ref;
|
fRootCatalogRef = ref;
|
||||||
@ -381,28 +387,33 @@ SkPdfNativeObject* SkPdfNativeDoc::readObject(int id/*, int expectedGeneration*/
|
|||||||
|
|
||||||
current = nextObject(0, current, end, &idObj, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, end, &idObj, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
if (current >= end) {
|
if (current >= end) {
|
||||||
// TODO(edisonn): report warning/error
|
SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kReadStreamError_SkPdfIssue, "reading id", NULL, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
current = nextObject(0, current, end, &generationObj, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, end, &generationObj, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
if (current >= end) {
|
if (current >= end) {
|
||||||
// TODO(edisonn): report warning/error
|
SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kReadStreamError_SkPdfIssue, "reading generation", NULL, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
current = nextObject(0, current, end, &objKeyword, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(0, current, end, &objKeyword, NULL, NULL PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
if (current >= end) {
|
if (current >= end) {
|
||||||
// TODO(edisonn): report warning/error
|
SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kReadStreamError_SkPdfIssue, "reading keyword obj", NULL, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!idObj.isInteger() || !generationObj.isInteger() || id != idObj.intValue()/* || generation != generationObj.intValue()*/) {
|
if (!idObj.isInteger() || id != idObj.intValue()) {
|
||||||
// TODO(edisonn): report warning/error
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readObject: unexpected id", &idObj, SkPdfNativeObject::kInteger_PdfObjectType, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(edisonn): verify that the generation is the right one
|
||||||
|
if (!generationObj.isInteger() /* || generation != generationObj.intValue()*/) {
|
||||||
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readObject: unexpected generation", &generationObj, SkPdfNativeObject::kInteger_PdfObjectType, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!objKeyword.isKeyword() || strcmp(objKeyword.c_str(), "obj") != 0) {
|
if (!objKeyword.isKeyword() || strcmp(objKeyword.c_str(), "obj") != 0) {
|
||||||
// TODO(edisonn): report warning/error
|
SkPdfReportUnexpectedType(kIgnoreError_SkPdfIssueSeverity, "readObject: unexpected obj keyword", &objKeyword, SkPdfNativeObject::kKeyword_PdfObjectType, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
current = nextObject(1, current, end, dict, fAllocator, this PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
current = nextObject(1, current, end, dict, fAllocator, this PUT_TRACK_STREAM_ARGS_EXPL2(0, fFileContent));
|
||||||
@ -543,7 +554,7 @@ SkPdfNativeObject* SkPdfNativeDoc::resolveReference(SkPdfNativeObject* ref) {
|
|||||||
|
|
||||||
// TODO(edisonn): verify id and gen expected
|
// TODO(edisonn): verify id and gen expected
|
||||||
if (id < 0 || id >= fObjects.count()) {
|
if (id < 0 || id >= fObjects.count()) {
|
||||||
// TODO(edisonn): report error/warning
|
SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kReadStreamError_SkPdfIssue, "resolve reference id out of bounds", NULL, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,7 +564,7 @@ SkPdfNativeObject* SkPdfNativeDoc::resolveReference(SkPdfNativeObject* ref) {
|
|||||||
printf("\nresolve(%s) = %s\n", ref->toString(0).c_str(), fObjects[id].fResolvedReference->toString(0, ref->toString().size() + 13).c_str());
|
printf("\nresolve(%s) = %s\n", ref->toString(0).c_str(), fObjects[id].fResolvedReference->toString(0, ref->toString().size() + 13).c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO(edisonn): for known good documents, assert here THAT THE REFERENCE IS NOT null
|
SkPdfReportIf(!fObjects[id].fResolvedReference, kIgnoreError_SkPdfIssueSeverity, kBadReference_SkPdfIssue, "ref is NULL", NULL, NULL);
|
||||||
return fObjects[id].fResolvedReference;
|
return fObjects[id].fResolvedReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,11 +18,13 @@
|
|||||||
#include "SkBitmap.h"
|
#include "SkBitmap.h"
|
||||||
#include "SkPdfFont.h"
|
#include "SkPdfFont.h"
|
||||||
|
|
||||||
|
#include "SkPdfReporter.h"
|
||||||
|
|
||||||
SkPdfNativeObject SkPdfNativeObject::kNull = SkPdfNativeObject::makeNull(PUT_TRACK_PARAMETERS_SRC0);
|
SkPdfNativeObject SkPdfNativeObject::kNull = SkPdfNativeObject::makeNull(PUT_TRACK_PARAMETERS_SRC0);
|
||||||
|
|
||||||
bool SkPdfNativeObject::applyFlateDecodeFilter() {
|
bool SkPdfNativeObject::applyFlateDecodeFilter() {
|
||||||
if (!SkFlate::HaveFlate()) {
|
if (!SkFlate::HaveFlate()) {
|
||||||
// TODO(edisonn): warn, make callers handle it
|
SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kNoFlateLibrary_SkPdfIssue, "forgot to link with flate library?", NULL, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ bool SkPdfNativeObject::applyFlateDecodeFilter() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// TODO(edisonn): warn, make callers handle it
|
SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kBadStream_SkPdfIssue, "inflate failed", this, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +63,7 @@ bool SkPdfNativeObject::applyFilter(const char* name) {
|
|||||||
} else if (strcmp(name, "DCTDecode") == 0) {
|
} else if (strcmp(name, "DCTDecode") == 0) {
|
||||||
return applyDCTDecodeFilter();
|
return applyDCTDecodeFilter();
|
||||||
}
|
}
|
||||||
// TODO(edisonn): allert, not supported, but should be implemented asap
|
SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "filter not supported", this, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +71,7 @@ bool SkPdfNativeObject::filterStream() {
|
|||||||
SkPdfMarkObjectUsed();
|
SkPdfMarkObjectUsed();
|
||||||
|
|
||||||
if (!hasStream()) {
|
if (!hasStream()) {
|
||||||
|
SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kBadStream_SkPdfIssue, "No Stream", this, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +96,7 @@ bool SkPdfNativeObject::filterStream() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO(edisonn): report warning
|
SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kIncositentSyntax_SkPdfIssue, "filter name should be a Name", this, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +105,9 @@ bool SkPdfNativeObject::filterStream() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SkPdfNativeObject::releaseData() {
|
void SkPdfNativeObject::releaseData() {
|
||||||
// TODO(edisonn): report here unused objects
|
#ifdef PDF_TRACK_OBJECT_USAGE
|
||||||
|
SkPdfReportIf(!fUsed, kInfo_SkPdfIssueSeverity, NULL, this, "Unused object in rendering");
|
||||||
|
#endif // PDF_TRACK_OBJECT_USAGE
|
||||||
|
|
||||||
SkPdfMarkObjectUnused();
|
SkPdfMarkObjectUnused();
|
||||||
|
|
||||||
|
@ -38,25 +38,31 @@ SkMatrix SkMatrixFromPdfMatrix(double array[6]);
|
|||||||
class SkPdfNativeObject {
|
class SkPdfNativeObject {
|
||||||
public:
|
public:
|
||||||
enum ObjectType {
|
enum ObjectType {
|
||||||
kInvalid_PdfObjectType,
|
// The type will have only one of these values, but for error reporting, we make it an enum
|
||||||
|
// so it can easily report that something was expected to be one of a few types
|
||||||
|
kInvalid_PdfObjectType = 1 << 1,
|
||||||
|
|
||||||
kBoolean_PdfObjectType,
|
kBoolean_PdfObjectType = 1 << 2,
|
||||||
kInteger_PdfObjectType,
|
kInteger_PdfObjectType = 1 << 3,
|
||||||
kReal_PdfObjectType,
|
kReal_PdfObjectType = 1 << 4,
|
||||||
kString_PdfObjectType,
|
_kNumber_PdfObjectType = kInteger_PdfObjectType | kReal_PdfObjectType,
|
||||||
kHexString_PdfObjectType,
|
kString_PdfObjectType = 1 << 5,
|
||||||
kName_PdfObjectType,
|
kHexString_PdfObjectType = 1 << 6,
|
||||||
kKeyword_PdfObjectType,
|
_kAnyString_PdfObjectType = kString_PdfObjectType | kHexString_PdfObjectType,
|
||||||
//kStream_PdfObjectType, // attached to a Dictionary
|
kName_PdfObjectType = 1 << 7,
|
||||||
kArray_PdfObjectType,
|
kKeyword_PdfObjectType = 1 << 8,
|
||||||
kDictionary_PdfObjectType,
|
_kStream_PdfObjectType = 1 << 9, // attached to a Dictionary, do not use
|
||||||
kNull_PdfObjectType,
|
kArray_PdfObjectType = 1 << 10,
|
||||||
|
kDictionary_PdfObjectType = 1 << 11,
|
||||||
|
kNull_PdfObjectType = 1 << 12,
|
||||||
|
|
||||||
// TODO(edisonn): after the pdf has been loaded completely, resolve all references
|
// TODO(edisonn): after the pdf has been loaded completely, resolve all references
|
||||||
// try the same thing with delayed loaded ...
|
// try the same thing with delayed loaded ...
|
||||||
kReference_PdfObjectType,
|
kReference_PdfObjectType = 1 << 13,
|
||||||
|
|
||||||
kUndefined_PdfObjectType, // per 1.4 spec, if the same key appear twice in the dictionary, the value is undefined
|
kUndefined_PdfObjectType = 1 << 14, // per 1.4 spec, if the same key appear twice in the dictionary, the value is undefined
|
||||||
|
|
||||||
|
_kObject_PdfObjectType = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DataType {
|
enum DataType {
|
||||||
|
@ -811,11 +811,15 @@ const unsigned char* nextObject(int level, const unsigned char* start, const uns
|
|||||||
// skip white spaces
|
// skip white spaces
|
||||||
start = skipPdfWhiteSpaces(level, start, end);
|
start = skipPdfWhiteSpaces(level, start, end);
|
||||||
|
|
||||||
|
if (start >= end) {
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
current = endOfPdfToken(level, start, end);
|
current = endOfPdfToken(level, start, end);
|
||||||
|
|
||||||
// no token, len would be 0
|
// no token, len would be 0
|
||||||
if (current == start) {
|
if (current == start || current == end) {
|
||||||
return NULL;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tokenLen = current - start;
|
int tokenLen = current - start;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
'../experimental/PdfViewer/SkPdfGraphicsState.cpp',
|
'../experimental/PdfViewer/SkPdfGraphicsState.cpp',
|
||||||
'../experimental/PdfViewer/SkPdfFont.cpp',
|
'../experimental/PdfViewer/SkPdfFont.cpp',
|
||||||
'../experimental/PdfViewer/SkPdfRenderer.cpp',
|
'../experimental/PdfViewer/SkPdfRenderer.cpp',
|
||||||
|
'../experimental/PdfViewer/SkPdfReporter.cpp',
|
||||||
'../experimental/PdfViewer/SkPdfUtils.cpp',
|
'../experimental/PdfViewer/SkPdfUtils.cpp',
|
||||||
#'../experimental/PdfViewer/SkPdfNYI.cpp',
|
#'../experimental/PdfViewer/SkPdfNYI.cpp',
|
||||||
'../experimental/PdfViewer/SkTrackDevice.cpp',
|
'../experimental/PdfViewer/SkTrackDevice.cpp',
|
||||||
|
Loading…
Reference in New Issue
Block a user