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 "SkPdfNativeObject.h" | 8 #include "SkPdfNativeObject.h" |
9 | 9 |
10 // TODO(edisonn): mac builder does not find the header ... but from headers is o
k | 10 // TODO(edisonn): mac builder does not find the header ... but from headers is o
k |
11 //#include "SkPdfStreamCommonDictionary_autogen.h" | 11 //#include "SkPdfStreamCommonDictionary_autogen.h" |
12 #include "SkPdfHeaders_autogen.h" | 12 #include "SkPdfHeaders_autogen.h" |
13 | 13 |
14 #include "SkFlate.h" | 14 #include "SkFlate.h" |
15 #include "SkStream.h" | 15 #include "SkStream.h" |
16 #include "SkPdfNativeTokenizer.h" | 16 #include "SkPdfNativeTokenizer.h" |
17 | 17 |
18 #include "SkBitmap.h" | 18 #include "SkBitmap.h" |
19 #include "SkPdfFont.h" | 19 #include "SkPdfFont.h" |
20 | 20 |
| 21 #include "SkPdfReporter.h" |
| 22 |
21 SkPdfNativeObject SkPdfNativeObject::kNull = SkPdfNativeObject::makeNull(PUT_TRA
CK_PARAMETERS_SRC0); | 23 SkPdfNativeObject SkPdfNativeObject::kNull = SkPdfNativeObject::makeNull(PUT_TRA
CK_PARAMETERS_SRC0); |
22 | 24 |
23 bool SkPdfNativeObject::applyFlateDecodeFilter() { | 25 bool SkPdfNativeObject::applyFlateDecodeFilter() { |
24 if (!SkFlate::HaveFlate()) { | 26 if (!SkFlate::HaveFlate()) { |
25 // TODO(edisonn): warn, make callers handle it | 27 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kNoFlateLibrary_SkPdfIssue,
"forgot to link with flate library?", NULL, NULL); |
26 return false; | 28 return false; |
27 } | 29 } |
28 | 30 |
29 const unsigned char* old = fStr.fBuffer; | 31 const unsigned char* old = fStr.fBuffer; |
30 bool deleteOld = isStreamOwned(); | 32 bool deleteOld = isStreamOwned(); |
31 | 33 |
32 SkMemoryStream skstream(fStr.fBuffer, fStr.fBytes >> 2, false); | 34 SkMemoryStream skstream(fStr.fBuffer, fStr.fBytes >> 2, false); |
33 SkDynamicMemoryWStream uncompressedData; | 35 SkDynamicMemoryWStream uncompressedData; |
34 | 36 |
35 if (SkFlate::Inflate(&skstream, &uncompressedData)) { | 37 if (SkFlate::Inflate(&skstream, &uncompressedData)) { |
36 fStr.fBytes = (uncompressedData.bytesWritten() << 2) + kOwnedStreamBit +
kUnfilteredStreamBit; | 38 fStr.fBytes = (uncompressedData.bytesWritten() << 2) + kOwnedStreamBit +
kUnfilteredStreamBit; |
37 fStr.fBuffer = (const unsigned char*)new unsigned char[uncompressedData.
bytesWritten()]; | 39 fStr.fBuffer = (const unsigned char*)new unsigned char[uncompressedData.
bytesWritten()]; |
38 uncompressedData.copyTo((void*)fStr.fBuffer); | 40 uncompressedData.copyTo((void*)fStr.fBuffer); |
39 | 41 |
40 if (deleteOld) { | 42 if (deleteOld) { |
41 delete[] old; | 43 delete[] old; |
42 } | 44 } |
43 | 45 |
44 return true; | 46 return true; |
45 } else { | 47 } else { |
46 // TODO(edisonn): warn, make callers handle it | 48 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kBadStream_SkPdfIssue, "inf
late failed", this, NULL); |
47 return false; | 49 return false; |
48 } | 50 } |
49 } | 51 } |
50 | 52 |
51 bool SkPdfNativeObject::applyDCTDecodeFilter() { | 53 bool SkPdfNativeObject::applyDCTDecodeFilter() { |
52 // this would fail, and it won't allow any more filters. | 54 // this would fail, and it won't allow any more filters. |
53 // technically, it would be possible, but not a real world scenario | 55 // technically, it would be possible, but not a real world scenario |
54 // TODO(edisonn): or get the image here and store it for fast retrieval? | 56 // TODO(edisonn): or get the image here and store it for fast retrieval? |
55 return false; | 57 return false; |
56 } | 58 } |
57 | 59 |
58 bool SkPdfNativeObject::applyFilter(const char* name) { | 60 bool SkPdfNativeObject::applyFilter(const char* name) { |
59 if (strcmp(name, "FlateDecode") == 0) { | 61 if (strcmp(name, "FlateDecode") == 0) { |
60 return applyFlateDecodeFilter(); | 62 return applyFlateDecodeFilter(); |
61 } else if (strcmp(name, "DCTDecode") == 0) { | 63 } else if (strcmp(name, "DCTDecode") == 0) { |
62 return applyDCTDecodeFilter(); | 64 return applyDCTDecodeFilter(); |
63 } | 65 } |
64 // TODO(edisonn): allert, not supported, but should be implemented asap | 66 SkPdfReport(kCodeWarning_SkPdfIssueSeverity, kNYI_SkPdfIssue, "filter not su
pported", this, NULL); |
65 return false; | 67 return false; |
66 } | 68 } |
67 | 69 |
68 bool SkPdfNativeObject::filterStream() { | 70 bool SkPdfNativeObject::filterStream() { |
69 SkPdfMarkObjectUsed(); | 71 SkPdfMarkObjectUsed(); |
70 | 72 |
71 if (!hasStream()) { | 73 if (!hasStream()) { |
| 74 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kBadStream_SkPdfIssue, "No
Stream", this, NULL); |
72 return false; | 75 return false; |
73 } | 76 } |
74 | 77 |
75 if (isStreamFiltered()) { | 78 if (isStreamFiltered()) { |
76 return true; | 79 return true; |
77 } | 80 } |
78 | 81 |
79 SkPdfStreamCommonDictionary* stream = (SkPdfStreamCommonDictionary*)this; | 82 SkPdfStreamCommonDictionary* stream = (SkPdfStreamCommonDictionary*)this; |
80 | 83 |
81 if (!stream->has_Filter()) { | 84 if (!stream->has_Filter()) { |
82 fStr.fBytes = ((fStr.fBytes >> 1) << 1) + kFilteredStreamBit; | 85 fStr.fBytes = ((fStr.fBytes >> 1) << 1) + kFilteredStreamBit; |
83 } else if (stream->isFilterAName(NULL)) { | 86 } else if (stream->isFilterAName(NULL)) { |
84 SkString filterName = stream->getFilterAsName(NULL); | 87 SkString filterName = stream->getFilterAsName(NULL); |
85 applyFilter(filterName.c_str()); | 88 applyFilter(filterName.c_str()); |
86 } else if (stream->isFilterAArray(NULL)) { | 89 } else if (stream->isFilterAArray(NULL)) { |
87 const SkPdfArray* filters = stream->getFilterAsArray(NULL); | 90 const SkPdfArray* filters = stream->getFilterAsArray(NULL); |
88 int cnt = filters->size(); | 91 int cnt = filters->size(); |
89 for (int i = cnt - 1; i >= 0; i--) { | 92 for (int i = cnt - 1; i >= 0; i--) { |
90 const SkPdfNativeObject* filterName = filters->objAtAIndex(i); | 93 const SkPdfNativeObject* filterName = filters->objAtAIndex(i); |
91 if (filterName != NULL && filterName->isName()) { | 94 if (filterName != NULL && filterName->isName()) { |
92 if (!applyFilter(filterName->nameValue())) { | 95 if (!applyFilter(filterName->nameValue())) { |
93 break; | 96 break; |
94 } | 97 } |
95 } else { | 98 } else { |
96 // TODO(edisonn): report warning | 99 SkPdfReport(kIgnoreError_SkPdfIssueSeverity, kIncositentSyntax_S
kPdfIssue, "filter name should be a Name", this, NULL); |
97 } | 100 } |
98 } | 101 } |
99 } | 102 } |
100 | 103 |
101 return true; | 104 return true; |
102 } | 105 } |
103 | 106 |
104 void SkPdfNativeObject::releaseData() { | 107 void SkPdfNativeObject::releaseData() { |
105 // TODO(edisonn): report here unused objects | 108 #ifdef PDF_TRACK_OBJECT_USAGE |
| 109 SkPdfReportIf(!fUsed, kInfo_SkPdfIssueSeverity, NULL, this, "Unused object i
n rendering"); |
| 110 #endif // PDF_TRACK_OBJECT_USAGE |
106 | 111 |
107 SkPdfMarkObjectUnused(); | 112 SkPdfMarkObjectUnused(); |
108 | 113 |
109 if (fData) { | 114 if (fData) { |
110 switch (fDataType) { | 115 switch (fDataType) { |
111 case kFont_Data: | 116 case kFont_Data: |
112 delete (SkPdfFont*)fData; | 117 delete (SkPdfFont*)fData; |
113 break; | 118 break; |
114 case kBitmap_Data: | 119 case kBitmap_Data: |
115 delete (SkBitmap*)fData; | 120 delete (SkBitmap*)fData; |
116 break; | 121 break; |
117 default: | 122 default: |
118 SkASSERT(false); | 123 SkASSERT(false); |
119 break; | 124 break; |
120 } | 125 } |
121 } | 126 } |
122 fData = NULL; | 127 fData = NULL; |
123 fDataType = kEmpty_Data; | 128 fDataType = kEmpty_Data; |
124 } | 129 } |
OLD | NEW |