Skip to content

Commit

Permalink
Monochrome font support
Browse files Browse the repository at this point in the history
  • Loading branch information
metafloor committed Apr 21, 2015
1 parent 472dc8b commit 2093ca3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ the end of this document.

## Status

* Current bwip-js version is 0.11.0
* Current bwip-js version is 0.12.0
* Current BWIPP version is 2015-03-24
* Node.js compatibility >= v0.10
* npm dependencies: none
Expand Down Expand Up @@ -113,6 +113,7 @@ bwipjs.loadFont('Inconsolata', 108,
bwipjs.toBuffer({
bcid: 'code128', // Barcode type
text: '0123456789', // Text to encode
scale: 3, // 3x scaling factor
height: 10, // Bar height, in millimeters
includetext: true, // Show human-readable text
textxalign: 'center', // Always good to set this
Expand All @@ -131,12 +132,27 @@ bwipjs.toBuffer({
});
```

Only the first two options `bcid` and `text` are required.
Only the first two options `bcid` and `text` are required. The other bwip-js
specific options are:

- `scaleX` : The x-axis scaling factor. Must be an integer > 0. Default is 2.
- `scaleY` : The y-axis scaling factor. Must be an integer > 0. Default is `scaleX`.
- `scale` : Sets both the x-axis and y-axis scaling factors. Must be an integer > 0.

- `rotate` : Allows rotating the image to one of the four orthogonal orientations. A string value. Must be one of:

* `"N"` : Normal (not rotated). The default.
* `"R"` : Clockwise (right) 90 degree rotation.
* `"L"` : Counter-clockwise (left) 90 degree rotation.
* `"I"` : Inverted 180 degree rotation.

- `monochrome` : Sets the human-readable text to render in monochrome. Boolean `true` or `false`. Default is `false` which renders 256-level gray-scale anti-aliased text.

You will need to consult the
[BWIPP documentation](https://github.com/bwipp/postscriptbarcode/wiki)
to determine what options are available for each barcode type.


## Features

An
Expand Down
14 changes: 12 additions & 2 deletions node-bwipjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ function load(path) {
module.exports = function(req, res) {
var args = url.parse(req.url, true).query;

// Fix the monochrome non sequitur
args.monochrome = args.monochrome === '';

module.exports.toBuffer(args, function(err, png) {
if (err) {
res.writeHead(400, { 'Content-Type':'text/plain' });
Expand Down Expand Up @@ -82,8 +85,11 @@ module.exports.toBuffer = function(args, callback) {
// Set the defaults
var scale = args.scale || 2;
var scaleX = +args.scaleX || scale;
var scaleY = +args.scaleY || scale;
var scaleY = +args.scaleY || scaleX;
var rot = args.rotate || 'N';
var mono = args.monochrome || false;

// The required parameters
var bcid = args.bcid;
var text = args.text;

Expand All @@ -101,6 +107,7 @@ module.exports.toBuffer = function(args, callback) {
delete args.rotate;
delete args.text;
delete args.bcid;
delete args.monochrome;

// Initialize a barcode writer object
var bw = new sandbox.BWIPJS;
Expand All @@ -109,7 +116,7 @@ module.exports.toBuffer = function(args, callback) {
var opts = {};
for (id in args) {
// options that do not take a value e.g. parsefnc
if (!args[id])
if (args[id] === '' || args[id] === undefined)
opts[id] = bw.value(true);
else
opts[id] = bw.value(args[id]);
Expand All @@ -122,6 +129,9 @@ module.exports.toBuffer = function(args, callback) {
// We use mm rather than inches for height
if (opts.height)
opts.height = opts.height / 25.4 || 0.5;

// Enable/disable monochrome font rendering
sandbox.BWIPJS.ft_monochrome(mono ? 1 : 0);

// Render the bar code
bw.bitmap(new Bitmap);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bwip-js",
"version": "0.11.0",
"description": "Barcode Writer in Pure JavaScript",
"version": "0.12.0",
"description": "Barcode image generator supporting over 90 types and standards.",
"main": "node-bwipjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -11,7 +11,7 @@
"url": "https://github.com/metafloor/bwip-js.git"
},
"keywords": [
"qr"
"qr",
"itf",
"gs1",
"upc",
Expand All @@ -28,7 +28,7 @@
"code",
"bar",
"generator",
"barcode",
"barcode"
],
"author": "Mark Warren <mwarren@metafloor.com>",
"license": "MIT",
Expand Down

0 comments on commit 2093ca3

Please sign in to comment.