Skip to content

Commit

Permalink
fix(unix): removes remaining png.c refs; enables pipe() for non-Win32
Browse files Browse the repository at this point in the history
Removes all remaining PNG conditionals. Re-enables pipe() for Unix systems.
Updates createFile() to use createStream() and then pipe bitmap to file.
  • Loading branch information
jshor committed Dec 9, 2019
1 parent 5930666 commit 7131d1c
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 345 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ after_success:

env:
matrix:
- NODE_VERSION="9"
- NODE_VERSION="9"
- NODE_VERSION="10"
- NODE_VERSION="11"
- NODE_VERSION="12"
- NODE_VERSION="13"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ A `Symbol` is a regular JavaScript object with the following available propertie
| outputOptions | Number | Symbology-specific output option. | No | `NULL` |
| foregroundColor | Hexadecimal number | Barcode foreground color. | No | FFFFFF |
| backgroundColor | Hexadecimal number | Barcode background color. | No | 000000 |
| fileName | String | Full path to the file to render. | **Yes** | |
| fileName | String | Full path to the file to render. | **Yes*** | |
| scale | Number | Scale of the barcode image. Applies only to PNG. | No | 1.0 |
| option1 | Number | Symbology-type-specific option value. | No | `NULL` |
| option2 | Number | Symbology-type-specific option value. | No | `NULL` |
Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ image: Visual Studio 2017

install:
- ps: Install-Product node 8 x64
- npm remove node-gyp
# - npm remove node-gyp
- yarn global add windows-build-tools
# - yarn test
- yarn
- yarn package-binary
- yarn publish-binary
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"module_path": "./lib/binding/bin/",
"remote_path": "./builds/v{version}/{platform}/{arch}/{node_abi}",
"package_name": "{module_name}.tar.gz",
"host": "https://symbologyjs.s3-us-west-2.amazonaws.com"
"host": "https://symbology.dev.s3-us-west-2.amazonaws.com"
},
"dependencies": {
"nan": "2.x",
"node-pre-gyp": "0.x",
"node-pre-gyp": "^0.14.0",
"pngjs": "3.3.0",
"pngjs-image": "^0.11.6"
},
Expand All @@ -49,8 +49,8 @@
"start": "node ./index.js",
"install": "node-pre-gyp install --fallback-to-build",
"test": "./node_modules/istanbul/lib/cli.js cover _mocha -- -R spec ./src/**/*.test.js",
"build": "node-pre-gyp build --target_arch=x64",
"package-binary": "node-pre-gyp build package --target_arch=x64",
"build": "node-pre-gyp rebuild --target_arch=x64",
"package-binary": "node-pre-gyp rebuild package --target_arch=x64",
"publish-binary": "node-pre-gyp publish --target_arch=x64"
}
}
78 changes: 58 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ function pngRender(bitmap, width, height) {
* @param {String} outputType - 'png', 'svg', or 'eps' (default: 'png')
* @returns {Promise<Object>} object with resulting props (see docs)
*/
exp.createStream = function(symbol, barcodeData, outputType) {
function theCreateStram(symbol, barcodeData, outputType) {
outputType = outputType || exp.Output.PNG
symbol.fileName = 'out.' + outputType
symbol.fileName = symbol.fileName || 'out.' + outputType

if (outputType !== exp.Output.PNG) {
symbol.outputOptions = 8; // force buffer to write to rendered_data
Expand All @@ -154,24 +154,16 @@ exp.createStream = function(symbol, barcodeData, outputType) {
var res = createSymbology(symbol, barcodeData, 'createStream');

if(res.code <= 2) {
if (outputType === exp.Output.PNG) {
var pngData = pngRender(res.encodedData, res.width, res.height);

return blobToBase64Png(pngData)
.then(function(base64Data) {
return {
data: base64Data,
width: res.width,
height: res.height,
message: res.message,
code: res.code
};
});
if (typeof res.encodedData === 'string') {
res.encodedData = res.encodedData.replace(/\r?\n?[^\r\n]*$/, '')
}

return Promise.resolve({
data: res.encodedData,
message: res.message,
code: res.code
code: res.code,
width: res.width,
height: res.height
});
}
return Promise.reject({
Expand All @@ -180,6 +172,27 @@ exp.createStream = function(symbol, barcodeData, outputType) {
});
};

exp.createStream = function(symbol, barcodeData, outputType) {
return theCreateStram(symbol, barcodeData, outputType)
.then((res) => {
if (outputType === exp.Output.PNG) {
var pngData = pngRender(res.data, res.width, res.height);

return blobToBase64Png(pngData)
.then(function(base64Data) {
return {
data: base64Data,
width: res.width,
height: res.height,
message: res.message,
code: res.code
};
});
}
return res
})
}

/**
* Creates a stream of a PNG, SVG or EPS file in the specified fileName path.
*
Expand All @@ -190,11 +203,36 @@ exp.createStream = function(symbol, barcodeData, outputType) {
* @returns {Promise<Object>} object with resulting props (see docs)
*/
exp.createFile = function(symbol, barcodeData) {
var res = createSymbology(symbol, barcodeData, 'createFile');
const outputType = exp.Output[symbol.fileName.split('.').pop().toUpperCase()] || exp.Output.PNG

return theCreateStram(symbol, barcodeData, outputType)
.then((res) => {
console.log('did the do', outputType)
if (outputType === exp.Output.PNG) {
console.log('found png')
var image = pngRender(res.data, res.width, res.height);

return new Promise((resolve, reject) => {
image.writeImage(symbol.fileName, function(err) {
if (err) {
reject(err)
} else {
delete res.data

resolve(res)
}
});
});
}

return new Promise(function(resolve) {
resolve(res);
});
console.log('WRITING: ', symbol.fileName)

fs.writeFileSync(symbol.fileName, res.data)

delete res.data

return res
})
};

module.exports = exp;
11 changes: 2 additions & 9 deletions src/lib/zint/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ extern int channel_code(struct zint_symbol *symbol, uint8_t source[], int length
extern int code_one(struct zint_symbol *symbol, uint8_t source[], int length); /* Code One */
extern int grid_matrix(struct zint_symbol *symbol, uint8_t source[], int length); /* Grid Matrix */

#ifndef NO_PNG
extern int png_handle(struct zint_symbol *symbol, int rotate_angle);
#endif

extern int render_plot(struct zint_symbol *symbol, float width, float height);

extern int bmp_handle(struct zint_symbol *symbol, int rotate_angle);
Expand Down Expand Up @@ -715,13 +711,10 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle)
output[3] = '\0';
to_upper((uint8_t*)output);

#ifndef NO_PNG
if(!(strcmp(output, "PNG"))) {
if(symbol->scale < 1.0) { symbol->text[0] = '\0'; }
error_number = png_handle(symbol, rotate_angle);
} else
#endif
if(!(strcmp(output, "TXT"))) {
error_number = bmp_handle(symbol, rotate_angle);
} else if(!(strcmp(output, "TXT"))) {
error_number = dump_plot(symbol);
} else if(!(strcmp(output, "EPS"))) {
error_number = ps_plot(symbol);
Expand Down
Loading

0 comments on commit 7131d1c

Please sign in to comment.