muhammara 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/node_modules/@mapbox/node-pre-gyp/CHANGELOG.md +3 -0
- package/node_modules/@mapbox/node-pre-gyp/package.json +6 -7
- package/node_modules/ansi-regex/package.json +1 -2
- package/node_modules/brace-expansion/package.json +2 -1
- package/node_modules/gauge/CHANGELOG.md +163 -0
- package/node_modules/gauge/LICENSE +13 -0
- package/node_modules/gauge/README.md +1 -1
- package/node_modules/gauge/{lib/base-theme.js → base-theme.js} +3 -7
- package/node_modules/gauge/{lib/error.js → error.js} +0 -0
- package/node_modules/gauge/{lib/has-color.js → has-color.js} +0 -0
- package/node_modules/gauge/{lib/index.js → index.js} +32 -89
- package/node_modules/gauge/package.json +42 -37
- package/node_modules/gauge/{lib/plumbing.js → plumbing.js} +1 -3
- package/node_modules/gauge/{lib/process.js → process.js} +0 -0
- package/node_modules/gauge/{lib/progress-bar.js → progress-bar.js} +5 -11
- package/node_modules/gauge/{lib/render-template.js → render-template.js} +24 -68
- package/node_modules/gauge/{lib/set-immediate.js → set-immediate.js} +0 -0
- package/node_modules/gauge/{lib/set-interval.js → set-interval.js} +0 -0
- package/node_modules/gauge/{lib/spin.js → spin.js} +0 -0
- package/node_modules/gauge/{lib/template-item.js → template-item.js} +6 -21
- package/node_modules/gauge/{lib/theme-set.js → theme-set.js} +23 -31
- package/node_modules/gauge/{lib/themes.js → themes.js} +13 -13
- package/node_modules/gauge/{lib/wide-truncate.js → wide-truncate.js} +3 -9
- package/node_modules/minimatch/README.md +22 -1
- package/node_modules/minimatch/minimatch.js +93 -69
- package/node_modules/minimatch/package.json +11 -10
- package/node_modules/minipass/index.js +6 -1
- package/node_modules/minipass/package.json +5 -5
- package/node_modules/node-fetch/lib/index.es.js +28 -2
- package/node_modules/node-fetch/lib/index.js +28 -2
- package/node_modules/node-fetch/lib/index.mjs +28 -2
- package/node_modules/node-fetch/package.json +13 -5
- package/node_modules/npmlog/LICENSE +15 -0
- package/node_modules/npmlog/{lib/log.js → log.js} +9 -9
- package/node_modules/npmlog/package.json +20 -31
- package/node_modules/object-assign/index.js +90 -0
- package/node_modules/object-assign/license +21 -0
- package/node_modules/object-assign/package.json +74 -0
- package/node_modules/object-assign/readme.md +61 -0
- package/node_modules/signal-exit/index.js +4 -2
- package/node_modules/signal-exit/package.json +5 -5
- package/package.json +1 -1
- package/src/deps/PDFWriter/CMakeLists.txt +8 -0
- package/src/deps/PDFWriter/DecryptionHelper.cpp +10 -8
- package/src/deps/PDFWriter/Deletable.h +46 -0
- package/src/deps/PDFWriter/DocumentContext.h +3 -3
- package/src/deps/PDFWriter/IDeletable.h +6 -0
- package/src/deps/PDFWriter/InputLZWDecodeStream.cpp +208 -0
- package/src/deps/PDFWriter/InputLZWDecodeStream.h +77 -0
- package/src/deps/PDFWriter/InputStreamSkipperStream.cpp +1 -1
- package/src/deps/PDFWriter/JPEGImageHandler.h +2 -2
- package/src/deps/PDFWriter/ObjectsContext.cpp +5 -0
- package/src/deps/PDFWriter/ObjectsContext.h +1 -0
- package/src/deps/PDFWriter/PDFDocumentHandler.cpp +19 -3
- package/src/deps/PDFWriter/PDFObject.cpp +13 -11
- package/src/deps/PDFWriter/PDFObject.h +7 -5
- package/src/deps/PDFWriter/PDFObjectParser.cpp +8 -0
- package/src/deps/PDFWriter/PDFObjectParser.h +6 -0
- package/src/deps/PDFWriter/PDFParser.cpp +25 -13
- package/src/deps/PDFWriter/PDFParserTokenizer.cpp +25 -24
- package/src/deps/PDFWriter/PDFParserTokenizer.h +1 -0
- package/src/deps/PDFWriter/PDFWriter.h +2 -2
- package/src/deps/PDFWriter/binding.gyp +2 -0
- package/node_modules/gauge/LICENSE.md +0 -20
- package/node_modules/gauge/lib/demo.js +0 -45
- package/node_modules/npmlog/LICENSE.md +0 -20
- package/src/deps/PDFWriter/InputPredictorPNGAverageStream.cpp +0 -120
- package/src/deps/PDFWriter/InputPredictorPNGAverageStream.h +0 -49
- package/src/deps/PDFWriter/InputPredictorPNGNoneStream.cpp +0 -109
- package/src/deps/PDFWriter/InputPredictorPNGNoneStream.h +0 -47
- package/src/deps/PDFWriter/InputPredictorPNGPaethStream.cpp +0 -136
- package/src/deps/PDFWriter/InputPredictorPNGPaethStream.h +0 -51
- package/src/deps/PDFWriter/InputPredictorPNGSubStream.cpp +0 -113
- package/src/deps/PDFWriter/InputPredictorPNGSubStream.h +0 -47
- package/src/deps/PDFWriter/InputPredictorPNGUpStream.cpp +0 -120
- package/src/deps/PDFWriter/InputPredictorPNGUpStream.h +0 -49
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Source File : InputLZWDecodeStream.cpp
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Copyright 2011 Gal Kahana PDFWriter
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
*/
|
|
21
|
+
#include "InputLZWDecodeStream.h"
|
|
22
|
+
|
|
23
|
+
#include "Trace.h"
|
|
24
|
+
#include "zlib.h"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
InputLZWDecodeStream::InputLZWDecodeStream(int early)
|
|
28
|
+
{
|
|
29
|
+
mSourceStream = NULL;
|
|
30
|
+
mCurrentlyEncoding = false;
|
|
31
|
+
mEarly = early;
|
|
32
|
+
inputBuf = 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
InputLZWDecodeStream::~InputLZWDecodeStream(void)
|
|
36
|
+
{
|
|
37
|
+
if(mCurrentlyEncoding)
|
|
38
|
+
FinalizeEncoding();
|
|
39
|
+
if(mSourceStream)
|
|
40
|
+
delete mSourceStream;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void InputLZWDecodeStream::FinalizeEncoding()
|
|
44
|
+
{
|
|
45
|
+
mCurrentlyEncoding = false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
InputLZWDecodeStream::InputLZWDecodeStream(IByteReader* inSourceReader)
|
|
49
|
+
{
|
|
50
|
+
mSourceStream = NULL;
|
|
51
|
+
mCurrentlyEncoding = false;
|
|
52
|
+
|
|
53
|
+
Assign(inSourceReader);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
void InputLZWDecodeStream::Assign(IByteReader* inSourceReader)
|
|
57
|
+
{
|
|
58
|
+
mSourceStream = inSourceReader;
|
|
59
|
+
if(mSourceStream)
|
|
60
|
+
StartEncoding();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void InputLZWDecodeStream::StartEncoding()
|
|
64
|
+
{
|
|
65
|
+
mCurrentlyEncoding = true;
|
|
66
|
+
|
|
67
|
+
inputBits = 0;
|
|
68
|
+
ClearTable();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
IOBasicTypes::LongBufferSizeType InputLZWDecodeStream::Read(IOBasicTypes::Byte* inBuffer, IOBasicTypes::LongBufferSizeType inBufferSize)
|
|
72
|
+
{
|
|
73
|
+
if (mCurrentlyEncoding)
|
|
74
|
+
{
|
|
75
|
+
if (seqIndex >= seqLength)
|
|
76
|
+
{
|
|
77
|
+
if (!ProcessNextCode())
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
memcpy(inBuffer, &seqBuf[seqIndex], 1);
|
|
81
|
+
seqIndex++;
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
bool InputLZWDecodeStream::ProcessNextCode()
|
|
88
|
+
{
|
|
89
|
+
int code;
|
|
90
|
+
int nextLength;
|
|
91
|
+
int i, j;
|
|
92
|
+
|
|
93
|
+
// check for EOF
|
|
94
|
+
bool ret = false;
|
|
95
|
+
do
|
|
96
|
+
{
|
|
97
|
+
if (!mCurrentlyEncoding)
|
|
98
|
+
break;
|
|
99
|
+
// check for eod and clear-table codes
|
|
100
|
+
do
|
|
101
|
+
{
|
|
102
|
+
code = GetCode();
|
|
103
|
+
if (code == -1 || code == 257)
|
|
104
|
+
{
|
|
105
|
+
mCurrentlyEncoding = false;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (code == 256)
|
|
109
|
+
{
|
|
110
|
+
ClearTable();
|
|
111
|
+
}
|
|
112
|
+
} while (code == 256);
|
|
113
|
+
|
|
114
|
+
if(!mCurrentlyEncoding)
|
|
115
|
+
break;
|
|
116
|
+
|
|
117
|
+
if (nextCode >= 4097)
|
|
118
|
+
{
|
|
119
|
+
//error(getPos(), "Bad LZW stream - expected clear-table code");
|
|
120
|
+
ClearTable();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// process the next code
|
|
124
|
+
nextLength = seqLength + 1;
|
|
125
|
+
if (code < 256)
|
|
126
|
+
{
|
|
127
|
+
seqBuf[0] = code;
|
|
128
|
+
seqLength = 1;
|
|
129
|
+
}
|
|
130
|
+
else if (code < nextCode)
|
|
131
|
+
{
|
|
132
|
+
seqLength = table[code].length;
|
|
133
|
+
for (i = seqLength - 1, j = code; i > 0; --i) {
|
|
134
|
+
seqBuf[i] = table[j].tail;
|
|
135
|
+
j = table[j].head;
|
|
136
|
+
}
|
|
137
|
+
seqBuf[0] = j;
|
|
138
|
+
}
|
|
139
|
+
else if (code == nextCode)
|
|
140
|
+
{
|
|
141
|
+
seqBuf[seqLength] = newChar;
|
|
142
|
+
++seqLength;
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
{
|
|
146
|
+
//error(getPos(), "Bad LZW stream - unexpected code");
|
|
147
|
+
mCurrentlyEncoding = false;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
newChar = seqBuf[0];
|
|
151
|
+
if (first) {
|
|
152
|
+
first = false;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
table[nextCode].length = nextLength;
|
|
156
|
+
table[nextCode].head = prevCode;
|
|
157
|
+
table[nextCode].tail = newChar;
|
|
158
|
+
++nextCode;
|
|
159
|
+
if (nextCode + mEarly == 512)
|
|
160
|
+
nextBits = 10;
|
|
161
|
+
else if (nextCode + mEarly == 1024)
|
|
162
|
+
nextBits = 11;
|
|
163
|
+
else if (nextCode + mEarly == 2048)
|
|
164
|
+
nextBits = 12;
|
|
165
|
+
}
|
|
166
|
+
prevCode = code;
|
|
167
|
+
|
|
168
|
+
// reset buffer
|
|
169
|
+
seqIndex = 0;
|
|
170
|
+
|
|
171
|
+
ret = true;
|
|
172
|
+
|
|
173
|
+
} while (false);
|
|
174
|
+
return ret;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
void InputLZWDecodeStream::ClearTable() {
|
|
179
|
+
nextCode = 258;
|
|
180
|
+
nextBits = 9;
|
|
181
|
+
seqIndex = seqLength = 0;
|
|
182
|
+
first = true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
int InputLZWDecodeStream::GetCode() {
|
|
186
|
+
int c;
|
|
187
|
+
int code;
|
|
188
|
+
|
|
189
|
+
IOBasicTypes::Byte buffer;
|
|
190
|
+
while (inputBits < nextBits)
|
|
191
|
+
{
|
|
192
|
+
mSourceStream->Read(&buffer, 1);
|
|
193
|
+
c = buffer;
|
|
194
|
+
|
|
195
|
+
if (c == -1) return -1;
|
|
196
|
+
inputBuf = (inputBuf << 8) | (c & 0xff);
|
|
197
|
+
inputBits += 8;
|
|
198
|
+
}
|
|
199
|
+
code = (inputBuf >> (inputBits - nextBits)) & ((1 << nextBits) - 1);
|
|
200
|
+
inputBits -= nextBits;
|
|
201
|
+
inputBuf = inputBuf & ((1 << inputBits) - 1); // avoid overflow by limiting to the bits its supposed to use
|
|
202
|
+
return code;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
bool InputLZWDecodeStream::NotEnded()
|
|
206
|
+
{
|
|
207
|
+
return mCurrentlyEncoding;
|
|
208
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Source File : InputLZWDecodeStream.h
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Copyright 2011 Gal Kahana PDFWriter
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
*/
|
|
21
|
+
#pragma once
|
|
22
|
+
|
|
23
|
+
#include "EStatusCode.h"
|
|
24
|
+
#include "IByteReader.h"
|
|
25
|
+
|
|
26
|
+
class InputLZWDecodeStream : public IByteReader
|
|
27
|
+
{
|
|
28
|
+
public:
|
|
29
|
+
InputLZWDecodeStream(int early);
|
|
30
|
+
|
|
31
|
+
// Note that assigning passes ownership on the stream, use Assign(NULL) to remove ownership
|
|
32
|
+
InputLZWDecodeStream(IByteReader* inSourceReader);
|
|
33
|
+
virtual ~InputLZWDecodeStream(void);
|
|
34
|
+
|
|
35
|
+
// Assigning passes ownership of the input stream to the decoder stream.
|
|
36
|
+
// if you don't care for that, then after finishing with the decode, Assign(NULL).
|
|
37
|
+
void Assign(IByteReader* inSourceReader);
|
|
38
|
+
|
|
39
|
+
// IByteReader implementation. note that "inBufferSize" determines how many
|
|
40
|
+
// bytes will be placed in the Buffer...not how many are actually read from the underlying
|
|
41
|
+
// encoded stream. got it?!
|
|
42
|
+
virtual IOBasicTypes::LongBufferSizeType Read(IOBasicTypes::Byte* inBuffer,IOBasicTypes::LongBufferSizeType inBufferSize);
|
|
43
|
+
|
|
44
|
+
virtual bool NotEnded();
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
|
|
48
|
+
IByteReader* mSourceStream;
|
|
49
|
+
|
|
50
|
+
bool mCurrentlyEncoding;
|
|
51
|
+
|
|
52
|
+
int mEarly; // early parameter
|
|
53
|
+
int inputBuf; // input buffer
|
|
54
|
+
int inputBits; // number of bits in input buffer
|
|
55
|
+
|
|
56
|
+
struct { // decoding table
|
|
57
|
+
int length;
|
|
58
|
+
int head;
|
|
59
|
+
IOBasicTypes::Byte tail;
|
|
60
|
+
} table[4097];
|
|
61
|
+
int nextCode; // next code to be used
|
|
62
|
+
int nextBits; // number of bits in next code word
|
|
63
|
+
int prevCode; // previous code used in stream
|
|
64
|
+
int newChar; // next char to be added to table
|
|
65
|
+
IOBasicTypes::Byte seqBuf[4097]; // buffer for current sequence
|
|
66
|
+
int seqLength; // length of current sequence
|
|
67
|
+
int seqIndex; // index into current sequence
|
|
68
|
+
bool first; // first code after a table clear
|
|
69
|
+
|
|
70
|
+
bool ProcessNextCode();
|
|
71
|
+
void ClearTable();
|
|
72
|
+
int GetCode();
|
|
73
|
+
|
|
74
|
+
void FinalizeEncoding();
|
|
75
|
+
void StartEncoding();
|
|
76
|
+
|
|
77
|
+
};
|
|
@@ -58,14 +58,14 @@ public:
|
|
|
58
58
|
|
|
59
59
|
// use this for retrieving image information for JPEG (useful for deciphering JPG dimensions tags)
|
|
60
60
|
BoolAndJPEGImageInformation RetrieveImageInformation(const std::string& inJPGFilePath);
|
|
61
|
-
|
|
61
|
+
BoolAndJPEGImageInformation RetrieveImageInformation(IByteReaderWithPosition* inJPGStream);
|
|
62
62
|
|
|
63
63
|
// DocumentContext::CreateImageXObjectFromJPGFile are equivelent
|
|
64
64
|
PDFImageXObject* CreateImageXObjectFromJPGFile(const std::string& inJPGFilePath);
|
|
65
65
|
PDFImageXObject* CreateImageXObjectFromJPGStream(IByteReaderWithPosition* inJPGStream);
|
|
66
66
|
PDFImageXObject* CreateImageXObjectFromJPGFile(const std::string& inJPGFilePath,ObjectIDType inImageXObjectID);
|
|
67
67
|
PDFImageXObject* CreateImageXObjectFromJPGStream(IByteReaderWithPosition* inJPGStream,ObjectIDType inImageXObjectID);
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
// will return form XObject, which will include the xobject at it's size
|
|
70
70
|
PDFFormXObject* CreateFormXObjectFromJPGFile(const std::string& inJPGFilePath);
|
|
71
71
|
PDFFormXObject* CreateFormXObjectFromJPGStream(IByteReaderWithPosition* inJPGStream);
|
|
@@ -378,6 +378,11 @@ void ObjectsContext::SetCompressStreams(bool inCompressStreams)
|
|
|
378
378
|
mCompressStreams = inCompressStreams;
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
bool ObjectsContext::IsCompressingStreams()
|
|
382
|
+
{
|
|
383
|
+
return mCompressStreams;
|
|
384
|
+
}
|
|
385
|
+
|
|
381
386
|
static const std::string scLength = "Length";
|
|
382
387
|
static const std::string scStream = "stream";
|
|
383
388
|
static const std::string scEndStream = "endstream";
|
|
@@ -114,6 +114,7 @@ public:
|
|
|
114
114
|
|
|
115
115
|
// Sets whether streams created by the objects context will be compressed (with flate) or not
|
|
116
116
|
void SetCompressStreams(bool inCompressStreams);
|
|
117
|
+
bool IsCompressingStreams();
|
|
117
118
|
|
|
118
119
|
// Create PDF stream and write it's header. note that stream are written with indirect object for Length, to allow one pass writing.
|
|
119
120
|
// inStreamDictionary can be passed in order to include stream generic information in an already written stream dictionary
|
|
@@ -2018,9 +2018,24 @@ EStatusCode PDFDocumentHandler::WriteStreamObject(PDFStreamInput* inStream, IObj
|
|
|
2018
2018
|
|
|
2019
2019
|
MapIterator<PDFNameToPDFObjectMap> it(streamDictionary->GetIterator());
|
|
2020
2020
|
EStatusCode status = PDFHummus::eSuccess;
|
|
2021
|
+
bool readingDecrypted = false;
|
|
2022
|
+
IByteReader* streamReader = NULL;
|
|
2023
|
+
|
|
2024
|
+
/*
|
|
2025
|
+
* To support unencrypted pdf output, mostly used for debugging, (and maybe i should put a general flag there),
|
|
2026
|
+
* add ability here to copy by rewriting the streams...when possible.
|
|
2027
|
+
*/
|
|
2028
|
+
if(!mObjectsContext->IsCompressingStreams()) {
|
|
2029
|
+
streamReader = mParser->StartReadingFromStream(inStream);
|
|
2030
|
+
readingDecrypted = streamReader != NULL;
|
|
2031
|
+
}
|
|
2032
|
+
if(!readingDecrypted) {
|
|
2033
|
+
streamReader = mParser->StartReadingFromStreamForPlainCopying(inStream);
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2021
2036
|
while (it.MoveNext() && PDFHummus::eSuccess == status)
|
|
2022
2037
|
{
|
|
2023
|
-
if (it.GetKey()->GetValue() != "Length") {
|
|
2038
|
+
if (it.GetKey()->GetValue() != "Length" && (!readingDecrypted || it.GetKey()->GetValue() != "Filter")) {
|
|
2024
2039
|
status = newStreamDictionary->WriteKey(it.GetKey()->GetValue());
|
|
2025
2040
|
if (PDFHummus::eSuccess == status)
|
|
2026
2041
|
status = WriteObjectByType(it.GetValue(), eTokenSeparatorEndLine, inWritePolicy);
|
|
@@ -2033,9 +2048,10 @@ EStatusCode PDFDocumentHandler::WriteStreamObject(PDFStreamInput* inStream, IObj
|
|
|
2033
2048
|
return PDFHummus::eFailure;
|
|
2034
2049
|
}
|
|
2035
2050
|
|
|
2036
|
-
PDFStream* newStream =
|
|
2051
|
+
PDFStream* newStream = readingDecrypted ?
|
|
2052
|
+
mObjectsContext->StartPDFStream(newStreamDictionary) :
|
|
2053
|
+
mObjectsContext->StartUnfilteredPDFStream(newStreamDictionary);
|
|
2037
2054
|
OutputStreamTraits outputTraits(newStream->GetWriteStream());
|
|
2038
|
-
IByteReader* streamReader = mParser->StartReadingFromStreamForPlainCopying(inStream);
|
|
2039
2055
|
|
|
2040
2056
|
status = outputTraits.CopyToOutputStream(streamReader);
|
|
2041
2057
|
if (status != PDFHummus::eSuccess)
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
*/
|
|
21
21
|
#include "PDFObject.h"
|
|
22
|
+
#include "IDeletable.h"
|
|
22
23
|
|
|
23
24
|
const char* PDFObject::scPDFObjectTypeLabel(int index)
|
|
24
25
|
{
|
|
@@ -53,9 +54,9 @@ PDFObject::PDFObject(int inType)
|
|
|
53
54
|
|
|
54
55
|
PDFObject::~PDFObject(void)
|
|
55
56
|
{
|
|
56
|
-
|
|
57
|
+
StringToIDeletable::iterator it = mMetadata.begin();
|
|
57
58
|
for (; it != mMetadata.end(); ++it) {
|
|
58
|
-
|
|
59
|
+
it->second->DeleteMe();
|
|
59
60
|
}
|
|
60
61
|
mMetadata.clear();
|
|
61
62
|
}
|
|
@@ -65,15 +66,15 @@ PDFObject::EPDFObjectType PDFObject::GetType()
|
|
|
65
66
|
return mType;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
void PDFObject::SetMetadata(const std::string& inKey,
|
|
69
|
+
void PDFObject::SetMetadata(const std::string& inKey, IDeletable* inValue) {
|
|
69
70
|
// delete old metadata
|
|
70
71
|
DeleteMetadata(inKey);
|
|
71
72
|
|
|
72
|
-
mMetadata.insert(
|
|
73
|
+
mMetadata.insert(StringToIDeletable::value_type(inKey, inValue));
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
IDeletable* PDFObject::GetMetadata(const std::string& inKey) {
|
|
77
|
+
StringToIDeletable::iterator it = mMetadata.find(inKey);
|
|
77
78
|
|
|
78
79
|
if (it == mMetadata.end())
|
|
79
80
|
return NULL;
|
|
@@ -81,19 +82,20 @@ void* PDFObject::GetMetadata(const std::string& inKey) {
|
|
|
81
82
|
return it->second;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
IDeletable* PDFObject::DetachMetadata(const std::string& inKey) {
|
|
86
|
+
StringToIDeletable::iterator it = mMetadata.find(inKey);
|
|
86
87
|
|
|
87
88
|
if (it == mMetadata.end())
|
|
88
89
|
return NULL;
|
|
89
90
|
else {
|
|
90
|
-
|
|
91
|
+
IDeletable* result = it->second;
|
|
91
92
|
mMetadata.erase(it);
|
|
92
93
|
return result;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
void PDFObject::DeleteMetadata(const std::string& inKey) {
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
IDeletable* result = DetachMetadata(inKey);
|
|
99
|
+
if(result)
|
|
100
|
+
result->DeleteMe();
|
|
99
101
|
}
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
#include <string>
|
|
26
26
|
#include <map>
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
class IDeletable;
|
|
29
|
+
|
|
30
|
+
typedef std::map<std::string, IDeletable*> StringToIDeletable;
|
|
29
31
|
|
|
30
32
|
class PDFObject : public RefCountObject
|
|
31
33
|
{
|
|
@@ -58,14 +60,14 @@ public:
|
|
|
58
60
|
/*
|
|
59
61
|
metadata will automatically be deleted when object is released
|
|
60
62
|
*/
|
|
61
|
-
void SetMetadata(const std::string& inKey,
|
|
62
|
-
|
|
63
|
+
void SetMetadata(const std::string& inKey,IDeletable* inValue); // will automatically delete old data in the same key
|
|
64
|
+
IDeletable* GetMetadata(const std::string& inKey);
|
|
63
65
|
// Detach will only remove the pointer from metadata map, Delete will also delete the inValue pointer
|
|
64
|
-
|
|
66
|
+
IDeletable* DetachMetadata(const std::string& inKey);
|
|
65
67
|
void DeleteMetadata(const std::string& inKey);
|
|
66
68
|
|
|
67
69
|
|
|
68
70
|
private:
|
|
69
71
|
EPDFObjectType mType;
|
|
70
|
-
|
|
72
|
+
StringToIDeletable mMetadata;
|
|
71
73
|
};
|
|
@@ -706,4 +706,12 @@ void PDFObjectParser::SetDecryptionHelper(DecryptionHelper* inDecryptionHelper)
|
|
|
706
706
|
void PDFObjectParser::SetParserExtender(IPDFParserExtender* inParserExtender)
|
|
707
707
|
{
|
|
708
708
|
mParserExtender = inParserExtender;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
IByteReader* PDFObjectParser::StartExternalRead() {
|
|
712
|
+
return mStream;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
void PDFObjectParser::EndExternalRead() {
|
|
716
|
+
ResetReadState();
|
|
709
717
|
}
|
|
@@ -49,6 +49,7 @@ public:
|
|
|
49
49
|
// Assign the stream to read from (does not take ownership of the stream, unless told so)
|
|
50
50
|
void SetReadStream(IByteReader* inSourceStream,IReadPositionProvider* inCurrentPositionProvider,bool inOwnsStream=false);
|
|
51
51
|
|
|
52
|
+
// the important bit - get next object in content stream
|
|
52
53
|
PDFObject* ParseNewObject();
|
|
53
54
|
|
|
54
55
|
// calls this when changing underlying stream position
|
|
@@ -64,6 +65,11 @@ public:
|
|
|
64
65
|
// helper method for others who need to parse encoded pdf data
|
|
65
66
|
std::string DecodeHexString(const std::string inStringToDecode);
|
|
66
67
|
|
|
68
|
+
// External reading. use to temporarily get access to the internal stream, instead of reading objects with ParseNewObject.
|
|
69
|
+
// when done mark with FinishExternalReading to commence reading
|
|
70
|
+
IByteReader* StartExternalRead();
|
|
71
|
+
void EndExternalRead();
|
|
72
|
+
|
|
67
73
|
private:
|
|
68
74
|
PDFParserTokenizer mTokenizer;
|
|
69
75
|
StringList mTokenBuffer;
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
#include "PDFStreamInput.h"
|
|
37
37
|
#include "InputLimitedStream.h"
|
|
38
38
|
#include "InputFlateDecodeStream.h"
|
|
39
|
+
#include "InputLZWDecodeStream.h"
|
|
39
40
|
#include "InputStreamSkipperStream.h"
|
|
40
41
|
#include "InputPredictorPNGOptimumStream.h"
|
|
41
42
|
#include "InputPredictorTIFFSubStream.h"
|
|
@@ -1925,27 +1926,39 @@ EStatusCodeAndIByteReader PDFParser::CreateFilterForStream(IByteReader* inStream
|
|
|
1925
1926
|
do
|
|
1926
1927
|
{
|
|
1927
1928
|
|
|
1928
|
-
if(inFilterName->GetValue() == "FlateDecode")
|
|
1929
|
+
if(inFilterName->GetValue() == "FlateDecode" || inFilterName->GetValue() == "LZWDecode")
|
|
1929
1930
|
{
|
|
1930
|
-
|
|
1931
|
-
flateStream = new InputFlateDecodeStream(NULL); // assigning null, so later delete, if failure occurs won't delete the input stream
|
|
1932
|
-
result = flateStream;
|
|
1933
|
-
|
|
1934
|
-
// check for predictor n' such
|
|
1935
|
-
if(!inDecodeParams)
|
|
1931
|
+
if (inFilterName->GetValue() == "FlateDecode")
|
|
1936
1932
|
{
|
|
1937
|
-
|
|
1933
|
+
InputFlateDecodeStream* flateStream;
|
|
1934
|
+
flateStream = new InputFlateDecodeStream(NULL); // assigning null, so later delete, if failure occurs won't delete the input stream
|
|
1938
1935
|
flateStream->Assign(inStream);
|
|
1939
|
-
|
|
1936
|
+
result = flateStream;
|
|
1937
|
+
}
|
|
1938
|
+
else if (inFilterName->GetValue() == "LZWDecode")
|
|
1939
|
+
{
|
|
1940
|
+
InputLZWDecodeStream* lzwStream;
|
|
1941
|
+
int early = 1;
|
|
1942
|
+
if (inDecodeParams)
|
|
1943
|
+
{
|
|
1944
|
+
PDFObjectCastPtr<PDFInteger> earlyObj(QueryDictionaryObject(inDecodeParams, "EarlyChange"));
|
|
1945
|
+
early = earlyObj->GetValue();
|
|
1946
|
+
}
|
|
1947
|
+
lzwStream = new InputLZWDecodeStream(early);
|
|
1948
|
+
lzwStream->Assign(inStream);
|
|
1949
|
+
result = lzwStream;
|
|
1940
1950
|
}
|
|
1941
1951
|
|
|
1952
|
+
// check for predictor n' such
|
|
1953
|
+
if (!inDecodeParams)
|
|
1954
|
+
// no predictor, stop here
|
|
1955
|
+
break;
|
|
1956
|
+
|
|
1942
1957
|
// read predictor, and apply the relevant predictor function
|
|
1943
1958
|
PDFObjectCastPtr<PDFInteger> predictor(QueryDictionaryObject(inDecodeParams,"Predictor"));
|
|
1944
1959
|
|
|
1945
1960
|
if(!predictor || predictor->GetValue() == 1)
|
|
1946
1961
|
{
|
|
1947
|
-
// no predictor or default, stop here
|
|
1948
|
-
flateStream->Assign(inStream);
|
|
1949
1962
|
break;
|
|
1950
1963
|
}
|
|
1951
1964
|
|
|
@@ -1994,7 +2007,6 @@ EStatusCodeAndIByteReader PDFParser::CreateFilterForStream(IByteReader* inStream
|
|
|
1994
2007
|
break;
|
|
1995
2008
|
}
|
|
1996
2009
|
}
|
|
1997
|
-
flateStream->Assign(inStream);
|
|
1998
2010
|
}
|
|
1999
2011
|
else if (inFilterName->GetValue() == "ASCIIHexDecode")
|
|
2000
2012
|
{
|
|
@@ -2028,7 +2040,7 @@ EStatusCodeAndIByteReader PDFParser::CreateFilterForStream(IByteReader* inStream
|
|
|
2028
2040
|
}
|
|
2029
2041
|
else
|
|
2030
2042
|
{
|
|
2031
|
-
TRACE_LOG("PDFParser::CreateFilterForStream, supporting only flate decode and ascii 85 decode, failing");
|
|
2043
|
+
TRACE_LOG("PDFParser::CreateFilterForStream, supporting only flate decode, lzw, dct, crypt and ascii 85+hex decode, failing");
|
|
2032
2044
|
status = PDFHummus::eFailure;
|
|
2033
2045
|
break;
|
|
2034
2046
|
}
|