muhammara 2.0.0 → 2.3.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/README.md +2 -2
  3. package/node_modules/@mapbox/node-pre-gyp/CHANGELOG.md +10 -0
  4. package/node_modules/@mapbox/node-pre-gyp/lib/util/abi_crosswalk.json +16 -0
  5. package/node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js +1 -1
  6. package/node_modules/@mapbox/node-pre-gyp/package.json +10 -11
  7. package/node_modules/ansi-regex/index.d.ts +37 -0
  8. package/node_modules/ansi-regex/index.js +4 -4
  9. package/node_modules/ansi-regex/package.json +17 -15
  10. package/node_modules/ansi-regex/readme.md +35 -3
  11. package/node_modules/brace-expansion/package.json +2 -1
  12. package/node_modules/debug/LICENSE +10 -9
  13. package/node_modules/debug/README.md +27 -1
  14. package/node_modules/debug/package.json +15 -15
  15. package/node_modules/debug/src/common.js +2 -2
  16. package/node_modules/detect-libc/README.md +124 -42
  17. package/node_modules/detect-libc/index.d.ts +11 -0
  18. package/node_modules/detect-libc/lib/detect-libc.js +166 -80
  19. package/node_modules/detect-libc/lib/process.js +16 -0
  20. package/node_modules/detect-libc/package.json +20 -19
  21. package/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
  22. package/node_modules/emoji-regex/README.md +73 -0
  23. package/node_modules/emoji-regex/es2015/index.js +6 -0
  24. package/node_modules/emoji-regex/es2015/text.js +6 -0
  25. package/node_modules/emoji-regex/index.d.ts +23 -0
  26. package/node_modules/emoji-regex/index.js +6 -0
  27. package/node_modules/emoji-regex/package.json +77 -0
  28. package/node_modules/emoji-regex/text.js +6 -0
  29. package/node_modules/gauge/package.json +7 -7
  30. package/node_modules/https-proxy-agent/dist/agent.js +2 -5
  31. package/node_modules/https-proxy-agent/dist/agent.js.map +1 -1
  32. package/node_modules/https-proxy-agent/package.json +5 -5
  33. package/node_modules/is-fullwidth-code-point/index.d.ts +17 -0
  34. package/node_modules/is-fullwidth-code-point/index.js +25 -21
  35. package/node_modules/is-fullwidth-code-point/license +4 -16
  36. package/node_modules/is-fullwidth-code-point/package.json +18 -24
  37. package/node_modules/is-fullwidth-code-point/readme.md +6 -6
  38. package/node_modules/minimatch/README.md +22 -1
  39. package/node_modules/minimatch/minimatch.js +93 -69
  40. package/node_modules/minimatch/package.json +11 -10
  41. package/node_modules/minipass/index.js +6 -1
  42. package/node_modules/minipass/package.json +5 -5
  43. package/node_modules/node-fetch/lib/index.es.js +29 -3
  44. package/node_modules/node-fetch/lib/index.js +29 -3
  45. package/node_modules/node-fetch/lib/index.mjs +29 -3
  46. package/node_modules/node-fetch/package.json +18 -10
  47. package/node_modules/semver/README.md +3 -1
  48. package/node_modules/semver/bin/semver.js +19 -9
  49. package/node_modules/semver/classes/comparator.js +3 -2
  50. package/node_modules/semver/classes/index.js +1 -1
  51. package/node_modules/semver/classes/range.js +31 -22
  52. package/node_modules/semver/classes/semver.js +1 -1
  53. package/node_modules/semver/functions/cmp.js +8 -4
  54. package/node_modules/semver/functions/coerce.js +3 -2
  55. package/node_modules/semver/functions/inc.js +4 -1
  56. package/node_modules/semver/functions/parse.js +1 -1
  57. package/node_modules/semver/internal/constants.js +2 -2
  58. package/node_modules/semver/internal/identifiers.js +1 -1
  59. package/node_modules/semver/internal/parse-options.js +3 -3
  60. package/node_modules/semver/internal/re.js +3 -3
  61. package/node_modules/semver/package.json +46 -13
  62. package/node_modules/semver/ranges/min-version.js +2 -1
  63. package/node_modules/semver/ranges/outside.js +1 -1
  64. package/node_modules/semver/ranges/simplify.js +15 -12
  65. package/node_modules/semver/ranges/subset.js +53 -31
  66. package/node_modules/signal-exit/index.js +34 -10
  67. package/node_modules/signal-exit/package.json +11 -9
  68. package/node_modules/string-width/index.d.ts +29 -0
  69. package/node_modules/string-width/index.js +16 -5
  70. package/node_modules/string-width/package.json +20 -20
  71. package/node_modules/string-width/readme.md +15 -7
  72. package/node_modules/strip-ansi/index.d.ts +17 -0
  73. package/node_modules/strip-ansi/index.js +1 -1
  74. package/node_modules/strip-ansi/package.json +19 -17
  75. package/node_modules/strip-ansi/readme.md +12 -5
  76. package/package.json +1 -1
  77. package/src/DocumentCopyingContextDriver.cpp +6 -6
  78. package/src/deps/PDFWriter/CMakeLists.txt +8 -0
  79. package/src/deps/PDFWriter/DecryptionHelper.cpp +10 -8
  80. package/src/deps/PDFWriter/Deletable.h +46 -0
  81. package/src/deps/PDFWriter/DocumentContext.h +3 -3
  82. package/src/deps/PDFWriter/IDeletable.h +6 -0
  83. package/src/deps/PDFWriter/InputLZWDecodeStream.cpp +208 -0
  84. package/src/deps/PDFWriter/InputLZWDecodeStream.h +77 -0
  85. package/src/deps/PDFWriter/InputStreamSkipperStream.cpp +1 -1
  86. package/src/deps/PDFWriter/JPEGImageHandler.h +2 -2
  87. package/src/deps/PDFWriter/ObjectsContext.cpp +5 -0
  88. package/src/deps/PDFWriter/ObjectsContext.h +1 -0
  89. package/src/deps/PDFWriter/PDFDocumentHandler.cpp +19 -3
  90. package/src/deps/PDFWriter/PDFObject.cpp +13 -11
  91. package/src/deps/PDFWriter/PDFObject.h +7 -5
  92. package/src/deps/PDFWriter/PDFObjectParser.cpp +8 -0
  93. package/src/deps/PDFWriter/PDFObjectParser.h +6 -0
  94. package/src/deps/PDFWriter/PDFParser.cpp +25 -13
  95. package/src/deps/PDFWriter/PDFParserTokenizer.cpp +25 -24
  96. package/src/deps/PDFWriter/PDFParserTokenizer.h +1 -0
  97. package/src/deps/PDFWriter/PDFWriter.h +2 -2
  98. package/src/deps/PDFWriter/binding.gyp +2 -0
  99. package/node_modules/detect-libc/.npmignore +0 -7
  100. package/node_modules/detect-libc/bin/detect-libc.js +0 -18
  101. package/node_modules/semver/CHANGELOG.md +0 -111
  102. package/src/deps/PDFWriter/InputPredictorPNGAverageStream.cpp +0 -120
  103. package/src/deps/PDFWriter/InputPredictorPNGAverageStream.h +0 -49
  104. package/src/deps/PDFWriter/InputPredictorPNGNoneStream.cpp +0 -109
  105. package/src/deps/PDFWriter/InputPredictorPNGNoneStream.h +0 -47
  106. package/src/deps/PDFWriter/InputPredictorPNGPaethStream.cpp +0 -136
  107. package/src/deps/PDFWriter/InputPredictorPNGPaethStream.h +0 -51
  108. package/src/deps/PDFWriter/InputPredictorPNGSubStream.cpp +0 -113
  109. package/src/deps/PDFWriter/InputPredictorPNGSubStream.h +0 -47
  110. package/src/deps/PDFWriter/InputPredictorPNGUpStream.cpp +0 -120
  111. package/src/deps/PDFWriter/InputPredictorPNGUpStream.h +0 -49
@@ -1,6 +1,6 @@
1
1
  # strip-ansi [![Build Status](https://travis-ci.org/chalk/strip-ansi.svg?branch=master)](https://travis-ci.org/chalk/strip-ansi)
2
2
 
3
- > Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
3
+ > Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string
4
4
 
5
5
 
6
6
  ## Install
@@ -17,12 +17,23 @@ const stripAnsi = require('strip-ansi');
17
17
 
18
18
  stripAnsi('\u001B[4mUnicorn\u001B[0m');
19
19
  //=> 'Unicorn'
20
+
21
+ stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
22
+ //=> 'Click'
20
23
  ```
21
24
 
22
25
 
26
+ ## strip-ansi for enterprise
27
+
28
+ Available as part of the Tidelift Subscription.
29
+
30
+ The maintainers of strip-ansi and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-strip-ansi?utm_source=npm-strip-ansi&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
31
+
32
+
23
33
  ## Related
24
34
 
25
35
  - [strip-ansi-cli](https://github.com/chalk/strip-ansi-cli) - CLI for this module
36
+ - [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Streaming version of this module
26
37
  - [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
27
38
  - [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
28
39
  - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
@@ -33,7 +44,3 @@ stripAnsi('\u001B[4mUnicorn\u001B[0m');
33
44
  - [Sindre Sorhus](https://github.com/sindresorhus)
34
45
  - [Josh Junon](https://github.com/qix-)
35
46
 
36
-
37
- ## License
38
-
39
- MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muhammara",
3
- "version": "2.0.0",
3
+ "version": "2.3.0",
4
4
  "description": "Create, read and modify PDF files and streams. A drop in replacement for hummujs PDF library",
5
5
  "homepage": "https://github.com/julianhille/Muhammarajs",
6
6
  "license": "Apache-2.0",
@@ -156,7 +156,7 @@ METHOD_RETURN_TYPE DocumentCopyingContextDriver::CreateFormXObjectFromPDFPage(co
156
156
 
157
157
  if(result.first != eSuccess)
158
158
  {
159
- THROW_EXCEPTION("Unable to create form xobject from PDF page, parhaps the page index does not fit the total pages count");
159
+ THROW_EXCEPTION("Unable to create form xobject from PDF page, perhaps the page index does not fit the total pages count");
160
160
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
161
161
  }
162
162
 
@@ -191,7 +191,7 @@ METHOD_RETURN_TYPE DocumentCopyingContextDriver::MergePDFPageToPage(const ARGS_T
191
191
  TO_UINT32(args[1])->Value());
192
192
 
193
193
  if(status != eSuccess)
194
- THROW_EXCEPTION("Unable to merge page index to page. parhaps the page index is wrong");
194
+ THROW_EXCEPTION("Unable to merge page index to page. Perhaps the page index is wrong");
195
195
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
196
196
 
197
197
  }
@@ -220,7 +220,7 @@ METHOD_RETURN_TYPE DocumentCopyingContextDriver::AppendPDFPageFromPDF(const ARGS
220
220
 
221
221
  if(result.first != eSuccess)
222
222
  {
223
- THROW_EXCEPTION("Unable to append page. parhaps the page index is wrong");
223
+ THROW_EXCEPTION("Unable to append page. Perhaps the page index is wrong");
224
224
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
225
225
  }
226
226
 
@@ -255,7 +255,7 @@ METHOD_RETURN_TYPE DocumentCopyingContextDriver::MergePDFPageToFormXObject(const
255
255
  TO_UINT32(args[1])->Value());
256
256
 
257
257
  if(status != eSuccess)
258
- THROW_EXCEPTION("Unable to merge page index to form. parhaps the page index is wrong");
258
+ THROW_EXCEPTION("Unable to merge page index to form. Perhaps the page index is wrong");
259
259
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
260
260
 
261
261
  }
@@ -293,7 +293,7 @@ METHOD_RETURN_TYPE DocumentCopyingContextDriver::CopyDirectObjectAsIs(const ARGS
293
293
 
294
294
  EStatusCode status = copyingContextDriver->CopyingContext->CopyDirectObjectAsIs(ObjectWrap::Unwrap<PDFObjectDriver>(args[0]->TO_OBJECT())->GetObject());
295
295
  if(status != eSuccess)
296
- THROW_EXCEPTION("Unable to merge page index to form. parhaps the page index is wrong");
296
+ THROW_EXCEPTION("Unable to merge page index to form. Perhaps the page index is wrong");
297
297
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
298
298
 
299
299
  }
@@ -347,7 +347,7 @@ METHOD_RETURN_TYPE DocumentCopyingContextDriver::CopyDirectObjectWithDeepCopy(co
347
347
 
348
348
  EStatusCodeAndObjectIDTypeList result = copyingContextDriver->CopyingContext->CopyDirectObjectWithDeepCopy(ObjectWrap::Unwrap<PDFObjectDriver>(args[0]->TO_OBJECT())->GetObject());
349
349
  if(result.first != eSuccess)
350
- THROW_EXCEPTION("Unable to copy object, parhaps the object id is wrong");
350
+ THROW_EXCEPTION("Unable to copy object, perhaps the object id is wrong");
351
351
 
352
352
  Local<Array> resultObjectIDs = NEW_ARRAY((unsigned int)result.second.size());
353
353
  unsigned int index = 0;
@@ -80,6 +80,7 @@ InputDCTDecodeStream.cpp
80
80
  InputFile.cpp
81
81
  InputFileStream.cpp
82
82
  InputFlateDecodeStream.cpp
83
+ InputLZWDecodeStream.cpp
83
84
  InputLimitedStream.cpp
84
85
  InputRC4XcodeStream.cpp
85
86
  InputPFBDecodeStream.cpp
@@ -206,6 +207,7 @@ CIDFontWriter.h
206
207
  CMYKRGBColor.h
207
208
  ContainerIterator.h
208
209
  DecryptionHelper.h
210
+ Deletable.h
209
211
  DescendentFontWriter.h
210
212
  DictionaryContext.h
211
213
  DictOperand.h
@@ -233,6 +235,7 @@ IByteReaderWithPosition.h
233
235
  IByteWriter.h
234
236
  IByteWriterWithPosition.h
235
237
  IContentContextListener.h
238
+ IDeletable.h
236
239
  IDescendentFontWriter.h
237
240
  IDocumentContextExtender.h
238
241
  IFontDescriptorHelper.h
@@ -251,6 +254,7 @@ InputDCTDecodeStream.h
251
254
  InputFile.h
252
255
  InputFileStream.h
253
256
  InputFlateDecodeStream.h
257
+ InputLZWDecodeStream.h
254
258
  InputLimitedStream.h
255
259
  InputRC4XcodeStream.h
256
260
  InputPFBDecodeStream.h
@@ -553,6 +557,8 @@ InputFileStream.cpp
553
557
  InputFileStream.h
554
558
  InputFlateDecodeStream.cpp
555
559
  InputFlateDecodeStream.h
560
+ InputLZWDecodeStream.cpp
561
+ InputLZWDecodeStream.h
556
562
  InputLimitedStream.cpp
557
563
  InputLimitedStream.h
558
564
  InputRC4XcodeStream.cpp
@@ -636,6 +642,8 @@ UppercaseSequance.h
636
642
  )
637
643
 
638
644
  source_group("PDF Embedding\\Parsed Objects" FILES
645
+ Deletable.h
646
+ IDeletable.h
639
647
  PDFArray.cpp
640
648
  PDFArray.h
641
649
  PDFBoolean.cpp
@@ -36,6 +36,7 @@ limitations under the License.
36
36
  #include "InputRC4XcodeStream.h"
37
37
  #include "InputAESDecodeStream.h"
38
38
  #include "Trace.h"
39
+ #include "Deletable.h"
39
40
  #include <memory>
40
41
 
41
42
  using namespace std;
@@ -333,9 +334,9 @@ IByteReader* DecryptionHelper::CreateDefaultDecryptionFilterForStream(PDFStreamI
333
334
  if (!IsEncrypted() || !CanDecryptDocument() || HasCryptFilterDefinition(mParser, inStream) || !mXcryptStreams)
334
335
  return NULL;
335
336
 
336
- void* savedEcnryptionKey = inStream->GetMetadata(scEcnryptionKeyMetadataKey);
337
+ IDeletable* savedEcnryptionKey = inStream->GetMetadata(scEcnryptionKeyMetadataKey);
337
338
  if (savedEcnryptionKey) {
338
- return CreateDecryptionReader(inToWrapStream, *((ByteList*)savedEcnryptionKey), mXcryptStreams->IsUsingAES());
339
+ return CreateDecryptionReader(inToWrapStream, *(((Deletable<ByteList>*)savedEcnryptionKey)->GetPtr()), mXcryptStreams->IsUsingAES());
339
340
  }
340
341
  else
341
342
  return NULL;
@@ -346,7 +347,7 @@ IByteReader* DecryptionHelper::CreateDecryptionFilterForStream(PDFStreamInput*
346
347
  if (!IsEncrypted() || !CanDecryptDocument())
347
348
  return inToWrapStream;
348
349
 
349
- void* savedEcnryptionKey = inStream->GetMetadata(scEcnryptionKeyMetadataKey);
350
+ IDeletable* savedEcnryptionKey = inStream->GetMetadata(scEcnryptionKeyMetadataKey);
350
351
  if (!savedEcnryptionKey) {
351
352
  // sign for no encryption here
352
353
  return inToWrapStream;
@@ -354,7 +355,7 @@ IByteReader* DecryptionHelper::CreateDecryptionFilterForStream(PDFStreamInput*
354
355
  XCryptionCommon* xcryption = GetFilterForName(mXcrypts, inCryptName);
355
356
 
356
357
  if (xcryption && savedEcnryptionKey) {
357
- return CreateDecryptionReader(inToWrapStream, *((ByteList*)savedEcnryptionKey), xcryption->IsUsingAES());
358
+ return CreateDecryptionReader(inToWrapStream, *(((Deletable<ByteList>*)savedEcnryptionKey)->GetPtr()), xcryption->IsUsingAES());
358
359
  }
359
360
  else
360
361
  return inToWrapStream;
@@ -369,12 +370,13 @@ std::string DecryptionHelper::DecryptString(const std::string& inStringToDecrypt
369
370
  if (!IsDecrypting() || !mXcryptStrings)
370
371
  return inStringToDecrypt;
371
372
 
372
- std::auto_ptr<IByteReader> pDecryptStream(CreateDecryptionReader(new InputStringStream(inStringToDecrypt), mXcryptStrings->GetCurrentObjectKey(), mXcryptStrings->IsUsingAES()));
373
- if (pDecryptStream.get()) {
373
+ IByteReader* decryptStream = CreateDecryptionReader(new InputStringStream(inStringToDecrypt), mXcryptStrings->GetCurrentObjectKey(), mXcryptStrings->IsUsingAES());
374
+ if (decryptStream) {
374
375
  OutputStringBufferStream outputStream;
375
376
  OutputStreamTraits traits(&outputStream);
376
- traits.CopyToOutputStream(pDecryptStream.get());
377
+ traits.CopyToOutputStream(decryptStream);
377
378
 
379
+ delete decryptStream;
378
380
  return outputStream.ToString();
379
381
  }
380
382
  else
@@ -453,7 +455,7 @@ void DecryptionHelper::OnObjectEnd(PDFObject* inObject) {
453
455
  XCryptionCommon* streamCryptFilter = GetCryptForStream((PDFStreamInput*)inObject);
454
456
  if (streamCryptFilter) {
455
457
  ByteList* savedKey = new ByteList(streamCryptFilter->GetCurrentObjectKey());
456
- inObject->SetMetadata(scEcnryptionKeyMetadataKey, savedKey);
458
+ inObject->SetMetadata(scEcnryptionKeyMetadataKey,new Deletable<ByteList>(savedKey));
457
459
  }
458
460
  }
459
461
 
@@ -0,0 +1,46 @@
1
+ #include "IDeletable.h"
2
+
3
+ template <typename T>
4
+ class Deletable: public IDeletable {
5
+ public:
6
+ Deletable(T* inData);
7
+ virtual ~Deletable();
8
+
9
+ virtual void DeleteMe();
10
+
11
+ T* operator->();
12
+
13
+ T* GetPtr();
14
+ private:
15
+ T* mValue;
16
+ };
17
+
18
+ template <typename T>
19
+ Deletable<T>::Deletable(T* inValue)
20
+ {
21
+ mValue = inValue;
22
+ }
23
+
24
+ template <typename T>
25
+ Deletable<T>::~Deletable()
26
+ {
27
+ delete mValue;
28
+ }
29
+
30
+ template <typename T>
31
+ void Deletable<T>::DeleteMe()
32
+ {
33
+ delete this;
34
+ }
35
+
36
+ template <typename T>
37
+ T* Deletable<T>::operator->()
38
+ {
39
+ return mValue;
40
+ }
41
+
42
+ template <typename T>
43
+ T* Deletable<T>::GetPtr()
44
+ {
45
+ return mValue;
46
+ }
@@ -283,9 +283,9 @@ namespace PDFHummus
283
283
 
284
284
  // some public image info services, for users of hummus
285
285
  DoubleAndDoublePair GetImageDimensions(const std::string& inImageFile,unsigned long inImageIndex = 0, const PDFParsingOptions& inOptions = PDFParsingOptions::DefaultPDFParsingOptions());
286
- DoubleAndDoublePair GetImageDimensions(IByteReaderWithPosition* inImageStream,unsigned long inImageIndex = 0, const PDFParsingOptions& inOptions = PDFParsingOptions::DefaultPDFParsingOptions());
287
- EHummusImageType GetImageType(const std::string& inImageFile,unsigned long inImageIndex);
288
- EHummusImageType GetImageType(IByteReaderWithPosition* inImageStream,unsigned long inImageIndex);
286
+ DoubleAndDoublePair GetImageDimensions(IByteReaderWithPosition* inImageStream,unsigned long inImageIndex = 0, const PDFParsingOptions& inOptions = PDFParsingOptions::DefaultPDFParsingOptions());
287
+ EHummusImageType GetImageType(const std::string& inImageFile,unsigned long inImageIndex);
288
+ EHummusImageType GetImageType(IByteReaderWithPosition* inImageStream,unsigned long inImageIndex);
289
289
  unsigned long GetImagePagesCount(const std::string& inImageFile, const PDFParsingOptions& inOptions = PDFParsingOptions::DefaultPDFParsingOptions());
290
290
 
291
291
 
@@ -0,0 +1,6 @@
1
+ #pragma once
2
+
3
+ class IDeletable {
4
+ public:
5
+ virtual void DeleteMe() = 0;
6
+ };
@@ -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
+ };
@@ -53,7 +53,7 @@ IOBasicTypes::LongBufferSizeType InputStreamSkipperStream::Read(IOBasicTypes::By
53
53
 
54
54
  bool InputStreamSkipperStream::NotEnded()
55
55
  {
56
- return mStream->NotEnded();
56
+ return mStream ? mStream->NotEnded() : false;
57
57
  }
58
58
 
59
59
 
@@ -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
- BoolAndJPEGImageInformation RetrieveImageInformation(IByteReaderWithPosition* inJPGStream);
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 = mObjectsContext->StartUnfilteredPDFStream(newStreamDictionary);
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)