Skip to content

Commit

Permalink
Merge pull request #118 from zxing-js/develop
Browse files Browse the repository at this point in the history
v0.9.2

May the force be with you.
  • Loading branch information
odahcam committed Dec 11, 2018
2 parents ea54f92 + 726ba0b commit b9b1240
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@zxing/library",
"version": "0.9.1",
"version": "0.9.2",
"description": "TypeScript port of ZXing multi-format 1D/2D barcode image processing library.",
"keywords": [
"reader",
Expand Down
43 changes: 38 additions & 5 deletions src/browser/BrowserQRCodeSvgWriter.ts
Expand Up @@ -20,19 +20,27 @@ class BrowserQRCodeSvgWriter {
/**
* A HTML container element for the image.
*/
private containerElement: HTMLElement;
private containerElement?: HTMLElement;

/**
* Constructs. 😉
*/
public constructor(containerElement: string | HTMLElement) {
public constructor(containerElement?: string | HTMLElement) {
if (typeof containerElement === 'string') {
this.containerElement = document.getElementById(containerElement);
} else {
this.containerElement = containerElement;
}
}

/**
* Writes and renders a QRCode to the DOM.
*
* @param contents
* @param width
* @param height
* @param hints
*/
public write(
contents: string,
width: number,
Expand Down Expand Up @@ -68,7 +76,20 @@ class BrowserQRCodeSvgWriter {

const code = Encoder.encode(contents, errorCorrectionLevel, hints);

return this.renderResult(code, width, height, quietZone);
return this.renderResultToDOM(code, width, height, quietZone);
}

/**
* Renders the result and then appends it to the DOM.
*/
private renderResultToDOM(code: QRCode, width: number /*int*/, height: number /*int*/, quietZone: number /*int*/): SVGSVGElement {

const svgElement = this.renderResult(code, width, height, quietZone);

if (this.containerElement)
this.containerElement.appendChild(svgElement);

return svgElement;
}

/**
Expand Down Expand Up @@ -101,8 +122,6 @@ class BrowserQRCodeSvgWriter {

const svgElement = this.createSVGElement(outputWidth, outputHeight);

this.containerElement.appendChild(svgElement);

for (let inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++ , outputY += multiple) {
// Write the contents of this row of the barcode
for (let inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++ , outputX += multiple) {
Expand All @@ -116,6 +135,12 @@ class BrowserQRCodeSvgWriter {
return svgElement;
}

/**
* Creates a SVG element.
*
* @param w SVG's width attribute
* @param h SVG's height attribute
*/
private createSVGElement(w: number, h: number): SVGSVGElement {

const svgElement = document.createElementNS(BrowserQRCodeSvgWriter.SVG_NS, 'svg');
Expand All @@ -126,6 +151,14 @@ class BrowserQRCodeSvgWriter {
return svgElement;
}

/**
* Creates a SVG rect element.
*
* @param x Element's x coordinate
* @param y Element's y coordinate
* @param w Element's width attribute
* @param h Element's height attribute
*/
private createSvgRectElement(x: number, y: number, w: number, h: number): SVGRectElement {

const rect = document.createElementNS(BrowserQRCodeSvgWriter.SVG_NS, 'rect');
Expand Down
2 changes: 1 addition & 1 deletion src/core/qrcode/decoder/DataMask.ts
Expand Up @@ -18,7 +18,7 @@

import BitMatrix from '../../common/BitMatrix';

export const enum DataMaskValues {
export enum DataMaskValues {
DATA_MASK_000,
DATA_MASK_001,
DATA_MASK_010,
Expand Down
2 changes: 1 addition & 1 deletion src/core/qrcode/decoder/ErrorCorrectionLevel.ts
Expand Up @@ -20,7 +20,7 @@
import ArgumentException from '../../ArgumentException';
import IllegalArgumentException from '../../IllegalArgumentException';

export const enum ErrorCorrectionLevelValues {
export enum ErrorCorrectionLevelValues {
L,
M,
Q,
Expand Down
2 changes: 1 addition & 1 deletion src/core/qrcode/decoder/Mode.ts
Expand Up @@ -20,7 +20,7 @@
import Version from './Version';
import IllegalArgumentException from '../../IllegalArgumentException';

export const enum ModeValues {
export enum ModeValues {
TERMINATOR, // Not really a mode...
NUMERIC,
ALPHANUMERIC,
Expand Down

0 comments on commit b9b1240

Please sign in to comment.