QR Code correction level
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
import Node from './Node';
|
import Node from './Node';
|
||||||
import {canvasPool2D} from '../canvas/CanvasPool';
|
import {canvasPool2D} from '../canvas/CanvasPool';
|
||||||
import {BrowserQRCodeSvgWriter} from '@zxing/browser';
|
import {BrowserQRCodeSvgWriter} from '@zxing/browser';
|
||||||
|
import {EncodeHintType, QRCodeDecoderErrorCorrectionLevel} from '@zxing/library';
|
||||||
|
|
||||||
const inputs = {
|
const inputs = {
|
||||||
text: {
|
text: {
|
||||||
@@ -15,6 +16,20 @@ const inputs = {
|
|||||||
type: 'Number',
|
type: 'Number',
|
||||||
min: 1,
|
min: 1,
|
||||||
} as NumberVar,
|
} as NumberVar,
|
||||||
|
correction: {
|
||||||
|
type: 'String',
|
||||||
|
default: 'L',
|
||||||
|
enum: [
|
||||||
|
'L', /** L = ~7% correction */
|
||||||
|
'M', /** M = ~15% correction */
|
||||||
|
'Q', /** Q = ~25% correction */
|
||||||
|
'H', /** H = ~30% correction */
|
||||||
|
],
|
||||||
|
} as StringVar,
|
||||||
|
margin: {
|
||||||
|
type: 'Number',
|
||||||
|
min: 0,
|
||||||
|
} as NumberVar,
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputs = {
|
const outputs = {
|
||||||
@@ -24,6 +39,9 @@ const outputs = {
|
|||||||
size: {
|
size: {
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
} as NumberVar,
|
} as NumberVar,
|
||||||
|
margin: {
|
||||||
|
type: 'Number',
|
||||||
|
} as NumberVar,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class QRCodeGenerator extends Node<typeof inputs, typeof outputs> {
|
export default class QRCodeGenerator extends Node<typeof inputs, typeof outputs> {
|
||||||
@@ -38,8 +56,10 @@ export default class QRCodeGenerator extends Node<typeof inputs, typeof outputs>
|
|||||||
if (!this.in.text.value || !this.in.size.value) {
|
if (!this.in.text.value || !this.in.size.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BrowserQRCodeSvgWriter.QUIET_ZONE_SIZE = 0;
|
const encodeHintTypeMap = new Map<EncodeHintType, any>();
|
||||||
const svgElement = this.writer.write(this.in.text.value, this.in.size.value, this.in.size.value);
|
encodeHintTypeMap.set(EncodeHintType.MARGIN, this.in.margin.value);
|
||||||
|
encodeHintTypeMap.set(EncodeHintType.ERROR_CORRECTION, QRCodeDecoderErrorCorrectionLevel[this.in.correction.value]);
|
||||||
|
const svgElement = this.writer.write(this.in.text.value, this.in.size.value, this.in.size.value, encodeHintTypeMap);
|
||||||
const canvas = canvasPool2D.createCanvas();
|
const canvas = canvasPool2D.createCanvas();
|
||||||
canvas.width = this.in.size.value;
|
canvas.width = this.in.size.value;
|
||||||
canvas.height = this.in.size.value;
|
canvas.height = this.in.size.value;
|
||||||
@@ -66,6 +86,7 @@ export default class QRCodeGenerator extends Node<typeof inputs, typeof outputs>
|
|||||||
img.height = this.in.size.value;
|
img.height = this.in.size.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.out.margin.value = this.in.margin.value;
|
||||||
this.out.size.value = this.in.size.value;
|
this.out.size.value = this.in.size.value;
|
||||||
this.out.image.value = canvas;
|
this.out.image.value = canvas;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user