Skip to content

Commit f9109a4

Browse files
committed
Return canvas element from toCanvas()
1 parent 9cc3e8e commit f9109a4

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ found at the end of this document.
2424
2525
## Status
2626

27-
* Current bwip-js version is 2.0.1 (2019-12-13)
27+
* Current bwip-js version is 2.0.2 (2019-12-14)
2828
* Current BWIPP version is 2019-11-08
2929
* Node.js compatibility: 0.12+
3030
* Browser compatibility: Edge, Firefox, Chrome
@@ -154,14 +154,15 @@ The script adds a single `bwipjs` global object. To draw a barcode to a canvas:
154154

155155
```javascript
156156
try {
157-
bwipjs.toCanvas('mycanvas', {
158-
bcid: 'code128', // Barcode type
159-
text: '0123456789', // Text to encode
160-
scale: 3, // 3x scaling factor
161-
height: 10, // Bar height, in millimeters
162-
includetext: true, // Show human-readable text
163-
textxalign: 'center', // Always good to set this
164-
});
157+
// The return value is the canvas element
158+
let canvas = bwipjs.toCanvas('mycanvas', {
159+
bcid: 'code128', // Barcode type
160+
text: '0123456789', // Text to encode
161+
scale: 3, // 3x scaling factor
162+
height: 10, // Bar height, in millimeters
163+
includetext: true, // Show human-readable text
164+
textxalign: 'center', // Always good to set this
165+
});
165166
} catch (e) {
166167
// `e` may be a string or Error object
167168
}
@@ -205,14 +206,15 @@ import bwipjs from 'bwip-js';
205206
class App extends Component {
206207
componentDidMount() {
207208
try {
208-
bwipjs.toCanvas('mycanvas', {
209-
bcid: 'code128', // Barcode type
210-
text: '0123456789', // Text to encode
211-
scale: 3, // 3x scaling factor
212-
height: 10, // Bar height, in millimeters
213-
includetext: true, // Show human-readable text
214-
textxalign: 'center', // Always good to set this
215-
});
209+
// The return value is the canvas element
210+
let canvas = bwipjs.toCanvas('mycanvas', {
211+
bcid: 'code128', // Barcode type
212+
text: '0123456789', // Text to encode
213+
scale: 3, // 3x scaling factor
214+
height: 10, // Bar height, in millimeters
215+
includetext: true, // Show human-readable text
216+
textxalign: 'center', // Always good to set this
217+
});
216218
} catch (e) {
217219
// `e` may be a string or Error object
218220
}

dist/bwip-js-min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/bwip-js.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ function ToBuffer(opts, callback) {
120120
//
121121
// This function is synchronous and throws on error.
122122
//
123+
// Returns the HTMLCanvasElement.
124+
//
123125
// Browser usage only.
124126
function ToCanvas(opts, canvas) {
125127
if (typeof canvas == 'string') {
@@ -136,6 +138,8 @@ function ToCanvas(opts, canvas) {
136138
}
137139
FixupOptions(opts);
138140
Render(opts, DrawingCanvas(opts, canvas));
141+
142+
return canvas;
139143
}
140144

141145
// bwipjs.fixupOptions(options)
@@ -253,7 +257,7 @@ function Render(params, drawing) {
253257

254258
// Call into the BWIPP cross-compiled code and render the image.
255259
BWIPP()(bw, bcid, text, opts);
256-
return bw.render(); // Returns whatever drawing.end() returns
260+
return bw.render(); // Return whatever drawing.end() returns
257261
}
258262

259263
// bwipjs.raw(options)
@@ -36472,7 +36476,7 @@ return {
3647236476
request:Request, toBuffer:ToBuffer, toCanvas:ToCanvas, render:Render, raw:Raw,
3647336477
fixupOptions:FixupOptions,
3647436478
loadFont:FontLib.loadFont,
36475-
VERSION:'2.0.1 (2019-12-13)',
36479+
VERSION:'2.0.2 (2019-12-14)',
3647636480

3647736481
// Internals
3647836482
BWIPJS:BWIPJS, BWIPP:BWIPP, STBTT:STBTT, FontLib:FontLib,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bwip-js",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "JavaScript barcode generator supporting over 90 types and standards.",
55
"main": "./dist/bwip-js.js",
66
"bin": {

src/exports.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ function ToBuffer(opts, callback) {
8080
//
8181
// This function is synchronous and throws on error.
8282
//
83+
// Returns the HTMLCanvasElement.
84+
//
8385
// Browser usage only.
8486
function ToCanvas(opts, canvas) {
8587
if (typeof canvas == 'string') {
@@ -96,6 +98,8 @@ function ToCanvas(opts, canvas) {
9698
}
9799
FixupOptions(opts);
98100
Render(opts, DrawingCanvas(opts, canvas));
101+
102+
return canvas;
99103
}
100104

101105
// bwipjs.fixupOptions(options)

0 commit comments

Comments
 (0)