1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 
9 #ifndef SkPdfReporter_DEFINED
10 #define SkPdfReporter_DEFINED
11 
12 #include "SkPdfConfig.h"
13 
14 class SkPdfNativeObject;
15 class SkPdfContext;
16 
17 // TODO(edisonn): ability to turn on asserts for known good files
18 
19 // Severity of the issue, if it something interesting info, the result of an NYI feature,
20 // sme ignorable defect in pdf or a major issue.
21 enum SkPdfIssueSeverity {
22     kInfo_SkPdfIssueSeverity,
23     kCodeWarning_SkPdfIssueSeverity, // e.g. like NYI, PDF file is Ok.
24     kWarning_SkPdfIssueSeverity,
25     kIgnoreError_SkPdfIssueSeverity,
26     kError_SkPdfIssueSeverity,
27     kFatalError_SkPdfIssueSeverity,
28 
29     _kCount__SkPdfIssueSeverity
30 };
31 
32 // The type of the issue.
33 enum SkPdfIssue {
34     kNoIssue_SkPdfIssue,
35 
36     kNullObject_SkPdfIssue,
37     kUnusedObject_SkPdfIssue,
38     kUnexpectedArraySize_SkPdfIssue,
39     kMissingEncoding_SkPdfIssue,
40     kNYI_SkPdfIssue,
41     kIncostistentSizes_SkPdfIssue,
42     kMissingRequiredKey_SkPdfIssue,
43     kRecursiveReferencing_SkPdfIssue,
44     kStackNestingOverflow_SkPdfIssue,
45     kStackOverflow_SkPdfIssue,
46     kIncositentSyntax_SkPdfIssue,
47     kMissingFont_SkPdfIssue,
48     kInvalidFont_SkPdfIssue,
49     kMissingBT_SkPdfIssue,
50     kOutOfRange_SkPdfIssue,
51     kUnknownBlendMode_SkPdfIssue,
52     kMissingExtGState_SkPdfIssue,
53     kMissingXObject_SkPdfIssue,
54     kReadStreamError_SkPdfIssue,
55     kMissingToken_SkPdfIssue,
56     kBadReference_SkPdfIssue,
57     kNoFlateLibrary_SkPdfIssue,
58     kBadStream_SkPdfIssue,
59 
60     _kCount__SkPdfIssue
61 };
62 
63 #ifdef PDF_REPORT
64 
65 // Calls SkPdfReport(...) if report is true.
66 void SkPdfReportIf(bool report,
67                    SkPdfIssueSeverity sev, SkPdfIssue issue,
68                    const char* context,
69                    const SkPdfNativeObject* obj,
70                    SkPdfContext* pdfContext);
71 
72 // Reports an issue, along with information where it happened, for example obj can be used to report
73 // where exactly in th pdf there is a corruption
74 // TODO(edisonn): add ability to report the callstack
75 void SkPdfReport(SkPdfIssueSeverity sev, SkPdfIssue issue,
76                  const char* context,
77                  const SkPdfNativeObject* obj,
78                  SkPdfContext* pdfContext);
79 
80 // Reports that an object does not have the expected type
81 // TODO(edisonn): replace with SkPdfReportIfUnexpectedType() to simplify the callers?
82 // TODO(edisonn): pass the keyword/operator too which triggers the issue.
83 void SkPdfReportUnexpectedType(SkPdfIssueSeverity sev,
84                                const char* context,
85                                const SkPdfNativeObject* obj, int anyOfTypes,
86                                SkPdfContext* pdfContext);
87 
88 // Code only in builds with reporting turn on.
89 #define SkPdfREPORTCODE(code) code
90 
91 #else  // !PDF_REPORT
92 
93 #define SkPdfReportIf(a,b,c,d,e,f)
94 #define SkPdfReport(a,b,c,d,e)
95 #define SkPdfReportUnexpectedType(a,b,c,d,e)
96 #define SkPdfREPORTCODE(code)
97 
98 #endif  // PDF_REPORT
99 
100 #endif   // SkPdfReporter_DEFINED
101