Skip to content

Commit

Permalink
Added Crisp option
Browse files Browse the repository at this point in the history
  • Loading branch information
werthdavid committed Jul 29, 2019
1 parent 998b4ad commit 639f794
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ This is basically just a fork of kjua that adds the possibility to render QR-cod
### Limitations

Some options do not work when the code is rendered as SVG. These are:
* crisp
* rounded
* mode
* mSize
Expand Down
11 changes: 9 additions & 2 deletions src/lib/qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ const min_qrcode = (text, level, min_ver = 1, settings) => {
qr.isDark(row, col);
};
let svgText;
// SVG logic has to be here and not in draw_svg.js since we have access to QR-Generator only here
if (settings.render === 'svg') {
const cellSize = (settings.size - settings.quiet * 2) / moduleCount;
svgText = settings.render === 'svg' ? qr.createSvgTag(cellSize, settings.quiet, true) : undefined;
const modCount = moduleCount + settings.quiet * 2;
let moduleSize = settings.size / modCount;
let offset = 0;
if (settings.crisp) {
moduleSize = Math.floor(moduleSize);
offset = Math.floor((settings.size - moduleSize * modCount) / 2);
}
svgText = settings.render === 'svg' ? qr.createSvgTag(moduleSize, (moduleSize * settings.quiet) + offset, true) : undefined;
}
return {text, level, version, moduleCount, isDark, svgText};
} catch (err) {
Expand Down

0 comments on commit 639f794

Please sign in to comment.