ttf2woff2 1.2.3 → 2.0.3

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 (52) hide show
  1. package/.travis.yml +26 -16
  2. package/README.md +2 -2
  3. package/binding.gyp +3 -0
  4. package/build/Makefile +2 -2
  5. package/build/Release/.deps/Release/obj.target/addon/csrc/addon.o.d +54 -17
  6. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/backward_references.o.d +1 -1
  7. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/block_splitter.o.d +1 -1
  8. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/brotli_bit_stream.o.d +1 -1
  9. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/encode.o.d +1 -1
  10. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/encode_parallel.o.d +1 -1
  11. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/entropy_encode.o.d +1 -1
  12. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/histogram.o.d +1 -1
  13. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/literal_cost.o.d +1 -1
  14. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/metablock.o.d +1 -1
  15. package/build/Release/.deps/Release/obj.target/addon/csrc/enc/streams.o.d +1 -1
  16. package/build/Release/.deps/Release/obj.target/addon/csrc/woff2/font.o.d +1 -1
  17. package/build/Release/.deps/Release/obj.target/addon/csrc/woff2/glyph.o.d +1 -1
  18. package/build/Release/.deps/Release/obj.target/addon/csrc/woff2/normalize.o.d +1 -1
  19. package/build/Release/.deps/Release/obj.target/addon/csrc/woff2/table_tags.o.d +1 -1
  20. package/build/Release/.deps/Release/obj.target/addon/csrc/woff2/transform.o.d +1 -1
  21. package/build/Release/.deps/Release/obj.target/addon/csrc/woff2/variable_length.o.d +1 -1
  22. package/build/Release/.deps/Release/obj.target/addon/csrc/woff2/woff2_common.o.d +1 -1
  23. package/build/Release/.deps/Release/obj.target/addon/csrc/woff2/woff2_enc.o.d +1 -1
  24. package/build/Release/.deps/Release/obj.target/addon.node.d +1 -1
  25. package/build/Release/addon.node +0 -0
  26. package/build/Release/obj.target/addon/csrc/addon.o +0 -0
  27. package/build/Release/obj.target/addon/csrc/enc/backward_references.o +0 -0
  28. package/build/Release/obj.target/addon/csrc/enc/block_splitter.o +0 -0
  29. package/build/Release/obj.target/addon/csrc/enc/brotli_bit_stream.o +0 -0
  30. package/build/Release/obj.target/addon/csrc/enc/encode.o +0 -0
  31. package/build/Release/obj.target/addon/csrc/enc/encode_parallel.o +0 -0
  32. package/build/Release/obj.target/addon/csrc/enc/entropy_encode.o +0 -0
  33. package/build/Release/obj.target/addon/csrc/enc/histogram.o +0 -0
  34. package/build/Release/obj.target/addon/csrc/enc/literal_cost.o +0 -0
  35. package/build/Release/obj.target/addon/csrc/enc/metablock.o +0 -0
  36. package/build/Release/obj.target/addon/csrc/woff2/font.o +0 -0
  37. package/build/Release/obj.target/addon/csrc/woff2/glyph.o +0 -0
  38. package/build/Release/obj.target/addon/csrc/woff2/normalize.o +0 -0
  39. package/build/Release/obj.target/addon/csrc/woff2/transform.o +0 -0
  40. package/build/Release/obj.target/addon/csrc/woff2/variable_length.o +0 -0
  41. package/build/Release/obj.target/addon/csrc/woff2/woff2_enc.o +0 -0
  42. package/build/Release/obj.target/addon.node +0 -0
  43. package/build/addon.target.mk +10 -8
  44. package/csrc/addon.cc +28 -43
  45. package/csrc/fallback.cc +35 -17
  46. package/csrc/woff2/port.h +2 -0
  47. package/jssrc/index.js +7 -9
  48. package/jssrc/ttf2woff2.js +8 -8
  49. package/package.json +14 -11
  50. package/tests/tests.mocha.js +15 -3
  51. package/build/Release/linker.lock +0 -0
  52. package/builderror.log +0 -24
package/csrc/fallback.cc CHANGED
@@ -1,33 +1,51 @@
1
1
  // Emscripten wrapper
2
-
2
+ #include <emscripten/bind.h>
3
3
  #include <stdlib.h>
4
4
  #include "./woff2/woff2_enc.h"
5
5
 
6
+ using namespace emscripten;
6
7
  using std::string;
7
8
 
8
- extern "C"
9
- {
9
+ int getSizePtr() {
10
+ int* sizePtr = reinterpret_cast<int*>(calloc(1, sizeof(int)));
11
+ return reinterpret_cast<int>(sizePtr);
12
+ }
10
13
 
11
- char * convertTTFToWOFF2(char * input, int length, int * outputLength) {
14
+ int convert(int inputDataAddress, int inputLength, int outputSizePtrAddress) {
15
+ int* outputSizePtr = reinterpret_cast<int*>(outputSizePtrAddress);
16
+ char* inputData = reinterpret_cast<char*>(inputDataAddress);
12
17
 
13
- const uint8_t* input_data = reinterpret_cast<const uint8_t*>(input);
14
- size_t output_size = woff2::MaxWOFF2CompressedSize(input_data, length);
18
+ size_t outputSize = woff2::MaxWOFF2CompressedSize(
19
+ reinterpret_cast<const uint8_t*>(inputData),
20
+ inputLength
21
+ );
15
22
 
16
- uint8_t* output_data = reinterpret_cast<uint8_t*>(malloc(output_size));
23
+ uint8_t* outputData = reinterpret_cast<uint8_t*>(calloc(outputSize, sizeof(uint8_t)));
17
24
 
18
25
 
19
- if (woff2::ConvertTTFToWOFF2(input_data, length,
20
- output_data, &output_size)) {
21
- //output.resize(output_size);
22
- }
26
+ if(!woff2::ConvertTTFToWOFF2(
27
+ reinterpret_cast<const uint8_t*>(inputData),
28
+ inputLength,
29
+ outputData,
30
+ &outputSize
31
+ )) {
32
+ // throw an error
33
+ }
23
34
 
24
- *outputLength = output_size;
35
+ *outputSizePtr = outputSize;
25
36
 
26
- return (char *) output_data;
27
- }
37
+ return reinterpret_cast<int>(outputData);
38
+ }
28
39
 
29
- void freeTTFToWOFF2(char * output_data) {
30
- free(output_data);
31
- }
40
+ void freePtrs(int outputDataAddress, int sizePtrAddress) {
41
+ int* sizePtr = reinterpret_cast<int*>(sizePtrAddress);
42
+ char* outputData = reinterpret_cast<char*>(outputDataAddress);
43
+ free(outputData);
44
+ free(sizePtr);
45
+ }
32
46
 
47
+ EMSCRIPTEN_BINDINGS(ttf2woff2_fallback) {
48
+ function("getSizePtr", &getSizePtr, allow_raw_pointers());
49
+ function("convert", &convert, allow_raw_pointers());
50
+ function("freePtrs", &freePtrs, allow_raw_pointers());
33
51
  }
package/csrc/woff2/port.h CHANGED
@@ -17,6 +17,8 @@
17
17
  #ifndef WOFF2_PORT_H_
18
18
  #define WOFF2_PORT_H_
19
19
 
20
+ #include <assert.h>
21
+
20
22
  namespace woff2 {
21
23
 
22
24
  typedef unsigned int uint32;
package/jssrc/index.js CHANGED
@@ -3,20 +3,20 @@
3
3
  var theTTFToWOFF2Module = require('./ttf2woff2');
4
4
 
5
5
  module.exports = function ttf2woff2(inputContent) {
6
- var outputSize;
7
- var outputContent;
8
- var outputBufferPtr;
9
- var i;
10
6
 
11
7
  // Prepare input
12
8
  var inputBuffer = theTTFToWOFF2Module._malloc(inputContent.length + 1);
13
9
  var outputSizePtr = theTTFToWOFF2Module._malloc(4);
10
+ var outputBufferPtr;
11
+ var outputSize;
12
+ var outputContent;
13
+ var i;
14
14
 
15
15
  theTTFToWOFF2Module.writeArrayToMemory(inputContent, inputBuffer);
16
16
 
17
17
  // Run
18
- outputBufferPtr = theTTFToWOFF2Module._convertTTFToWOFF2(
19
- inputBuffer, inputContent.length + 1, outputSizePtr
18
+ outputBufferPtr = theTTFToWOFF2Module.convert(
19
+ inputBuffer, inputContent.length, outputSizePtr
20
20
  );
21
21
 
22
22
  // Retrieve output
@@ -27,9 +27,7 @@ module.exports = function ttf2woff2(inputContent) {
27
27
  outputContent[i] = theTTFToWOFF2Module.getValue(outputBufferPtr + i, 'i8');
28
28
  }
29
29
 
30
- theTTFToWOFF2Module._free(inputBuffer);
31
- theTTFToWOFF2Module._free(outputSizePtr);
32
- theTTFToWOFF2Module._freeTTFToWOFF2(outputBufferPtr);
30
+ theTTFToWOFF2Module.freePtrs(outputBufferPtr, outputSizePtr);
33
31
 
34
32
  return outputContent;
35
33
  };