Skip to content

Commit

Permalink
attempt to refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuhikoarase committed Feb 15, 2019
1 parent 086252a commit 633a0d3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 9 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ Helper functions for HTML.
| margin | <code>number</code> | default: cellSize * 4 |
| alt | <code>string</code> | (optional) |

#### createSvgTag(opts) => <code>string</code>

| Param | Type | Description |
| ------------- | -------------------- | --------------------- |
| opts | <code>object</code> | default: {} |
| opts.cellSize | <code>number</code> | default: 2 |
| opts.margin | <code>number</code> | default: cellSize * 4 |
| opts.scalable | <code>boolean</code> | default: false |

#### renderTo2dContext(context, cellSize) => <code>void</code>

--
Expand Down
4 changes: 3 additions & 1 deletion js/qrcode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ interface QRCode {
getModuleCount() : number;
isDark(row: number, col: number) : boolean;
createImgTag(cellSize?: number, margin?: number) : string;
createSvgTag(cellSize?: number, margin?: number, displaySize?: any) : string;
createSvgTag(cellSize?: number, margin?: number) : string;
createSvgTag(opts? : { cellSize?: number, margin?: number,
scalable?: boolean }) : string;
createDataURL(cellSize?: number, margin?: number) : string;
createTableTag(cellSize?: number, margin?: number) : string;
createASCII(cellSize?: number, margin?: number) : string;
Expand Down
15 changes: 11 additions & 4 deletions js/qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,16 @@ var qrcode = function() {
return qrHtml;
};

_this.createSvgTag = function(cellSize, margin, displaySize) {
_this.createSvgTag = function(cellSize, margin) {

var opts = {};
if (typeof arguments[0] == 'object') {
// Called by options.
opts = arguments[0];
// overwrite cellSize and margin.
cellSize = opts.cellSize;
margin = opts.margin;
}

cellSize = cellSize || 2;
margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
Expand All @@ -502,10 +511,8 @@ var qrcode = function() {
rect = 'l' + cellSize + ',0 0,' + cellSize +
' -' + cellSize + ',0 0,-' + cellSize + 'z ';

displaySize = (typeof displaySize == 'undefined') ? size : (typeof displaySize == "number") ? displaySize : -1;

qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
qrSvg += displaySize > 0 ? ' width="' + displaySize + 'px" height="' + displaySize + 'px"' : '';
qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : '';
qrSvg += ' viewBox="0 0 ' + size + ' ' + size + '" ';
qrSvg += ' preserveAspectRatio="xMinYMin meet">';
qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
Expand Down

0 comments on commit 633a0d3

Please sign in to comment.