muhammara 2.6.0 → 3.0.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 CHANGED
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.0.0] - 2022-07-19
11
+
12
+ ### Fixed
13
+
14
+ - Links in docs
15
+
16
+ ### Added
17
+
18
+ - drawPath can now be used differently and this new way can be described with ts.
19
+ The old style is `drawPath(x1, y1, x2, y2..., options)` we now allow `drawPath([[x1, y1], [x2, y2]...], options)` too
20
+ - scn and SCN can now be used differently and this new way can be described with ts.
21
+ The old style is `scn(c1, c2, c3, c4, ..., 'patternName')` we now allow `scn([[c1, c2, c3, c4, ...], 'patternName')` too
22
+
23
+ ### Changed
24
+
25
+ - Bump dev dependency versions s
26
+
27
+ ### Breaking
28
+
29
+ - Node < 11 and Electron < 11 removed
30
+ - Renamed typo exported value from eTokenSeprator to eTokenSeparator
31
+
10
32
  ## [2.6.0] - 2022-06-30
11
33
 
12
34
  ### Changed
@@ -241,7 +263,8 @@ with the following changes.
241
263
 
242
264
  * Initial release
243
265
 
244
- [Unreleased]: https://github.com/julianhille/MuhammaraJS/compare/2.6.0...HEAD
266
+ [Unreleased]: https://github.com/julianhille/MuhammaraJS/compare/3.0.0...HEAD
267
+ [3.0.0]: https://github.com/julianhille/MuhammaraJS/compare/2.6.0...3.0.0
245
268
  [2.6.0]: https://github.com/julianhille/MuhammaraJS/compare/2.5.0...2.6.0
246
269
  [2.5.0]: https://github.com/julianhille/MuhammaraJS/compare/2.4.0...2.5.0
247
270
  [2.4.0]: https://github.com/julianhille/MuhammaraJS/compare/2.3.0...2.4.0
package/README.md CHANGED
@@ -22,6 +22,13 @@ If you are looking for a C++ Library go [here](https://github.com/galkahana/PDF-
22
22
  Version 2.0 will be incompatible with some older node and
23
23
  electron versions because we needed to upgrade node-pre-gyp.
24
24
 
25
+ Version 3.x has breaking changes:
26
+
27
+ - Node < 11 and Electron < 11 removed the prebuilts
28
+ - Renamed typo exported value from eTokenSeprator to eTokenSeparator
29
+
30
+ This wont affect alot of you but still.
31
+
25
32
  # Installation
26
33
 
27
34
  ```
package/muhammara.d.ts CHANGED
@@ -179,9 +179,11 @@ declare module 'muhammara' {
179
179
  SC(...colorComponents: number[]): this;
180
180
  SCN(...parameters: any[]): this; // This can't be materialized in TypeScript
181
181
  ////SCN(...colorComponents: number[], patternName?: string): this;
182
+ SCN(colorComponents: number[], patternName?: string): this;
182
183
  sc(...colorComponents: number[]): this;
183
184
  scn(...parameters: any[]): this; // This can't be materialized in TypeScript
184
185
  ////scn(...colorComponents: number[], patternName?: string): this;
186
+ scn(colorComponents: number[], patternName?: string): this;
185
187
  G(gray: number): this;
186
188
  g(gray: number): this;
187
189
  RG(r: number, g: number, b: number): this;
@@ -211,6 +213,7 @@ declare module 'muhammara' {
211
213
  writeFreeCode(freeCode: string): this;
212
214
  drawPath(...parameters: any[]): this; // This can't be materialized in TypeScript
213
215
  ////drawPath(...xyPairs: number[], options: GraphicOptions): this;
216
+ drawPath(xyPairs: Array<[number, number]>, options: GraphicOptions): this;
214
217
  drawCircle(x: PosX, y: PosY, r: number, options: GraphicOptions): this;
215
218
  drawSquare(x: PosX, y: PosY, l: number, options: GraphicOptions): this;
216
219
  drawRectangle(x: PosX, y: PosY, w: number, h: number, options: GraphicOptions): this;
@@ -549,12 +552,12 @@ declare module 'muhammara' {
549
552
 
550
553
  export type eTokenSeparatorSpace = 0;
551
554
  export type eTokenSeparatorEndLine = 1;
552
- export type eTokenSepratorNone = 2;
555
+ export type eTokenSeparatorNone = 2;
553
556
 
554
557
  enum ETokenSeparator {
555
558
  eTokenSeparatorSpace,
556
559
  eTokenSeparatorEndLine,
557
- eTokenSepratorNone
560
+ eTokenSeparatorNone
558
561
  }
559
562
 
560
563
  export interface ObjectsContext {
@@ -16,6 +16,7 @@
16
16
  "fetchSpec": "~5.2.0"
17
17
  },
18
18
  "_requiredBy": [
19
+ "/randombytes",
19
20
  "/string_decoder"
20
21
  ],
21
22
  "_resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
@@ -16,8 +16,7 @@
16
16
  "fetchSpec": "^2.0.0"
17
17
  },
18
18
  "_requiredBy": [
19
- "/npmlog",
20
- "/yargs"
19
+ "/npmlog"
21
20
  ],
22
21
  "_resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
23
22
  "_shasum": "045f9782d011ae9a6803ddd382b24392b3d890f7",
@@ -16,8 +16,11 @@
16
16
  "fetchSpec": "^4.2.3"
17
17
  },
18
18
  "_requiredBy": [
19
+ "/cliui",
19
20
  "/gauge",
20
- "/wide-align"
21
+ "/wide-align",
22
+ "/wrap-ansi",
23
+ "/yargs"
21
24
  ],
22
25
  "_resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
23
26
  "_shasum": "269c7117d27b05ad2e536830a8ec895ef9c6d010",
@@ -16,8 +16,10 @@
16
16
  "fetchSpec": "^6.0.1"
17
17
  },
18
18
  "_requiredBy": [
19
+ "/cliui",
19
20
  "/gauge",
20
- "/string-width"
21
+ "/string-width",
22
+ "/wrap-ansi"
21
23
  ],
22
24
  "_resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
23
25
  "_shasum": "9e26c63d30f53443e9489495b2105d37b67a85d9",
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "muhammara",
3
- "version": "2.6.0",
4
- "description": "Create, read and modify PDF files and streams. A drop in replacement for hummujs PDF library",
3
+ "version": "3.0.0",
4
+ "description": "Create, read and modify PDF files and streams. A drop in replacement for hummusjs PDF library",
5
5
  "homepage": "https://github.com/julianhille/Muhammarajs",
6
6
  "license": "Apache-2.0",
7
7
  "author": "Julian <j.hille484@gmail.com>",
8
8
  "main": "./muhammara.js",
9
9
  "types": "./muhammara.d.ts",
10
10
  "engines": {
11
- "node": ">=8"
11
+ "node": ">=11"
12
12
  },
13
13
  "scripts": {
14
14
  "install": "node-pre-gyp install --fallback-to-build ${EXTRA_NODE_PRE_GYP_FLAGS:-\"\"}",
@@ -46,8 +46,8 @@
46
46
  ],
47
47
  "devDependencies": {
48
48
  "@types/node": "^18.0.0",
49
- "chai": "^4.2.0",
50
- "mocha": "^6.2.3",
49
+ "chai": "^4.3.6",
50
+ "mocha": "^8.4.0",
51
51
  "npm": "^6.14.5"
52
52
  },
53
53
  "binary": {
@@ -816,20 +816,34 @@ METHOD_RETURN_TYPE AbstractContentContextDriver::SCN(const ARGS_TYPE& args)
816
816
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
817
817
  }
818
818
 
819
- if (args.Length() == 0 ||
820
- (args.Length() == 1 && !args[0]->IsNumber()))
819
+ if (
820
+ args.Length() == 0 ||
821
+ (args.Length() == 1 && !(args[0]->IsNumber() || args[0]->IsArray())) ||
822
+ (args.Length() > 1 && !(args[args.Length()-1]->IsNumber() || args[args.Length()-1]->IsArray() || args[args.Length()-1]->IsString() ))
823
+
824
+ )
821
825
  {
822
- THROW_EXCEPTION("Wrong Arguments, please provide at least one color component");
826
+ THROW_EXCEPTION("Wrong Arguments, please provide at least one color component or a list of color components and optional a pattern name");
823
827
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
824
828
  }
825
-
829
+
830
+ double* components;
831
+ int componentsLength = 0;
826
832
  bool hasPatternArgument = args[args.Length()-1]->IsString();
827
- int componentsLength = hasPatternArgument ? args.Length() - 1 : args.Length();
828
-
829
- double* components = new double[componentsLength];
830
- for(int i = 0; i < componentsLength; ++i)
831
- components[i] = TO_NUMBER(args[i])->Value();
832
-
833
+ if (!args[0]->IsArray()) {
834
+ componentsLength = hasPatternArgument ? args.Length() - 1 : args.Length();
835
+ components = new double[componentsLength];
836
+ for(int i = 0; i < componentsLength; ++i)
837
+ components[i] = TO_NUMBER(args[i])->Value();
838
+ } else {
839
+ Local<Object> arr = args[0]->TO_OBJECT();
840
+ componentsLength = TO_INT32(arr->Get(GET_CURRENT_CONTEXT, NEW_STRING("length")).ToLocalChecked())->Value();
841
+ components = new double[componentsLength];
842
+ for(int i = 0; i < componentsLength; ++i) {
843
+ components[i] = TO_NUMBER(arr->Get(GET_CURRENT_CONTEXT, i).ToLocalChecked())->Value();
844
+ }
845
+ }
846
+
833
847
  if(hasPatternArgument)
834
848
  contentContext->GetContext()->SCN(components,componentsLength,*UTF_8_VALUE(args[args.Length()-1]->TO_STRING()));
835
849
  else
@@ -880,20 +894,34 @@ METHOD_RETURN_TYPE AbstractContentContextDriver::scn(const ARGS_TYPE& args)
880
894
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
881
895
  }
882
896
 
883
- if (args.Length() == 0 ||
884
- (args.Length() == 1 && !args[0]->IsNumber()))
897
+ if (
898
+ args.Length() == 0 ||
899
+ (args.Length() == 1 && !(args[0]->IsNumber() || args[0]->IsArray())) ||
900
+ (args.Length() > 1 && !(args[args.Length()-1]->IsNumber() || args[args.Length()-1]->IsArray() || args[args.Length()-1]->IsString() ))
901
+
902
+ )
885
903
  {
886
- THROW_EXCEPTION("Wrong Arguments, please provide at least one color component");
887
- SET_FUNCTION_RETURN_VALUE(UNDEFINED)
888
- }
889
-
904
+ THROW_EXCEPTION("Wrong Arguments, please provide at least one color component or a list of color components and optional a pattern name");
905
+ SET_FUNCTION_RETURN_VALUE(UNDEFINED)
906
+ }
907
+
908
+ double* components;
909
+ int componentsLength = 0;
890
910
  bool hasPatternArgument = args[args.Length()-1]->IsString();
891
- int componentsLength = hasPatternArgument ? args.Length() - 1 : args.Length();
892
-
893
- double* components = new double[componentsLength];
894
- for(int i = 0; i < componentsLength; ++i)
895
- components[i] = TO_NUMBER(args[i])->Value();
896
-
911
+ if (!args[0]->IsArray()) {
912
+ componentsLength = hasPatternArgument ? args.Length() - 1 : args.Length();
913
+ components = new double[componentsLength];
914
+ for(int i = 0; i < componentsLength; ++i)
915
+ components[i] = TO_NUMBER(args[i])->Value();
916
+ } else {
917
+ Local<Object> arr = args[0]->TO_OBJECT();
918
+ componentsLength = TO_INT32(arr->Get(GET_CURRENT_CONTEXT, NEW_STRING("length")).ToLocalChecked())->Value();
919
+ components = new double[componentsLength];
920
+ for(int i = 0; i < componentsLength; ++i) {
921
+ components[i] = TO_NUMBER(arr->Get(GET_CURRENT_CONTEXT, i).ToLocalChecked())->Value();
922
+ }
923
+ }
924
+
897
925
  if(hasPatternArgument)
898
926
  contentContext->GetContext()->scn(components,componentsLength,*UTF_8_VALUE(args[args.Length()-1]->TO_STRING()));
899
927
  else
@@ -1757,6 +1785,7 @@ METHOD_RETURN_TYPE AbstractContentContextDriver::WriteFreeCode(const ARGS_TYPE&
1757
1785
  }
1758
1786
 
1759
1787
  /* context.drawPath(x1,y1,x2,y2,x3,y3...{type:stroke, color:#FF00FF, width:3, close:true})
1788
+ /* context.drawPath([[x1,y1],[x2,y2].....]...{type:stroke, color:#FF00FF, width:3, close:true})
1760
1789
  */
1761
1790
  METHOD_RETURN_TYPE AbstractContentContextDriver::DrawPath(const ARGS_TYPE& args)
1762
1791
  {
@@ -1769,24 +1798,64 @@ METHOD_RETURN_TYPE AbstractContentContextDriver::DrawPath(const ARGS_TYPE& args)
1769
1798
  THROW_EXCEPTION("Null content context. Please create a context");
1770
1799
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
1771
1800
  }
1772
-
1773
- if(args.Length() < 2)
1801
+
1802
+ if(
1803
+ (args.Length() == 1 && !args[0]->IsArray()) ||
1804
+ args.Length() < 2
1805
+ )
1774
1806
  {
1775
- THROW_EXCEPTION("Wrong Arguments, please provide path coordinates and an optional options object");
1807
+ THROW_EXCEPTION("Wrong Arguments, please provide path coordinates as numbers (x1, y1, x2, y2 etc) or as list of coordinates and an optional options object");
1776
1808
  SET_FUNCTION_RETURN_VALUE(UNDEFINED)
1777
1809
  }
1778
-
1779
- contentContext->SetupColorAndLineWidth(args[args.Length() - 1]);
1780
-
1781
- contentContext->GetContext()->m(TO_NUMBER(args[0])->Value(),TO_NUMBER(args[1])->Value());
1782
- for(int i=2;i<args.Length()-1;i+=2)
1810
+ if (!args[0]->IsArray())
1783
1811
  {
1784
- if(!args[i]->IsNumber()) // options object, stop
1785
- break;
1786
- contentContext->GetContext()->l(TO_NUMBER(args[i])->Value(),TO_NUMBER(args[i+1])->Value());
1812
+ contentContext->SetupColorAndLineWidth(args[args.Length() - 1]);
1813
+ contentContext->GetContext()->m(TO_NUMBER(args[0])->Value(),TO_NUMBER(args[1])->Value());
1814
+ for(int i=2;i<args.Length()-1;i+=2)
1815
+ {
1816
+ if(!args[i]->IsNumber()) // options object, stop
1817
+ break;
1818
+ contentContext->GetContext()->l(TO_NUMBER(args[i])->Value(),TO_NUMBER(args[i+1])->Value());
1819
+ }
1820
+
1821
+ contentContext->FinishPath(args[args.Length() - 1]);
1822
+ }
1823
+ else
1824
+ {
1825
+ Local<Object> outer = args[0]->TO_OBJECT();
1826
+ int arrayLength =TO_INT32(outer->Get(GET_CURRENT_CONTEXT, NEW_STRING("length")).ToLocalChecked())->Value();
1827
+ if(arrayLength <= 1) {
1828
+ THROW_EXCEPTION("Wrong arguments. Coordinate list must have at least one point");
1829
+ SET_FUNCTION_RETURN_VALUE(UNDEFINED);
1830
+ }
1831
+ Local<Object> inner;
1832
+ contentContext->SetupColorAndLineWidth(args[args.Length() - 1]);
1833
+ for(int i=0;i<arrayLength;++i) {
1834
+ inner = outer->Get(GET_CURRENT_CONTEXT, i).ToLocalChecked()->TO_OBJECT();
1835
+
1836
+ if (!inner->IsArray() || TO_INT32(inner->Get(GET_CURRENT_CONTEXT, NEW_STRING("length")).ToLocalChecked())->Value() != 2)
1837
+ {
1838
+ THROW_EXCEPTION("Wrong arguments. Coordinate list must have exactly one x and one y value");
1839
+ SET_FUNCTION_RETURN_VALUE(UNDEFINED);
1840
+ break;
1841
+ }
1842
+ if (i == 0)
1843
+ {
1844
+ contentContext->GetContext()->m(
1845
+ TO_NUMBER(inner->Get(GET_CURRENT_CONTEXT, 0).ToLocalChecked())->Value(),
1846
+ TO_NUMBER(inner->Get(GET_CURRENT_CONTEXT, 1).ToLocalChecked())->Value()
1847
+ );
1848
+ }
1849
+ else
1850
+ {
1851
+ contentContext->GetContext()->l(
1852
+ TO_NUMBER(inner->Get(GET_CURRENT_CONTEXT, 0).ToLocalChecked())->Value(),
1853
+ TO_NUMBER(inner->Get(GET_CURRENT_CONTEXT, 1).ToLocalChecked())->Value()
1854
+ );
1855
+ }
1856
+ }
1857
+ contentContext->FinishPath(args[args.Length() - 1]);
1787
1858
  }
1788
-
1789
- contentContext->FinishPath(args[args.Length() - 1]);
1790
1859
  SET_FUNCTION_RETURN_VALUE(args.This())
1791
1860
  }
1792
1861
 
@@ -147,7 +147,7 @@ void CFFANSIFontWriter::WriteCharSet( DictionaryContext* inDescriptorContext,
147
147
  for (; it != inEncodedGlyphs.end(); ++it)
148
148
  {
149
149
  std::string glyphName = inFontInfo->GetGlyphName(it->first);
150
- primitiveWriter.WriteName(glyphName.c_str(), eTokenSepratorNone);
150
+ primitiveWriter.WriteName(glyphName.c_str(), eTokenSeparatorNone);
151
151
  }
152
152
 
153
153
 
@@ -24,5 +24,5 @@ enum ETokenSeparator
24
24
  {
25
25
  eTokenSeparatorSpace,
26
26
  eTokenSeparatorEndLine,
27
- eTokenSepratorNone
27
+ eTokenSeparatorNone
28
28
  };
@@ -100,7 +100,7 @@ public:
100
100
 
101
101
  // Array writing, currently just writing begin and end brackets
102
102
  void StartArray();
103
- void EndArray(ETokenSeparator inSeparate = eTokenSepratorNone);
103
+ void EndArray(ETokenSeparator inSeparate = eTokenSeparatorNone);
104
104
 
105
105
  // Indirect objects writing
106
106
  // override that allocate a new object ID and returns it
@@ -1518,7 +1518,7 @@ std::string PDFDocumentHandler::AsEncodedName(const std::string& inName)
1518
1518
  OutputStringBufferStream aStringBuilder;
1519
1519
 
1520
1520
  primitiveWriter.SetStreamForWriting(&aStringBuilder);
1521
- primitiveWriter.WriteName(inName,eTokenSepratorNone);
1521
+ primitiveWriter.WriteName(inName,eTokenSeparatorNone);
1522
1522
 
1523
1523
  return aStringBuilder.ToString().substr(1); // return without initial forward slash
1524
1524
  }
@@ -1728,7 +1728,7 @@ EStatusCode PDFDocumentHandler::MergeAndReplaceResourcesTokens( IByteWriter* inT
1728
1728
  status = traits.CopyToOutputStream(streamReader,(LongBufferSizeType)(it->ResourceTokenPosition - previousContentPosition));
1729
1729
  if(status != PDFHummus::eSuccess)
1730
1730
  break;
1731
- primitivesWriter.WriteName(inMappedResourcesNames.find(it->ResourceToken)->second,eTokenSepratorNone);
1731
+ primitivesWriter.WriteName(inMappedResourcesNames.find(it->ResourceToken)->second,eTokenSeparatorNone);
1732
1732
  // note that i'm using SkipBy here. if i want to use SkipTo, i have to user the skipper stream as input stream for the rest
1733
1733
  // of the reader objects here, as SkipTo relies on information on how many bytes were read
1734
1734
  skipper.SkipBy(it->ResourceToken.size() + 1); // skip the resource name in the read stream [include +1 for slash]
@@ -52,7 +52,7 @@ public:
52
52
  void WriteNull(ETokenSeparator inSeparate = eTokenSeparatorSpace);
53
53
 
54
54
  void StartArray();
55
- void EndArray(ETokenSeparator inSeparate = eTokenSepratorNone);
55
+ void EndArray(ETokenSeparator inSeparate = eTokenSeparatorNone);
56
56
 
57
57
  IByteWriter* GetWritingStream();
58
58
 
package/src/muhammara.cpp CHANGED
@@ -632,7 +632,7 @@ DEF_INIT(MuhammaraInit) {
632
632
  // ETokenSeparator
633
633
  EXPORTS_SET(exports,NEW_SYMBOL("eTokenSeparatorSpace"),NEW_NUMBER(eTokenSeparatorSpace))
634
634
  EXPORTS_SET(exports,NEW_SYMBOL("eTokenSeparatorEndLine"),NEW_NUMBER(eTokenSeparatorEndLine))
635
- EXPORTS_SET(exports,NEW_SYMBOL("eTokenSepratorNone"),NEW_NUMBER(eTokenSepratorNone))
635
+ EXPORTS_SET(exports,NEW_SYMBOL("eTokenSeparatorNone"),NEW_NUMBER(eTokenSeparatorNone))
636
636
 
637
637
  // EXrefEntryType
638
638
  EXPORTS_SET(exports,NEW_SYMBOL("eXrefEntryExisting"),NEW_NUMBER(eXrefEntryExisting))